annotate agent/src/os/win32/windbg/sawindbg.cpp @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents a61af66fc99e
children 9fae07c31641
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // this is source code windbg based SA debugger agent to debug
a61af66fc99e Initial load
duke
parents:
diff changeset
26 // Dr. Watson dump files and process snapshots.
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 #include "sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 #ifdef _M_IA64
a61af66fc99e Initial load
duke
parents:
diff changeset
31 #include "sun_jvm_hotspot_debugger_ia64_IA64ThreadContext.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
32 #define NPRGREG sun_jvm_hotspot_debugger_ia64_IA64ThreadContext_NPRGREG
a61af66fc99e Initial load
duke
parents:
diff changeset
33 #elif _M_IX86
a61af66fc99e Initial load
duke
parents:
diff changeset
34 #include "sun_jvm_hotspot_debugger_x86_X86ThreadContext.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
35 #define NPRGREG sun_jvm_hotspot_debugger_x86_X86ThreadContext_NPRGREG
a61af66fc99e Initial load
duke
parents:
diff changeset
36 #elif _M_AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
37 #include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
38 #define NPRGREG sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_NPRGREG
a61af66fc99e Initial load
duke
parents:
diff changeset
39 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
40 #error "SA windbg back-end is not supported for your cpu!"
a61af66fc99e Initial load
duke
parents:
diff changeset
41 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 #include <limits.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
44 #include <windows.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 #ifndef STDMETHODV
a61af66fc99e Initial load
duke
parents:
diff changeset
47 #define STDMETHODV(method) virtual HRESULT STDMETHODVCALLTYPE method
a61af66fc99e Initial load
duke
parents:
diff changeset
48 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 #define DEBUG_NO_IMPLEMENTATION
a61af66fc99e Initial load
duke
parents:
diff changeset
51 #include <dbgeng.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
52 #include <dbghelp.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // simple template to manage array delete across early (error) returns
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 template <class T>
a61af66fc99e Initial load
duke
parents:
diff changeset
57 class AutoArrayPtr {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 T* m_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
60 AutoArrayPtr(T* ptr) : m_ptr(ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 ~AutoArrayPtr() {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 delete [] m_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 T* asPtr() {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 return m_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70 };
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 class AutoJavaString {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 JNIEnv* m_env;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 jstring m_str;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 const char* m_buf;
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
78 AutoJavaString(JNIEnv* env, jstring str, const char* buf)
a61af66fc99e Initial load
duke
parents:
diff changeset
79 : m_env(env), m_str(str), m_buf(buf) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 ~AutoJavaString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 m_env->ReleaseStringUTFChars(m_str, m_buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 operator const char* () {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 return m_buf;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 };
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // field and method IDs we want here
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 static jfieldID imagePath_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 static jfieldID symbolPath_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 static jfieldID ptrIDebugClient_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 static jfieldID ptrIDebugControl_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 static jfieldID ptrIDebugDataSpaces_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 static jfieldID ptrIDebugOutputCallbacks_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 static jfieldID ptrIDebugAdvanced_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 static jfieldID ptrIDebugSymbols_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 static jfieldID ptrIDebugSystemObjects_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 static jmethodID addLoadObject_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 static jmethodID addThread_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 static jmethodID createClosestSymbol_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 static jmethodID setThreadIntegerRegisterSet_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 #define CHECK_EXCEPTION_(value) if(env->ExceptionOccurred()) { return value; }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 #define CHECK_EXCEPTION if(env->ExceptionOccurred()) { return;}
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 #define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
112 throwNewDebuggerException(env, str); return value; }
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 #define THROW_NEW_DEBUGGER_EXCEPTION(str) { throwNewDebuggerException(env, str); \
a61af66fc99e Initial load
duke
parents:
diff changeset
115 return;}
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 static void throwNewDebuggerException(JNIEnv* env, const char* errMsg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 env->ThrowNew(env->FindClass("sun/jvm/hotspot/debugger/DebuggerException"), errMsg);
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
122 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
123 * Method: initIDs
a61af66fc99e Initial load
duke
parents:
diff changeset
124 * Signature: ()V
a61af66fc99e Initial load
duke
parents:
diff changeset
125 */
a61af66fc99e Initial load
duke
parents:
diff changeset
126 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_initIDs
a61af66fc99e Initial load
duke
parents:
diff changeset
127 (JNIEnv *env, jclass clazz) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 imagePath_ID = env->GetStaticFieldID(clazz, "imagePath", "Ljava/lang/String;");
a61af66fc99e Initial load
duke
parents:
diff changeset
129 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 symbolPath_ID = env->GetStaticFieldID(clazz, "symbolPath", "Ljava/lang/String;");
a61af66fc99e Initial load
duke
parents:
diff changeset
132 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 ptrIDebugClient_ID = env->GetFieldID(clazz, "ptrIDebugClient", "J");
a61af66fc99e Initial load
duke
parents:
diff changeset
135 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 ptrIDebugControl_ID = env->GetFieldID(clazz, "ptrIDebugControl", "J");
a61af66fc99e Initial load
duke
parents:
diff changeset
138 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 ptrIDebugDataSpaces_ID = env->GetFieldID(clazz, "ptrIDebugDataSpaces", "J");
a61af66fc99e Initial load
duke
parents:
diff changeset
141 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 ptrIDebugOutputCallbacks_ID = env->GetFieldID(clazz,
a61af66fc99e Initial load
duke
parents:
diff changeset
144 "ptrIDebugOutputCallbacks", "J");
a61af66fc99e Initial load
duke
parents:
diff changeset
145 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 ptrIDebugAdvanced_ID = env->GetFieldID(clazz, "ptrIDebugAdvanced", "J");
a61af66fc99e Initial load
duke
parents:
diff changeset
148 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 ptrIDebugSymbols_ID = env->GetFieldID(clazz,
a61af66fc99e Initial load
duke
parents:
diff changeset
151 "ptrIDebugSymbols", "J");
a61af66fc99e Initial load
duke
parents:
diff changeset
152 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 ptrIDebugSystemObjects_ID = env->GetFieldID(clazz,
a61af66fc99e Initial load
duke
parents:
diff changeset
155 "ptrIDebugSystemObjects", "J");
a61af66fc99e Initial load
duke
parents:
diff changeset
156 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 addLoadObject_ID = env->GetMethodID(clazz, "addLoadObject",
a61af66fc99e Initial load
duke
parents:
diff changeset
159 "(Ljava/lang/String;JJ)V");
a61af66fc99e Initial load
duke
parents:
diff changeset
160 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 addThread_ID = env->GetMethodID(clazz, "addThread", "(J)V");
a61af66fc99e Initial load
duke
parents:
diff changeset
163 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 createClosestSymbol_ID = env->GetMethodID(clazz, "createClosestSymbol",
a61af66fc99e Initial load
duke
parents:
diff changeset
166 "(Ljava/lang/String;J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;");
a61af66fc99e Initial load
duke
parents:
diff changeset
167 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 setThreadIntegerRegisterSet_ID = env->GetMethodID(clazz,
a61af66fc99e Initial load
duke
parents:
diff changeset
170 "setThreadIntegerRegisterSet", "(J[J)V");
a61af66fc99e Initial load
duke
parents:
diff changeset
171 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // class for IDebugOutputCallbacks
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 class SAOutputCallbacks : public IDebugOutputCallbacks {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 LONG m_refCount;
a61af66fc99e Initial load
duke
parents:
diff changeset
179 char* m_msgBuffer;
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
182 SAOutputCallbacks() : m_refCount(0), m_msgBuffer(0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 ~SAOutputCallbacks() {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 clearBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 const char* getBuffer() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 return m_msgBuffer;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 void clearBuffer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 if (m_msgBuffer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 free(m_msgBuffer);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 m_msgBuffer = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 STDMETHOD_(ULONG, AddRef)(THIS);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 STDMETHOD_(ULONG, Release)(THIS);
a61af66fc99e Initial load
duke
parents:
diff changeset
202 STDMETHOD(QueryInterface)(THIS_
a61af66fc99e Initial load
duke
parents:
diff changeset
203 IN REFIID interfaceId,
a61af66fc99e Initial load
duke
parents:
diff changeset
204 OUT PVOID* ppInterface);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 STDMETHOD(Output)(THIS_
a61af66fc99e Initial load
duke
parents:
diff changeset
206 IN ULONG mask,
a61af66fc99e Initial load
duke
parents:
diff changeset
207 IN PCSTR msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
208 };
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 STDMETHODIMP_(ULONG) SAOutputCallbacks::AddRef(THIS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 InterlockedIncrement(&m_refCount);
a61af66fc99e Initial load
duke
parents:
diff changeset
212 return m_refCount;
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 STDMETHODIMP_(ULONG) SAOutputCallbacks::Release(THIS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 LONG retVal;
a61af66fc99e Initial load
duke
parents:
diff changeset
217 InterlockedDecrement(&m_refCount);
a61af66fc99e Initial load
duke
parents:
diff changeset
218 retVal = m_refCount;
a61af66fc99e Initial load
duke
parents:
diff changeset
219 if (retVal == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 delete this;
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222 return retVal;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224
a61af66fc99e Initial load
duke
parents:
diff changeset
225 STDMETHODIMP SAOutputCallbacks::QueryInterface(THIS_
a61af66fc99e Initial load
duke
parents:
diff changeset
226 IN REFIID interfaceId,
a61af66fc99e Initial load
duke
parents:
diff changeset
227 OUT PVOID* ppInterface) {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 *ppInterface = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
229 HRESULT res = E_NOINTERFACE;
a61af66fc99e Initial load
duke
parents:
diff changeset
230 if (TRUE == IsEqualIID(interfaceId, __uuidof(IUnknown)) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
231 TRUE == IsEqualIID(interfaceId, __uuidof(IDebugOutputCallbacks))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
232 *ppInterface = (IDebugOutputCallbacks*) this;
a61af66fc99e Initial load
duke
parents:
diff changeset
233 AddRef();
a61af66fc99e Initial load
duke
parents:
diff changeset
234 res = S_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239 STDMETHODIMP SAOutputCallbacks::Output(THIS_
a61af66fc99e Initial load
duke
parents:
diff changeset
240 IN ULONG mask,
a61af66fc99e Initial load
duke
parents:
diff changeset
241 IN PCSTR msg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 int len = (int) (strlen(msg) + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
243 if (m_msgBuffer == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 m_msgBuffer = (char*) malloc(len);
a61af66fc99e Initial load
duke
parents:
diff changeset
245 if (m_msgBuffer == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
246 fprintf(stderr, "out of memory debugger output!\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
247 return S_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249 strcpy(m_msgBuffer, msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
250 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 m_msgBuffer = (char*) realloc(m_msgBuffer, len + strlen(m_msgBuffer));
a61af66fc99e Initial load
duke
parents:
diff changeset
252 if (m_msgBuffer == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
253 fprintf(stderr, "out of memory debugger output!\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
254 return S_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
256 strcat(m_msgBuffer, msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258 return S_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 static bool getWindbgInterfaces(JNIEnv* env, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 // get windbg interfaces ..
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264 IDebugClient* ptrIDebugClient = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
265 if (DebugCreate(__uuidof(IDebugClient), (PVOID*) &ptrIDebugClient) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to create IDebugClient object!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268 env->SetLongField(obj, ptrIDebugClient_ID, (jlong) ptrIDebugClient);
a61af66fc99e Initial load
duke
parents:
diff changeset
269
a61af66fc99e Initial load
duke
parents:
diff changeset
270 IDebugControl* ptrIDebugControl = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 if (ptrIDebugClient->QueryInterface(__uuidof(IDebugControl), (PVOID*) &ptrIDebugControl)
a61af66fc99e Initial load
duke
parents:
diff changeset
272 != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugControl", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275 env->SetLongField(obj, ptrIDebugControl_ID, (jlong) ptrIDebugControl);
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 IDebugDataSpaces* ptrIDebugDataSpaces = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
278 if (ptrIDebugClient->QueryInterface(__uuidof(IDebugDataSpaces), (PVOID*) &ptrIDebugDataSpaces)
a61af66fc99e Initial load
duke
parents:
diff changeset
279 != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugDataSpaces object!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
282 env->SetLongField(obj, ptrIDebugDataSpaces_ID, (jlong) ptrIDebugDataSpaces);
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284 SAOutputCallbacks* ptrIDebugOutputCallbacks = new SAOutputCallbacks();
a61af66fc99e Initial load
duke
parents:
diff changeset
285 ptrIDebugOutputCallbacks->AddRef();
a61af66fc99e Initial load
duke
parents:
diff changeset
286 env->SetLongField(obj, ptrIDebugOutputCallbacks_ID, (jlong) ptrIDebugOutputCallbacks);
a61af66fc99e Initial load
duke
parents:
diff changeset
287 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289 IDebugAdvanced* ptrIDebugAdvanced = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
290 if (ptrIDebugClient->QueryInterface(__uuidof(IDebugAdvanced), (PVOID*) &ptrIDebugAdvanced)
a61af66fc99e Initial load
duke
parents:
diff changeset
291 != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugAdvanced object!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294 env->SetLongField(obj, ptrIDebugAdvanced_ID, (jlong) ptrIDebugAdvanced);
a61af66fc99e Initial load
duke
parents:
diff changeset
295
a61af66fc99e Initial load
duke
parents:
diff changeset
296 IDebugSymbols* ptrIDebugSymbols = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
297 if (ptrIDebugClient->QueryInterface(__uuidof(IDebugSymbols), (PVOID*) &ptrIDebugSymbols)
a61af66fc99e Initial load
duke
parents:
diff changeset
298 != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugSymbols object!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301 env->SetLongField(obj, ptrIDebugSymbols_ID, (jlong) ptrIDebugSymbols);
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 IDebugSystemObjects* ptrIDebugSystemObjects = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
304 if (ptrIDebugClient->QueryInterface(__uuidof(IDebugSystemObjects), (PVOID*) &ptrIDebugSystemObjects)
a61af66fc99e Initial load
duke
parents:
diff changeset
305 != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugSystemObjects object!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308 env->SetLongField(obj, ptrIDebugSystemObjects_ID, (jlong) ptrIDebugSystemObjects);
a61af66fc99e Initial load
duke
parents:
diff changeset
309
a61af66fc99e Initial load
duke
parents:
diff changeset
310 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 static bool setImageAndSymbolPath(JNIEnv* env, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 jboolean isCopy;
a61af66fc99e Initial load
duke
parents:
diff changeset
315 jclass clazz = env->GetObjectClass(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
316 jstring path;
a61af66fc99e Initial load
duke
parents:
diff changeset
317 const char* buf;
a61af66fc99e Initial load
duke
parents:
diff changeset
318
a61af66fc99e Initial load
duke
parents:
diff changeset
319 path = (jstring) env->GetStaticObjectField(clazz, imagePath_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
320 buf = env->GetStringUTFChars(path, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
321 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
322 AutoJavaString imagePath(env, path, buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
323
a61af66fc99e Initial load
duke
parents:
diff changeset
324 path = (jstring) env->GetStaticObjectField(clazz, symbolPath_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
325 buf = env->GetStringUTFChars(path, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
326 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
327 AutoJavaString symbolPath(env, path, buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
328
a61af66fc99e Initial load
duke
parents:
diff changeset
329 IDebugSymbols* ptrIDebugSymbols = (IDebugSymbols*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
330 ptrIDebugSymbols_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
331 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333 ptrIDebugSymbols->SetImagePath(imagePath);
a61af66fc99e Initial load
duke
parents:
diff changeset
334 ptrIDebugSymbols->SetSymbolPath(symbolPath);
a61af66fc99e Initial load
duke
parents:
diff changeset
335 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
337
a61af66fc99e Initial load
duke
parents:
diff changeset
338 static bool openDumpFile(JNIEnv* env, jobject obj, jstring coreFileName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 // open the dump file
a61af66fc99e Initial load
duke
parents:
diff changeset
340 jboolean isCopy;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 const char* buf = env->GetStringUTFChars(coreFileName, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
342 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
343 AutoJavaString coreFile(env, coreFileName, buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
344 if (setImageAndSymbolPath(env, obj) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
347
a61af66fc99e Initial load
duke
parents:
diff changeset
348 IDebugClient* ptrIDebugClient = (IDebugClient*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
349 ptrIDebugClient_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
350 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
351 if (ptrIDebugClient->OpenDumpFile(coreFile) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
352 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: OpenDumpFile failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
354
a61af66fc99e Initial load
duke
parents:
diff changeset
355 IDebugControl* ptrIDebugControl = (IDebugControl*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
356 ptrIDebugControl_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
357 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
358 if (ptrIDebugControl->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: WaitForEvent failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
361
a61af66fc99e Initial load
duke
parents:
diff changeset
362 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364
a61af66fc99e Initial load
duke
parents:
diff changeset
365
a61af66fc99e Initial load
duke
parents:
diff changeset
366 static bool attachToProcess(JNIEnv* env, jobject obj, jint pid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 if (setImageAndSymbolPath(env, obj) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370 IDebugClient* ptrIDebugClient = (IDebugClient*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
371 ptrIDebugClient_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
372 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374 /***********************************************************************************
a61af66fc99e Initial load
duke
parents:
diff changeset
375
a61af66fc99e Initial load
duke
parents:
diff changeset
376 We are attaching to a process in 'read-only' mode. i.e., we do not want to
a61af66fc99e Initial load
duke
parents:
diff changeset
377 put breakpoints, suspend/resume threads etc. For read-only JDI and HSDB kind of
a61af66fc99e Initial load
duke
parents:
diff changeset
378 usage this should suffice. We are not intending to use this for full-fledged
a61af66fc99e Initial load
duke
parents:
diff changeset
379 ProcessControl implementation to be used with BugSpotAgent.
a61af66fc99e Initial load
duke
parents:
diff changeset
380
a61af66fc99e Initial load
duke
parents:
diff changeset
381 Please refer to DEBUG_ATTACH_NONINVASIVE mode source comments from dbgeng.h.
a61af66fc99e Initial load
duke
parents:
diff changeset
382 In this mode, debug engine does not call DebugActiveProrcess. i.e., we are not
a61af66fc99e Initial load
duke
parents:
diff changeset
383 actually debugging at all. We can safely 'detach' from the process anytime
a61af66fc99e Initial load
duke
parents:
diff changeset
384 we want and debuggee process is left as is on all Windows variants.
a61af66fc99e Initial load
duke
parents:
diff changeset
385
a61af66fc99e Initial load
duke
parents:
diff changeset
386 This also makes JDI-on-SA installation/usage simpler because with this we would
a61af66fc99e Initial load
duke
parents:
diff changeset
387 not need a tool like ServiceInstaller from http://www.kcmultimedia.com/smaster.
a61af66fc99e Initial load
duke
parents:
diff changeset
388
a61af66fc99e Initial load
duke
parents:
diff changeset
389 ***********************************************************************************/
a61af66fc99e Initial load
duke
parents:
diff changeset
390
a61af66fc99e Initial load
duke
parents:
diff changeset
391
a61af66fc99e Initial load
duke
parents:
diff changeset
392 if (ptrIDebugClient->AttachProcess(0, pid, DEBUG_ATTACH_NONINVASIVE) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
393 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: AttachProcess failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
395
a61af66fc99e Initial load
duke
parents:
diff changeset
396 IDebugControl* ptrIDebugControl = (IDebugControl*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
397 ptrIDebugControl_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
398 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
399 if (ptrIDebugControl->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
400 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: WaitForEvent failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
401 }
a61af66fc99e Initial load
duke
parents:
diff changeset
402
a61af66fc99e Initial load
duke
parents:
diff changeset
403 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
405
a61af66fc99e Initial load
duke
parents:
diff changeset
406
a61af66fc99e Initial load
duke
parents:
diff changeset
407 static bool addLoadObjects(JNIEnv* env, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
408 IDebugSymbols* ptrIDebugSymbols = (IDebugSymbols*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
409 ptrIDebugSymbols_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
410 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
411 ULONG loaded = 0, unloaded = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
412 if (ptrIDebugSymbols->GetNumberModules(&loaded, &unloaded) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
413 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetNumberModules failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
414 }
a61af66fc99e Initial load
duke
parents:
diff changeset
415
a61af66fc99e Initial load
duke
parents:
diff changeset
416 AutoArrayPtr<DEBUG_MODULE_PARAMETERS> params(new DEBUG_MODULE_PARAMETERS[loaded]);
a61af66fc99e Initial load
duke
parents:
diff changeset
417
a61af66fc99e Initial load
duke
parents:
diff changeset
418 if (params.asPtr() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
419 THROW_NEW_DEBUGGER_EXCEPTION_("out of memory to allocate debug module params!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
421
a61af66fc99e Initial load
duke
parents:
diff changeset
422 if (ptrIDebugSymbols->GetModuleParameters(loaded, 0, NULL, params.asPtr()) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
423 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetModuleParameters failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
424 }
a61af66fc99e Initial load
duke
parents:
diff changeset
425
a61af66fc99e Initial load
duke
parents:
diff changeset
426 for (int u = 0; u < (int)loaded; u++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
427 TCHAR imageName[MAX_PATH];
a61af66fc99e Initial load
duke
parents:
diff changeset
428 if (ptrIDebugSymbols->GetModuleNames(DEBUG_ANY_ID, params.asPtr()[u].Base,
a61af66fc99e Initial load
duke
parents:
diff changeset
429 imageName, MAX_PATH, NULL, NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
430 0, NULL, NULL, 0, NULL) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
431 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetModuleNames failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
432 }
a61af66fc99e Initial load
duke
parents:
diff changeset
433
a61af66fc99e Initial load
duke
parents:
diff changeset
434 jstring strName = env->NewStringUTF(imageName);
a61af66fc99e Initial load
duke
parents:
diff changeset
435 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
436 env->CallVoidMethod(obj, addLoadObject_ID, strName, (jlong) params.asPtr()[u].Size,
a61af66fc99e Initial load
duke
parents:
diff changeset
437 (jlong) params.asPtr()[u].Base);
a61af66fc99e Initial load
duke
parents:
diff changeset
438 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
439 }
a61af66fc99e Initial load
duke
parents:
diff changeset
440
a61af66fc99e Initial load
duke
parents:
diff changeset
441 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
442 }
a61af66fc99e Initial load
duke
parents:
diff changeset
443
a61af66fc99e Initial load
duke
parents:
diff changeset
444 static bool addThreads(JNIEnv* env, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
445 IDebugSystemObjects* ptrIDebugSystemObjects = (IDebugSystemObjects*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
446 ptrIDebugSystemObjects_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
447 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
448
a61af66fc99e Initial load
duke
parents:
diff changeset
449 ULONG numThreads = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
450 if (ptrIDebugSystemObjects->GetNumberThreads(&numThreads) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
451 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetNumberThreads failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
452 }
a61af66fc99e Initial load
duke
parents:
diff changeset
453
a61af66fc99e Initial load
duke
parents:
diff changeset
454 AutoArrayPtr<ULONG> ptrSysThreadIds = new ULONG[numThreads];
a61af66fc99e Initial load
duke
parents:
diff changeset
455
a61af66fc99e Initial load
duke
parents:
diff changeset
456 if (ptrSysThreadIds.asPtr() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
457 THROW_NEW_DEBUGGER_EXCEPTION_("out of memory to allocate thread ids!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
458 }
a61af66fc99e Initial load
duke
parents:
diff changeset
459
a61af66fc99e Initial load
duke
parents:
diff changeset
460 AutoArrayPtr<ULONG> ptrThreadIds = new ULONG[numThreads];
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462 if (ptrThreadIds.asPtr() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 THROW_NEW_DEBUGGER_EXCEPTION_("out of memory to allocate thread ids!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
465
a61af66fc99e Initial load
duke
parents:
diff changeset
466 if (ptrIDebugSystemObjects->GetThreadIdsByIndex(0, numThreads,
a61af66fc99e Initial load
duke
parents:
diff changeset
467 ptrThreadIds.asPtr(), ptrSysThreadIds.asPtr()) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
468 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetThreadIdsByIndex failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
469 }
a61af66fc99e Initial load
duke
parents:
diff changeset
470
a61af66fc99e Initial load
duke
parents:
diff changeset
471
a61af66fc99e Initial load
duke
parents:
diff changeset
472 IDebugAdvanced* ptrIDebugAdvanced = (IDebugAdvanced*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
473 ptrIDebugAdvanced_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
474 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
475
a61af66fc99e Initial load
duke
parents:
diff changeset
476 // for each thread, get register context and save it.
a61af66fc99e Initial load
duke
parents:
diff changeset
477 for (ULONG t = 0; t < numThreads; t++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
478 if (ptrIDebugSystemObjects->SetCurrentThreadId(ptrThreadIds.asPtr()[t]) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
479 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: SetCurrentThread failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
480 }
a61af66fc99e Initial load
duke
parents:
diff changeset
481
a61af66fc99e Initial load
duke
parents:
diff changeset
482 jlongArray regs = env->NewLongArray(NPRGREG);
a61af66fc99e Initial load
duke
parents:
diff changeset
483 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
484
a61af66fc99e Initial load
duke
parents:
diff changeset
485 jboolean isCopy = JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
486 jlong* ptrRegs = env->GetLongArrayElements(regs, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
487 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
488
a61af66fc99e Initial load
duke
parents:
diff changeset
489 // copy register values from the CONTEXT struct
a61af66fc99e Initial load
duke
parents:
diff changeset
490 CONTEXT context;
a61af66fc99e Initial load
duke
parents:
diff changeset
491 memset(&context, 0, sizeof(CONTEXT));
a61af66fc99e Initial load
duke
parents:
diff changeset
492
a61af66fc99e Initial load
duke
parents:
diff changeset
493 #undef REG_INDEX
a61af66fc99e Initial load
duke
parents:
diff changeset
494 #ifdef _M_IA64
a61af66fc99e Initial load
duke
parents:
diff changeset
495 #define REG_INDEX(x) sun_jvm_hotspot_debugger_ia64_IA64ThreadContext_##x
a61af66fc99e Initial load
duke
parents:
diff changeset
496
a61af66fc99e Initial load
duke
parents:
diff changeset
497 context.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG;
a61af66fc99e Initial load
duke
parents:
diff changeset
498 ptrIDebugAdvanced->GetThreadContext(&context, sizeof(CONTEXT));
a61af66fc99e Initial load
duke
parents:
diff changeset
499
a61af66fc99e Initial load
duke
parents:
diff changeset
500 ptrRegs[REG_INDEX(GR0)] = 0; // always 0
a61af66fc99e Initial load
duke
parents:
diff changeset
501 ptrRegs[REG_INDEX(GR1)] = context.IntGp; // r1
a61af66fc99e Initial load
duke
parents:
diff changeset
502 ptrRegs[REG_INDEX(GR2)] = context.IntT0; // r2-r3
a61af66fc99e Initial load
duke
parents:
diff changeset
503 ptrRegs[REG_INDEX(GR3)] = context.IntT1;
a61af66fc99e Initial load
duke
parents:
diff changeset
504 ptrRegs[REG_INDEX(GR4)] = context.IntS0; // r4-r7
a61af66fc99e Initial load
duke
parents:
diff changeset
505 ptrRegs[REG_INDEX(GR5)] = context.IntS1;
a61af66fc99e Initial load
duke
parents:
diff changeset
506 ptrRegs[REG_INDEX(GR6)] = context.IntS2;
a61af66fc99e Initial load
duke
parents:
diff changeset
507 ptrRegs[REG_INDEX(GR7)] = context.IntS3;
a61af66fc99e Initial load
duke
parents:
diff changeset
508 ptrRegs[REG_INDEX(GR8)] = context.IntV0; // r8
a61af66fc99e Initial load
duke
parents:
diff changeset
509 ptrRegs[REG_INDEX(GR9)] = context.IntT2; // r9-r11
a61af66fc99e Initial load
duke
parents:
diff changeset
510 ptrRegs[REG_INDEX(GR10)] = context.IntT3;
a61af66fc99e Initial load
duke
parents:
diff changeset
511 ptrRegs[REG_INDEX(GR11)] = context.IntT4;
a61af66fc99e Initial load
duke
parents:
diff changeset
512 ptrRegs[REG_INDEX(GR12)] = context.IntSp; // r12 stack pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
513 ptrRegs[REG_INDEX(GR13)] = context.IntTeb; // r13 teb
a61af66fc99e Initial load
duke
parents:
diff changeset
514 ptrRegs[REG_INDEX(GR14)] = context.IntT5; // r14-r31
a61af66fc99e Initial load
duke
parents:
diff changeset
515 ptrRegs[REG_INDEX(GR15)] = context.IntT6;
a61af66fc99e Initial load
duke
parents:
diff changeset
516 ptrRegs[REG_INDEX(GR16)] = context.IntT7;
a61af66fc99e Initial load
duke
parents:
diff changeset
517 ptrRegs[REG_INDEX(GR17)] = context.IntT8;
a61af66fc99e Initial load
duke
parents:
diff changeset
518 ptrRegs[REG_INDEX(GR18)] = context.IntT9;
a61af66fc99e Initial load
duke
parents:
diff changeset
519 ptrRegs[REG_INDEX(GR19)] = context.IntT10;
a61af66fc99e Initial load
duke
parents:
diff changeset
520 ptrRegs[REG_INDEX(GR20)] = context.IntT11;
a61af66fc99e Initial load
duke
parents:
diff changeset
521 ptrRegs[REG_INDEX(GR21)] = context.IntT12;
a61af66fc99e Initial load
duke
parents:
diff changeset
522 ptrRegs[REG_INDEX(GR22)] = context.IntT13;
a61af66fc99e Initial load
duke
parents:
diff changeset
523 ptrRegs[REG_INDEX(GR23)] = context.IntT14;
a61af66fc99e Initial load
duke
parents:
diff changeset
524 ptrRegs[REG_INDEX(GR24)] = context.IntT15;
a61af66fc99e Initial load
duke
parents:
diff changeset
525 ptrRegs[REG_INDEX(GR25)] = context.IntT16;
a61af66fc99e Initial load
duke
parents:
diff changeset
526 ptrRegs[REG_INDEX(GR26)] = context.IntT17;
a61af66fc99e Initial load
duke
parents:
diff changeset
527 ptrRegs[REG_INDEX(GR27)] = context.IntT18;
a61af66fc99e Initial load
duke
parents:
diff changeset
528 ptrRegs[REG_INDEX(GR28)] = context.IntT19;
a61af66fc99e Initial load
duke
parents:
diff changeset
529 ptrRegs[REG_INDEX(GR29)] = context.IntT20;
a61af66fc99e Initial load
duke
parents:
diff changeset
530 ptrRegs[REG_INDEX(GR30)] = context.IntT21;
a61af66fc99e Initial load
duke
parents:
diff changeset
531 ptrRegs[REG_INDEX(GR31)] = context.IntT22;
a61af66fc99e Initial load
duke
parents:
diff changeset
532
a61af66fc99e Initial load
duke
parents:
diff changeset
533 ptrRegs[REG_INDEX(INT_NATS)] = context.IntNats;
a61af66fc99e Initial load
duke
parents:
diff changeset
534 ptrRegs[REG_INDEX(PREDS)] = context.Preds;
a61af66fc99e Initial load
duke
parents:
diff changeset
535
a61af66fc99e Initial load
duke
parents:
diff changeset
536 ptrRegs[REG_INDEX(BR_RP)] = context.BrRp;
a61af66fc99e Initial load
duke
parents:
diff changeset
537 ptrRegs[REG_INDEX(BR1)] = context.BrS0; // b1-b5
a61af66fc99e Initial load
duke
parents:
diff changeset
538 ptrRegs[REG_INDEX(BR2)] = context.BrS1;
a61af66fc99e Initial load
duke
parents:
diff changeset
539 ptrRegs[REG_INDEX(BR3)] = context.BrS2;
a61af66fc99e Initial load
duke
parents:
diff changeset
540 ptrRegs[REG_INDEX(BR4)] = context.BrS3;
a61af66fc99e Initial load
duke
parents:
diff changeset
541 ptrRegs[REG_INDEX(BR5)] = context.BrS4;
a61af66fc99e Initial load
duke
parents:
diff changeset
542 ptrRegs[REG_INDEX(BR6)] = context.BrT0; // b6-b7
a61af66fc99e Initial load
duke
parents:
diff changeset
543 ptrRegs[REG_INDEX(BR7)] = context.BrT1;
a61af66fc99e Initial load
duke
parents:
diff changeset
544
a61af66fc99e Initial load
duke
parents:
diff changeset
545 ptrRegs[REG_INDEX(AP_UNAT)] = context.ApUNAT;
a61af66fc99e Initial load
duke
parents:
diff changeset
546 ptrRegs[REG_INDEX(AP_LC)] = context.ApLC;
a61af66fc99e Initial load
duke
parents:
diff changeset
547 ptrRegs[REG_INDEX(AP_EC)] = context.ApEC;
a61af66fc99e Initial load
duke
parents:
diff changeset
548 ptrRegs[REG_INDEX(AP_CCV)] = context.ApCCV;
a61af66fc99e Initial load
duke
parents:
diff changeset
549 ptrRegs[REG_INDEX(AP_DCR)] = context.ApDCR;
a61af66fc99e Initial load
duke
parents:
diff changeset
550
a61af66fc99e Initial load
duke
parents:
diff changeset
551 ptrRegs[REG_INDEX(RS_PFS)] = context.RsPFS;
a61af66fc99e Initial load
duke
parents:
diff changeset
552 ptrRegs[REG_INDEX(RS_BSP)] = context.RsBSP;
a61af66fc99e Initial load
duke
parents:
diff changeset
553 ptrRegs[REG_INDEX(RS_BSPSTORE)] = context.RsBSPSTORE;
a61af66fc99e Initial load
duke
parents:
diff changeset
554 ptrRegs[REG_INDEX(RS_RSC)] = context.RsRSC;
a61af66fc99e Initial load
duke
parents:
diff changeset
555 ptrRegs[REG_INDEX(RS_RNAT)] = context.RsRNAT;
a61af66fc99e Initial load
duke
parents:
diff changeset
556
a61af66fc99e Initial load
duke
parents:
diff changeset
557 ptrRegs[REG_INDEX(ST_IPSR)] = context.StIPSR;
a61af66fc99e Initial load
duke
parents:
diff changeset
558 ptrRegs[REG_INDEX(ST_IIP)] = context.StIIP;
a61af66fc99e Initial load
duke
parents:
diff changeset
559 ptrRegs[REG_INDEX(ST_IFS)] = context.StIFS;
a61af66fc99e Initial load
duke
parents:
diff changeset
560
a61af66fc99e Initial load
duke
parents:
diff changeset
561 ptrRegs[REG_INDEX(DB_I0)] = context.DbI0;
a61af66fc99e Initial load
duke
parents:
diff changeset
562 ptrRegs[REG_INDEX(DB_I1)] = context.DbI1;
a61af66fc99e Initial load
duke
parents:
diff changeset
563 ptrRegs[REG_INDEX(DB_I2)] = context.DbI2;
a61af66fc99e Initial load
duke
parents:
diff changeset
564 ptrRegs[REG_INDEX(DB_I3)] = context.DbI3;
a61af66fc99e Initial load
duke
parents:
diff changeset
565 ptrRegs[REG_INDEX(DB_I4)] = context.DbI4;
a61af66fc99e Initial load
duke
parents:
diff changeset
566 ptrRegs[REG_INDEX(DB_I5)] = context.DbI5;
a61af66fc99e Initial load
duke
parents:
diff changeset
567 ptrRegs[REG_INDEX(DB_I6)] = context.DbI6;
a61af66fc99e Initial load
duke
parents:
diff changeset
568 ptrRegs[REG_INDEX(DB_I7)] = context.DbI7;
a61af66fc99e Initial load
duke
parents:
diff changeset
569
a61af66fc99e Initial load
duke
parents:
diff changeset
570 ptrRegs[REG_INDEX(DB_D0)] = context.DbD0;
a61af66fc99e Initial load
duke
parents:
diff changeset
571 ptrRegs[REG_INDEX(DB_D1)] = context.DbD1;
a61af66fc99e Initial load
duke
parents:
diff changeset
572 ptrRegs[REG_INDEX(DB_D2)] = context.DbD2;
a61af66fc99e Initial load
duke
parents:
diff changeset
573 ptrRegs[REG_INDEX(DB_D3)] = context.DbD3;
a61af66fc99e Initial load
duke
parents:
diff changeset
574 ptrRegs[REG_INDEX(DB_D4)] = context.DbD4;
a61af66fc99e Initial load
duke
parents:
diff changeset
575 ptrRegs[REG_INDEX(DB_D5)] = context.DbD5;
a61af66fc99e Initial load
duke
parents:
diff changeset
576 ptrRegs[REG_INDEX(DB_D6)] = context.DbD6;
a61af66fc99e Initial load
duke
parents:
diff changeset
577 ptrRegs[REG_INDEX(DB_D7)] = context.DbD7;
a61af66fc99e Initial load
duke
parents:
diff changeset
578
a61af66fc99e Initial load
duke
parents:
diff changeset
579 #elif _M_IX86
a61af66fc99e Initial load
duke
parents:
diff changeset
580 #define REG_INDEX(x) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##x
a61af66fc99e Initial load
duke
parents:
diff changeset
581
a61af66fc99e Initial load
duke
parents:
diff changeset
582 context.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
a61af66fc99e Initial load
duke
parents:
diff changeset
583 ptrIDebugAdvanced->GetThreadContext(&context, sizeof(CONTEXT));
a61af66fc99e Initial load
duke
parents:
diff changeset
584
a61af66fc99e Initial load
duke
parents:
diff changeset
585 ptrRegs[REG_INDEX(GS)] = context.SegGs;
a61af66fc99e Initial load
duke
parents:
diff changeset
586 ptrRegs[REG_INDEX(FS)] = context.SegFs;
a61af66fc99e Initial load
duke
parents:
diff changeset
587 ptrRegs[REG_INDEX(ES)] = context.SegEs;
a61af66fc99e Initial load
duke
parents:
diff changeset
588 ptrRegs[REG_INDEX(DS)] = context.SegDs;
a61af66fc99e Initial load
duke
parents:
diff changeset
589
a61af66fc99e Initial load
duke
parents:
diff changeset
590 ptrRegs[REG_INDEX(EDI)] = context.Edi;
a61af66fc99e Initial load
duke
parents:
diff changeset
591 ptrRegs[REG_INDEX(ESI)] = context.Esi;
a61af66fc99e Initial load
duke
parents:
diff changeset
592 ptrRegs[REG_INDEX(EBX)] = context.Ebx;
a61af66fc99e Initial load
duke
parents:
diff changeset
593 ptrRegs[REG_INDEX(EDX)] = context.Edx;
a61af66fc99e Initial load
duke
parents:
diff changeset
594 ptrRegs[REG_INDEX(ECX)] = context.Ecx;
a61af66fc99e Initial load
duke
parents:
diff changeset
595 ptrRegs[REG_INDEX(EAX)] = context.Eax;
a61af66fc99e Initial load
duke
parents:
diff changeset
596
a61af66fc99e Initial load
duke
parents:
diff changeset
597 ptrRegs[REG_INDEX(FP)] = context.Ebp;
a61af66fc99e Initial load
duke
parents:
diff changeset
598 ptrRegs[REG_INDEX(PC)] = context.Eip;
a61af66fc99e Initial load
duke
parents:
diff changeset
599 ptrRegs[REG_INDEX(CS)] = context.SegCs;
a61af66fc99e Initial load
duke
parents:
diff changeset
600 ptrRegs[REG_INDEX(EFL)] = context.EFlags;
a61af66fc99e Initial load
duke
parents:
diff changeset
601 ptrRegs[REG_INDEX(SP)] = context.Esp;
a61af66fc99e Initial load
duke
parents:
diff changeset
602 ptrRegs[REG_INDEX(SS)] = context.SegSs;
a61af66fc99e Initial load
duke
parents:
diff changeset
603
a61af66fc99e Initial load
duke
parents:
diff changeset
604 ptrRegs[REG_INDEX(DR0)] = context.Dr0;
a61af66fc99e Initial load
duke
parents:
diff changeset
605 ptrRegs[REG_INDEX(DR1)] = context.Dr1;
a61af66fc99e Initial load
duke
parents:
diff changeset
606 ptrRegs[REG_INDEX(DR2)] = context.Dr2;
a61af66fc99e Initial load
duke
parents:
diff changeset
607 ptrRegs[REG_INDEX(DR3)] = context.Dr3;
a61af66fc99e Initial load
duke
parents:
diff changeset
608 ptrRegs[REG_INDEX(DR6)] = context.Dr6;
a61af66fc99e Initial load
duke
parents:
diff changeset
609 ptrRegs[REG_INDEX(DR7)] = context.Dr7;
a61af66fc99e Initial load
duke
parents:
diff changeset
610
a61af66fc99e Initial load
duke
parents:
diff changeset
611 #elif _M_AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
612 #define REG_INDEX(x) sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_##x
a61af66fc99e Initial load
duke
parents:
diff changeset
613
a61af66fc99e Initial load
duke
parents:
diff changeset
614 context.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
a61af66fc99e Initial load
duke
parents:
diff changeset
615 ptrIDebugAdvanced->GetThreadContext(&context, sizeof(CONTEXT));
a61af66fc99e Initial load
duke
parents:
diff changeset
616
a61af66fc99e Initial load
duke
parents:
diff changeset
617 // Segment Registers and processor flags
a61af66fc99e Initial load
duke
parents:
diff changeset
618 ptrRegs[REG_INDEX(CS)] = context.SegCs;
a61af66fc99e Initial load
duke
parents:
diff changeset
619 ptrRegs[REG_INDEX(DS)] = context.SegDs;
a61af66fc99e Initial load
duke
parents:
diff changeset
620 ptrRegs[REG_INDEX(ES)] = context.SegEs;
a61af66fc99e Initial load
duke
parents:
diff changeset
621 ptrRegs[REG_INDEX(FS)] = context.SegFs;
a61af66fc99e Initial load
duke
parents:
diff changeset
622 ptrRegs[REG_INDEX(GS)] = context.SegGs;
a61af66fc99e Initial load
duke
parents:
diff changeset
623 ptrRegs[REG_INDEX(SS)] = context.SegSs;
a61af66fc99e Initial load
duke
parents:
diff changeset
624 ptrRegs[REG_INDEX(RFL)] = context.EFlags;
a61af66fc99e Initial load
duke
parents:
diff changeset
625
a61af66fc99e Initial load
duke
parents:
diff changeset
626 // Integer registers
a61af66fc99e Initial load
duke
parents:
diff changeset
627 ptrRegs[REG_INDEX(RDI)] = context.Rdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
628 ptrRegs[REG_INDEX(RSI)] = context.Rsi;
a61af66fc99e Initial load
duke
parents:
diff changeset
629 ptrRegs[REG_INDEX(RAX)] = context.Rax;
a61af66fc99e Initial load
duke
parents:
diff changeset
630 ptrRegs[REG_INDEX(RCX)] = context.Rcx;
a61af66fc99e Initial load
duke
parents:
diff changeset
631 ptrRegs[REG_INDEX(RDX)] = context.Rdx;
a61af66fc99e Initial load
duke
parents:
diff changeset
632 ptrRegs[REG_INDEX(RBX)] = context.Rbx;
a61af66fc99e Initial load
duke
parents:
diff changeset
633 ptrRegs[REG_INDEX(RBP)] = context.Rbp;
a61af66fc99e Initial load
duke
parents:
diff changeset
634 ptrRegs[REG_INDEX(RSP)] = context.Rsp;
a61af66fc99e Initial load
duke
parents:
diff changeset
635
a61af66fc99e Initial load
duke
parents:
diff changeset
636 ptrRegs[REG_INDEX(R8)] = context.R8;
a61af66fc99e Initial load
duke
parents:
diff changeset
637 ptrRegs[REG_INDEX(R9)] = context.R9;
a61af66fc99e Initial load
duke
parents:
diff changeset
638 ptrRegs[REG_INDEX(R10)] = context.R10;
a61af66fc99e Initial load
duke
parents:
diff changeset
639 ptrRegs[REG_INDEX(R11)] = context.R11;
a61af66fc99e Initial load
duke
parents:
diff changeset
640 ptrRegs[REG_INDEX(R12)] = context.R12;
a61af66fc99e Initial load
duke
parents:
diff changeset
641 ptrRegs[REG_INDEX(R13)] = context.R13;
a61af66fc99e Initial load
duke
parents:
diff changeset
642 ptrRegs[REG_INDEX(R14)] = context.R14;
a61af66fc99e Initial load
duke
parents:
diff changeset
643 ptrRegs[REG_INDEX(R15)] = context.R15;
a61af66fc99e Initial load
duke
parents:
diff changeset
644
a61af66fc99e Initial load
duke
parents:
diff changeset
645 // Program counter
a61af66fc99e Initial load
duke
parents:
diff changeset
646 ptrRegs[REG_INDEX(RIP)] = context.Rip;
a61af66fc99e Initial load
duke
parents:
diff changeset
647 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
648
a61af66fc99e Initial load
duke
parents:
diff changeset
649 env->ReleaseLongArrayElements(regs, ptrRegs, JNI_COMMIT);
a61af66fc99e Initial load
duke
parents:
diff changeset
650 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
651
a61af66fc99e Initial load
duke
parents:
diff changeset
652 env->CallVoidMethod(obj, setThreadIntegerRegisterSet_ID,
a61af66fc99e Initial load
duke
parents:
diff changeset
653 (jlong) ptrThreadIds.asPtr()[t], regs);
a61af66fc99e Initial load
duke
parents:
diff changeset
654 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
655
a61af66fc99e Initial load
duke
parents:
diff changeset
656 ULONG sysId;
a61af66fc99e Initial load
duke
parents:
diff changeset
657 if (ptrIDebugSystemObjects->GetCurrentThreadSystemId(&sysId) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
658 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetCurrentThreadSystemId failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
659 }
a61af66fc99e Initial load
duke
parents:
diff changeset
660
a61af66fc99e Initial load
duke
parents:
diff changeset
661 env->CallVoidMethod(obj, addThread_ID, (jlong) sysId);
a61af66fc99e Initial load
duke
parents:
diff changeset
662 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
663 }
a61af66fc99e Initial load
duke
parents:
diff changeset
664
a61af66fc99e Initial load
duke
parents:
diff changeset
665 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
666 }
a61af66fc99e Initial load
duke
parents:
diff changeset
667
a61af66fc99e Initial load
duke
parents:
diff changeset
668 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
669 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
670 * Method: attach0
a61af66fc99e Initial load
duke
parents:
diff changeset
671 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
a61af66fc99e Initial load
duke
parents:
diff changeset
672 */
a61af66fc99e Initial load
duke
parents:
diff changeset
673 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2
a61af66fc99e Initial load
duke
parents:
diff changeset
674 (JNIEnv *env, jobject obj, jstring execName, jstring coreFileName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
675
a61af66fc99e Initial load
duke
parents:
diff changeset
676 if (getWindbgInterfaces(env, obj) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
677 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
678 }
a61af66fc99e Initial load
duke
parents:
diff changeset
679
a61af66fc99e Initial load
duke
parents:
diff changeset
680 if (openDumpFile(env, obj, coreFileName) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
681 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
682 }
a61af66fc99e Initial load
duke
parents:
diff changeset
683
a61af66fc99e Initial load
duke
parents:
diff changeset
684 if (addLoadObjects(env, obj) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
685 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
686 }
a61af66fc99e Initial load
duke
parents:
diff changeset
687
a61af66fc99e Initial load
duke
parents:
diff changeset
688 if (addThreads(env, obj) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
689 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
690 }
a61af66fc99e Initial load
duke
parents:
diff changeset
691 }
a61af66fc99e Initial load
duke
parents:
diff changeset
692
a61af66fc99e Initial load
duke
parents:
diff changeset
693 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
694 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
695 * Method: attach0
a61af66fc99e Initial load
duke
parents:
diff changeset
696 * Signature: (I)V
a61af66fc99e Initial load
duke
parents:
diff changeset
697 */
a61af66fc99e Initial load
duke
parents:
diff changeset
698 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_attach0__I
a61af66fc99e Initial load
duke
parents:
diff changeset
699 (JNIEnv *env, jobject obj, jint pid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
700
a61af66fc99e Initial load
duke
parents:
diff changeset
701 if (getWindbgInterfaces(env, obj) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
702 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
703 }
a61af66fc99e Initial load
duke
parents:
diff changeset
704
a61af66fc99e Initial load
duke
parents:
diff changeset
705 if (attachToProcess(env, obj, pid) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
706 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
707 }
a61af66fc99e Initial load
duke
parents:
diff changeset
708
a61af66fc99e Initial load
duke
parents:
diff changeset
709 if (addLoadObjects(env, obj) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
710 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
711 }
a61af66fc99e Initial load
duke
parents:
diff changeset
712
a61af66fc99e Initial load
duke
parents:
diff changeset
713 if (addThreads(env, obj) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
714 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
715 }
a61af66fc99e Initial load
duke
parents:
diff changeset
716 }
a61af66fc99e Initial load
duke
parents:
diff changeset
717
a61af66fc99e Initial load
duke
parents:
diff changeset
718
a61af66fc99e Initial load
duke
parents:
diff changeset
719 static bool releaseWindbgInterfaces(JNIEnv* env, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
720 IDebugDataSpaces* ptrIDebugDataSpaces = (IDebugDataSpaces*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
721 ptrIDebugDataSpaces_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
722 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
723 if (ptrIDebugDataSpaces != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
724 ptrIDebugDataSpaces->Release();
a61af66fc99e Initial load
duke
parents:
diff changeset
725 }
a61af66fc99e Initial load
duke
parents:
diff changeset
726
a61af66fc99e Initial load
duke
parents:
diff changeset
727 IDebugOutputCallbacks* ptrIDebugOutputCallbacks = (IDebugOutputCallbacks*)
a61af66fc99e Initial load
duke
parents:
diff changeset
728 env->GetLongField(obj, ptrIDebugOutputCallbacks_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
729 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
730 if (ptrIDebugOutputCallbacks != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
731 ptrIDebugOutputCallbacks->Release();
a61af66fc99e Initial load
duke
parents:
diff changeset
732 }
a61af66fc99e Initial load
duke
parents:
diff changeset
733
a61af66fc99e Initial load
duke
parents:
diff changeset
734 IDebugAdvanced* ptrIDebugAdvanced = (IDebugAdvanced*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
735 ptrIDebugAdvanced_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
736 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
737
a61af66fc99e Initial load
duke
parents:
diff changeset
738 if (ptrIDebugAdvanced != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
739 ptrIDebugAdvanced->Release();
a61af66fc99e Initial load
duke
parents:
diff changeset
740 }
a61af66fc99e Initial load
duke
parents:
diff changeset
741
a61af66fc99e Initial load
duke
parents:
diff changeset
742 IDebugSymbols* ptrIDebugSymbols = (IDebugSymbols*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
743 ptrIDebugSymbols_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
744 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
745 if (ptrIDebugSymbols != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
746 ptrIDebugSymbols->Release();
a61af66fc99e Initial load
duke
parents:
diff changeset
747 }
a61af66fc99e Initial load
duke
parents:
diff changeset
748
a61af66fc99e Initial load
duke
parents:
diff changeset
749 IDebugSystemObjects* ptrIDebugSystemObjects = (IDebugSystemObjects*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
750 ptrIDebugSystemObjects_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
751 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
752 if (ptrIDebugSystemObjects != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
753 ptrIDebugSystemObjects->Release();
a61af66fc99e Initial load
duke
parents:
diff changeset
754 }
a61af66fc99e Initial load
duke
parents:
diff changeset
755
a61af66fc99e Initial load
duke
parents:
diff changeset
756 IDebugControl* ptrIDebugControl = (IDebugControl*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
757 ptrIDebugControl_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
758 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
759 if (ptrIDebugControl != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
760 ptrIDebugControl->Release();
a61af66fc99e Initial load
duke
parents:
diff changeset
761 }
a61af66fc99e Initial load
duke
parents:
diff changeset
762
a61af66fc99e Initial load
duke
parents:
diff changeset
763 IDebugClient* ptrIDebugClient = (IDebugClient*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
764 ptrIDebugClient_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
765 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
766 if (ptrIDebugClient != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
767 ptrIDebugClient->Release();
a61af66fc99e Initial load
duke
parents:
diff changeset
768 }
a61af66fc99e Initial load
duke
parents:
diff changeset
769
a61af66fc99e Initial load
duke
parents:
diff changeset
770 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
771 }
a61af66fc99e Initial load
duke
parents:
diff changeset
772
a61af66fc99e Initial load
duke
parents:
diff changeset
773 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
774 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
775 * Method: detach0
a61af66fc99e Initial load
duke
parents:
diff changeset
776 * Signature: ()V
a61af66fc99e Initial load
duke
parents:
diff changeset
777 */
a61af66fc99e Initial load
duke
parents:
diff changeset
778 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_detach0
a61af66fc99e Initial load
duke
parents:
diff changeset
779 (JNIEnv *env, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
780 IDebugClient* ptrIDebugClient = (IDebugClient*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
781 ptrIDebugClient_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
782 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
783 ptrIDebugClient->DetachProcesses();
a61af66fc99e Initial load
duke
parents:
diff changeset
784 releaseWindbgInterfaces(env, obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
785 }
a61af66fc99e Initial load
duke
parents:
diff changeset
786
a61af66fc99e Initial load
duke
parents:
diff changeset
787
a61af66fc99e Initial load
duke
parents:
diff changeset
788 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
789 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
790 * Method: readBytesFromProcess0
a61af66fc99e Initial load
duke
parents:
diff changeset
791 * Signature: (JJ)[B
a61af66fc99e Initial load
duke
parents:
diff changeset
792 */
a61af66fc99e Initial load
duke
parents:
diff changeset
793 JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_readBytesFromProcess0
a61af66fc99e Initial load
duke
parents:
diff changeset
794 (JNIEnv *env, jobject obj, jlong address, jlong numBytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
795 jbyteArray byteArray = env->NewByteArray((long) numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
796 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
797
a61af66fc99e Initial load
duke
parents:
diff changeset
798 jboolean isCopy = JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
799 jbyte* bytePtr = env->GetByteArrayElements(byteArray, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
800 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
801
a61af66fc99e Initial load
duke
parents:
diff changeset
802 IDebugDataSpaces* ptrIDebugDataSpaces = (IDebugDataSpaces*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
803 ptrIDebugDataSpaces_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
804 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
805
a61af66fc99e Initial load
duke
parents:
diff changeset
806 ULONG bytesRead;
a61af66fc99e Initial load
duke
parents:
diff changeset
807 if (ptrIDebugDataSpaces->ReadVirtual((ULONG64) address, (PVOID) bytePtr,
a61af66fc99e Initial load
duke
parents:
diff changeset
808 (ULONG)numBytes, &bytesRead) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
809 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: ReadVirtual failed!", 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
810 }
a61af66fc99e Initial load
duke
parents:
diff changeset
811
a61af66fc99e Initial load
duke
parents:
diff changeset
812 if (bytesRead != numBytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
813 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
814 }
a61af66fc99e Initial load
duke
parents:
diff changeset
815
a61af66fc99e Initial load
duke
parents:
diff changeset
816 env->ReleaseByteArrayElements(byteArray, bytePtr, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
817 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
818
a61af66fc99e Initial load
duke
parents:
diff changeset
819 return byteArray;
a61af66fc99e Initial load
duke
parents:
diff changeset
820 }
a61af66fc99e Initial load
duke
parents:
diff changeset
821
a61af66fc99e Initial load
duke
parents:
diff changeset
822 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
823 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
824 * Method: getThreadIdFromSysId0
a61af66fc99e Initial load
duke
parents:
diff changeset
825 * Signature: (J)J
a61af66fc99e Initial load
duke
parents:
diff changeset
826 */
a61af66fc99e Initial load
duke
parents:
diff changeset
827 JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_getThreadIdFromSysId0
a61af66fc99e Initial load
duke
parents:
diff changeset
828 (JNIEnv *env, jobject obj, jlong sysId) {
a61af66fc99e Initial load
duke
parents:
diff changeset
829 IDebugSystemObjects* ptrIDebugSystemObjects = (IDebugSystemObjects*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
830 ptrIDebugSystemObjects_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
831 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
832
a61af66fc99e Initial load
duke
parents:
diff changeset
833 ULONG id = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
834 if (ptrIDebugSystemObjects->GetThreadIdBySystemId((ULONG)sysId, &id) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
835 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetThreadIdBySystemId failed!", 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
836 }
a61af66fc99e Initial load
duke
parents:
diff changeset
837
a61af66fc99e Initial load
duke
parents:
diff changeset
838 return (jlong) id;
a61af66fc99e Initial load
duke
parents:
diff changeset
839 }
a61af66fc99e Initial load
duke
parents:
diff changeset
840
a61af66fc99e Initial load
duke
parents:
diff changeset
841 // manage COM 'auto' pointers (to avoid multiple Release
a61af66fc99e Initial load
duke
parents:
diff changeset
842 // calls at every early (exception) returns). Similar to AutoArrayPtr.
a61af66fc99e Initial load
duke
parents:
diff changeset
843
a61af66fc99e Initial load
duke
parents:
diff changeset
844 template <class T>
a61af66fc99e Initial load
duke
parents:
diff changeset
845 class AutoCOMPtr {
a61af66fc99e Initial load
duke
parents:
diff changeset
846 T* m_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
847
a61af66fc99e Initial load
duke
parents:
diff changeset
848 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
849 AutoCOMPtr(T* ptr) : m_ptr(ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
850 }
a61af66fc99e Initial load
duke
parents:
diff changeset
851
a61af66fc99e Initial load
duke
parents:
diff changeset
852 ~AutoCOMPtr() {
a61af66fc99e Initial load
duke
parents:
diff changeset
853 if (m_ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
854 m_ptr->Release();
a61af66fc99e Initial load
duke
parents:
diff changeset
855 }
a61af66fc99e Initial load
duke
parents:
diff changeset
856 }
a61af66fc99e Initial load
duke
parents:
diff changeset
857
a61af66fc99e Initial load
duke
parents:
diff changeset
858 T* operator->() {
a61af66fc99e Initial load
duke
parents:
diff changeset
859 return m_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
860 }
a61af66fc99e Initial load
duke
parents:
diff changeset
861 };
a61af66fc99e Initial load
duke
parents:
diff changeset
862
a61af66fc99e Initial load
duke
parents:
diff changeset
863 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
864 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
865 * Method: consoleExecuteCommand0
a61af66fc99e Initial load
duke
parents:
diff changeset
866 * Signature: (Ljava/lang/String;)Ljava/lang/String;
a61af66fc99e Initial load
duke
parents:
diff changeset
867 */
a61af66fc99e Initial load
duke
parents:
diff changeset
868 JNIEXPORT jstring JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_consoleExecuteCommand0
a61af66fc99e Initial load
duke
parents:
diff changeset
869 (JNIEnv *env, jobject obj, jstring cmd) {
a61af66fc99e Initial load
duke
parents:
diff changeset
870 jboolean isCopy = JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
871 const char* buf = env->GetStringUTFChars(cmd, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
872 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
873 AutoJavaString command(env, cmd, buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
874
a61af66fc99e Initial load
duke
parents:
diff changeset
875 IDebugClient* ptrIDebugClient = (IDebugClient*) env->GetLongField(obj, ptrIDebugClient_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
876 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
877
a61af66fc99e Initial load
duke
parents:
diff changeset
878 IDebugClient* tmpClientPtr = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
879 if (ptrIDebugClient->CreateClient(&tmpClientPtr) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
880 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: CreateClient failed!", 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
881 }
a61af66fc99e Initial load
duke
parents:
diff changeset
882 AutoCOMPtr<IDebugClient> tmpClient(tmpClientPtr);
a61af66fc99e Initial load
duke
parents:
diff changeset
883
a61af66fc99e Initial load
duke
parents:
diff changeset
884 IDebugControl* tmpControlPtr = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
885 if (tmpClient->QueryInterface(__uuidof(IDebugControl), (PVOID*) &tmpControlPtr) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
886 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: QueryInterface (IDebugControl) failed", 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
887 }
a61af66fc99e Initial load
duke
parents:
diff changeset
888 AutoCOMPtr<IDebugControl> tmpControl(tmpControlPtr);
a61af66fc99e Initial load
duke
parents:
diff changeset
889
a61af66fc99e Initial load
duke
parents:
diff changeset
890 SAOutputCallbacks* saOutputCallbacks = (SAOutputCallbacks*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
891 ptrIDebugOutputCallbacks_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
892 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
893
a61af66fc99e Initial load
duke
parents:
diff changeset
894 saOutputCallbacks->clearBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
895
a61af66fc99e Initial load
duke
parents:
diff changeset
896 if (tmpClient->SetOutputCallbacks(saOutputCallbacks) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
897 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: SetOutputCallbacks failed!", 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
898 }
a61af66fc99e Initial load
duke
parents:
diff changeset
899
a61af66fc99e Initial load
duke
parents:
diff changeset
900 tmpControl->Execute(DEBUG_OUTPUT_VERBOSE, command, DEBUG_EXECUTE_DEFAULT);
a61af66fc99e Initial load
duke
parents:
diff changeset
901
a61af66fc99e Initial load
duke
parents:
diff changeset
902 const char* output = saOutputCallbacks->getBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
903 if (output == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
904 output = "";
a61af66fc99e Initial load
duke
parents:
diff changeset
905 }
a61af66fc99e Initial load
duke
parents:
diff changeset
906
a61af66fc99e Initial load
duke
parents:
diff changeset
907 jstring res = env->NewStringUTF(output);
a61af66fc99e Initial load
duke
parents:
diff changeset
908 saOutputCallbacks->clearBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
909 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
910 }
a61af66fc99e Initial load
duke
parents:
diff changeset
911
a61af66fc99e Initial load
duke
parents:
diff changeset
912 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
913 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
914 * Method: lookupByName0
a61af66fc99e Initial load
duke
parents:
diff changeset
915 * Signature: (Ljava/lang/String;Ljava/lang/String;)J
a61af66fc99e Initial load
duke
parents:
diff changeset
916 */
a61af66fc99e Initial load
duke
parents:
diff changeset
917
a61af66fc99e Initial load
duke
parents:
diff changeset
918 JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_lookupByName0
a61af66fc99e Initial load
duke
parents:
diff changeset
919 (JNIEnv *env, jobject obj, jstring objName, jstring sym) {
a61af66fc99e Initial load
duke
parents:
diff changeset
920 IDebugSymbols* ptrIDebugSymbols = (IDebugSymbols*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
921 ptrIDebugSymbols_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
922 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
923
a61af66fc99e Initial load
duke
parents:
diff changeset
924 jboolean isCopy;
a61af66fc99e Initial load
duke
parents:
diff changeset
925 const char* buf = env->GetStringUTFChars(sym, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
926 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
927 AutoJavaString name(env, sym, buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
928
a61af66fc99e Initial load
duke
parents:
diff changeset
929 ULONG64 offset = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
930 if (strstr(name, "::") != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
931 ptrIDebugSymbols->AddSymbolOptions(SYMOPT_UNDNAME);
a61af66fc99e Initial load
duke
parents:
diff changeset
932 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
933 ptrIDebugSymbols->RemoveSymbolOptions(SYMOPT_UNDNAME);
a61af66fc99e Initial load
duke
parents:
diff changeset
934 }
a61af66fc99e Initial load
duke
parents:
diff changeset
935 if (ptrIDebugSymbols->GetOffsetByName(name, &offset) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
936 return (jlong) 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
937 }
a61af66fc99e Initial load
duke
parents:
diff changeset
938 return (jlong) offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
939 }
a61af66fc99e Initial load
duke
parents:
diff changeset
940
a61af66fc99e Initial load
duke
parents:
diff changeset
941 #define SYMBOL_BUFSIZE 512
a61af66fc99e Initial load
duke
parents:
diff changeset
942 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
943 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
944 * Method: lookupByAddress0
a61af66fc99e Initial load
duke
parents:
diff changeset
945 * Signature: (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;
a61af66fc99e Initial load
duke
parents:
diff changeset
946 */
a61af66fc99e Initial load
duke
parents:
diff changeset
947 JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_lookupByAddress0
a61af66fc99e Initial load
duke
parents:
diff changeset
948 (JNIEnv *env, jobject obj, jlong address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
949 IDebugSymbols* ptrIDebugSymbols = (IDebugSymbols*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
950 ptrIDebugSymbols_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
951 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
952
a61af66fc99e Initial load
duke
parents:
diff changeset
953 ULONG64 disp = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
954 char buf[SYMBOL_BUFSIZE];
a61af66fc99e Initial load
duke
parents:
diff changeset
955 memset(buf, 0, sizeof(buf));
a61af66fc99e Initial load
duke
parents:
diff changeset
956
a61af66fc99e Initial load
duke
parents:
diff changeset
957 if (ptrIDebugSymbols->GetNameByOffset(address, buf, sizeof(buf),0,&disp)
a61af66fc99e Initial load
duke
parents:
diff changeset
958 != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
959 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
960 }
a61af66fc99e Initial load
duke
parents:
diff changeset
961
a61af66fc99e Initial load
duke
parents:
diff changeset
962 jstring sym = env->NewStringUTF(buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
963 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
964 jobject res = env->CallObjectMethod(obj, createClosestSymbol_ID, sym, disp);
a61af66fc99e Initial load
duke
parents:
diff changeset
965 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
966 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
967 }