annotate agent/src/os/win32/windbg/sawindbg.cpp @ 17716:cdb71841f4bc

6498581: ThreadInterruptTest3 produces wrong output on Windows Summary: There is race condition between os::interrupt and os::is_interrupted on Windows. In JVM_Sleep(Thread.sleep), check if thread gets interrupted, it may see interrupted but not really interrupted so cause spurious waking up (early return from sleep). Fix by checking if interrupt event really gets set thus prevent false return. For intrinsic of _isInterrupted, on Windows, go fastpath only on bit not set. Reviewed-by: acorn, kvn Contributed-by: david.holmes@oracle.com, yumin.qi@oracle.com
author minqi
date Wed, 26 Feb 2014 15:20:41 -0800
parents 55fb97c4c58d
children 4ca6dc0799b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17467
55fb97c4c58d 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 8103
diff changeset
2 * Copyright (c) 2002, 2013, 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
7994
9fae07c31641 6518907: cleanup IA64 specific code in Hotspot
morris
parents: 1552
diff changeset
30 #ifdef _M_IX86
0
a61af66fc99e Initial load
duke
parents:
diff changeset
31 #include "sun_jvm_hotspot_debugger_x86_X86ThreadContext.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
32 #define NPRGREG sun_jvm_hotspot_debugger_x86_X86ThreadContext_NPRGREG
a61af66fc99e Initial load
duke
parents:
diff changeset
33 #elif _M_AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
34 #include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
35 #define NPRGREG sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_NPRGREG
a61af66fc99e Initial load
duke
parents:
diff changeset
36 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
37 #error "SA windbg back-end is not supported for your cpu!"
a61af66fc99e Initial load
duke
parents:
diff changeset
38 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 #include <limits.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
41 #include <windows.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 #ifndef STDMETHODV
a61af66fc99e Initial load
duke
parents:
diff changeset
44 #define STDMETHODV(method) virtual HRESULT STDMETHODVCALLTYPE method
a61af66fc99e Initial load
duke
parents:
diff changeset
45 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 #define DEBUG_NO_IMPLEMENTATION
a61af66fc99e Initial load
duke
parents:
diff changeset
48 #include <dbgeng.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
49 #include <dbghelp.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // simple template to manage array delete across early (error) returns
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 template <class T>
a61af66fc99e Initial load
duke
parents:
diff changeset
54 class AutoArrayPtr {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 T* m_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
57 AutoArrayPtr(T* ptr) : m_ptr(ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 ~AutoArrayPtr() {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 delete [] m_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 T* asPtr() {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 return m_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67 };
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 class AutoJavaString {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 JNIEnv* m_env;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 jstring m_str;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 const char* m_buf;
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
75 AutoJavaString(JNIEnv* env, jstring str, const char* buf)
a61af66fc99e Initial load
duke
parents:
diff changeset
76 : m_env(env), m_str(str), m_buf(buf) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 ~AutoJavaString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 m_env->ReleaseStringUTFChars(m_str, m_buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 operator const char* () {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 return m_buf;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86 };
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // field and method IDs we want here
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 static jfieldID imagePath_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 static jfieldID symbolPath_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 static jfieldID ptrIDebugClient_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 static jfieldID ptrIDebugControl_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 static jfieldID ptrIDebugDataSpaces_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 static jfieldID ptrIDebugOutputCallbacks_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 static jfieldID ptrIDebugAdvanced_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 static jfieldID ptrIDebugSymbols_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 static jfieldID ptrIDebugSystemObjects_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 static jmethodID addLoadObject_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 static jmethodID addThread_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 static jmethodID createClosestSymbol_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 static jmethodID setThreadIntegerRegisterSet_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 #define CHECK_EXCEPTION_(value) if(env->ExceptionOccurred()) { return value; }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 #define CHECK_EXCEPTION if(env->ExceptionOccurred()) { return;}
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 #define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
109 throwNewDebuggerException(env, str); return value; }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 #define THROW_NEW_DEBUGGER_EXCEPTION(str) { throwNewDebuggerException(env, str); \
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return;}
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 static void throwNewDebuggerException(JNIEnv* env, const char* errMsg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 env->ThrowNew(env->FindClass("sun/jvm/hotspot/debugger/DebuggerException"), errMsg);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
119 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
120 * Method: initIDs
a61af66fc99e Initial load
duke
parents:
diff changeset
121 * Signature: ()V
a61af66fc99e Initial load
duke
parents:
diff changeset
122 */
a61af66fc99e Initial load
duke
parents:
diff changeset
123 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_initIDs
a61af66fc99e Initial load
duke
parents:
diff changeset
124 (JNIEnv *env, jclass clazz) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 imagePath_ID = env->GetStaticFieldID(clazz, "imagePath", "Ljava/lang/String;");
a61af66fc99e Initial load
duke
parents:
diff changeset
126 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 symbolPath_ID = env->GetStaticFieldID(clazz, "symbolPath", "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 ptrIDebugClient_ID = env->GetFieldID(clazz, "ptrIDebugClient", "J");
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 ptrIDebugControl_ID = env->GetFieldID(clazz, "ptrIDebugControl", "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 ptrIDebugDataSpaces_ID = env->GetFieldID(clazz, "ptrIDebugDataSpaces", "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 ptrIDebugOutputCallbacks_ID = env->GetFieldID(clazz,
a61af66fc99e Initial load
duke
parents:
diff changeset
141 "ptrIDebugOutputCallbacks", "J");
a61af66fc99e Initial load
duke
parents:
diff changeset
142 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 ptrIDebugAdvanced_ID = env->GetFieldID(clazz, "ptrIDebugAdvanced", "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 ptrIDebugSymbols_ID = env->GetFieldID(clazz,
a61af66fc99e Initial load
duke
parents:
diff changeset
148 "ptrIDebugSymbols", "J");
a61af66fc99e Initial load
duke
parents:
diff changeset
149 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 ptrIDebugSystemObjects_ID = env->GetFieldID(clazz,
a61af66fc99e Initial load
duke
parents:
diff changeset
152 "ptrIDebugSystemObjects", "J");
a61af66fc99e Initial load
duke
parents:
diff changeset
153 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 addLoadObject_ID = env->GetMethodID(clazz, "addLoadObject",
a61af66fc99e Initial load
duke
parents:
diff changeset
156 "(Ljava/lang/String;JJ)V");
a61af66fc99e Initial load
duke
parents:
diff changeset
157 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 addThread_ID = env->GetMethodID(clazz, "addThread", "(J)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 createClosestSymbol_ID = env->GetMethodID(clazz, "createClosestSymbol",
a61af66fc99e Initial load
duke
parents:
diff changeset
163 "(Ljava/lang/String;J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;");
a61af66fc99e Initial load
duke
parents:
diff changeset
164 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 setThreadIntegerRegisterSet_ID = env->GetMethodID(clazz,
a61af66fc99e Initial load
duke
parents:
diff changeset
167 "setThreadIntegerRegisterSet", "(J[J)V");
a61af66fc99e Initial load
duke
parents:
diff changeset
168 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // class for IDebugOutputCallbacks
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 class SAOutputCallbacks : public IDebugOutputCallbacks {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 LONG m_refCount;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 char* m_msgBuffer;
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
179 SAOutputCallbacks() : m_refCount(0), m_msgBuffer(0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 ~SAOutputCallbacks() {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 clearBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 const char* getBuffer() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 return m_msgBuffer;
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 void clearBuffer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 if (m_msgBuffer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 free(m_msgBuffer);
a61af66fc99e Initial load
duke
parents:
diff changeset
193 m_msgBuffer = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 STDMETHOD_(ULONG, AddRef)(THIS);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 STDMETHOD_(ULONG, Release)(THIS);
a61af66fc99e Initial load
duke
parents:
diff changeset
199 STDMETHOD(QueryInterface)(THIS_
a61af66fc99e Initial load
duke
parents:
diff changeset
200 IN REFIID interfaceId,
a61af66fc99e Initial load
duke
parents:
diff changeset
201 OUT PVOID* ppInterface);
a61af66fc99e Initial load
duke
parents:
diff changeset
202 STDMETHOD(Output)(THIS_
a61af66fc99e Initial load
duke
parents:
diff changeset
203 IN ULONG mask,
a61af66fc99e Initial load
duke
parents:
diff changeset
204 IN PCSTR msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 };
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 STDMETHODIMP_(ULONG) SAOutputCallbacks::AddRef(THIS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 InterlockedIncrement(&m_refCount);
a61af66fc99e Initial load
duke
parents:
diff changeset
209 return m_refCount;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 STDMETHODIMP_(ULONG) SAOutputCallbacks::Release(THIS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 LONG retVal;
a61af66fc99e Initial load
duke
parents:
diff changeset
214 InterlockedDecrement(&m_refCount);
a61af66fc99e Initial load
duke
parents:
diff changeset
215 retVal = m_refCount;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 if (retVal == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 delete this;
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219 return retVal;
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 STDMETHODIMP SAOutputCallbacks::QueryInterface(THIS_
a61af66fc99e Initial load
duke
parents:
diff changeset
223 IN REFIID interfaceId,
a61af66fc99e Initial load
duke
parents:
diff changeset
224 OUT PVOID* ppInterface) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 *ppInterface = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
226 HRESULT res = E_NOINTERFACE;
a61af66fc99e Initial load
duke
parents:
diff changeset
227 if (TRUE == IsEqualIID(interfaceId, __uuidof(IUnknown)) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
228 TRUE == IsEqualIID(interfaceId, __uuidof(IDebugOutputCallbacks))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 *ppInterface = (IDebugOutputCallbacks*) this;
a61af66fc99e Initial load
duke
parents:
diff changeset
230 AddRef();
a61af66fc99e Initial load
duke
parents:
diff changeset
231 res = S_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 STDMETHODIMP SAOutputCallbacks::Output(THIS_
a61af66fc99e Initial load
duke
parents:
diff changeset
237 IN ULONG mask,
a61af66fc99e Initial load
duke
parents:
diff changeset
238 IN PCSTR msg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 int len = (int) (strlen(msg) + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
240 if (m_msgBuffer == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 m_msgBuffer = (char*) malloc(len);
a61af66fc99e Initial load
duke
parents:
diff changeset
242 if (m_msgBuffer == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
243 fprintf(stderr, "out of memory debugger output!\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
244 return S_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
246 strcpy(m_msgBuffer, msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
247 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 m_msgBuffer = (char*) realloc(m_msgBuffer, len + strlen(m_msgBuffer));
a61af66fc99e Initial load
duke
parents:
diff changeset
249 if (m_msgBuffer == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 fprintf(stderr, "out of memory debugger output!\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
251 return S_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253 strcat(m_msgBuffer, msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
255 return S_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
257
a61af66fc99e Initial load
duke
parents:
diff changeset
258 static bool getWindbgInterfaces(JNIEnv* env, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 // get windbg interfaces ..
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 IDebugClient* ptrIDebugClient = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 if (DebugCreate(__uuidof(IDebugClient), (PVOID*) &ptrIDebugClient) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to create IDebugClient object!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265 env->SetLongField(obj, ptrIDebugClient_ID, (jlong) ptrIDebugClient);
a61af66fc99e Initial load
duke
parents:
diff changeset
266
a61af66fc99e Initial load
duke
parents:
diff changeset
267 IDebugControl* ptrIDebugControl = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
268 if (ptrIDebugClient->QueryInterface(__uuidof(IDebugControl), (PVOID*) &ptrIDebugControl)
a61af66fc99e Initial load
duke
parents:
diff changeset
269 != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugControl", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272 env->SetLongField(obj, ptrIDebugControl_ID, (jlong) ptrIDebugControl);
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 IDebugDataSpaces* ptrIDebugDataSpaces = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
275 if (ptrIDebugClient->QueryInterface(__uuidof(IDebugDataSpaces), (PVOID*) &ptrIDebugDataSpaces)
a61af66fc99e Initial load
duke
parents:
diff changeset
276 != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugDataSpaces object!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279 env->SetLongField(obj, ptrIDebugDataSpaces_ID, (jlong) ptrIDebugDataSpaces);
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 SAOutputCallbacks* ptrIDebugOutputCallbacks = new SAOutputCallbacks();
a61af66fc99e Initial load
duke
parents:
diff changeset
282 ptrIDebugOutputCallbacks->AddRef();
a61af66fc99e Initial load
duke
parents:
diff changeset
283 env->SetLongField(obj, ptrIDebugOutputCallbacks_ID, (jlong) ptrIDebugOutputCallbacks);
a61af66fc99e Initial load
duke
parents:
diff changeset
284 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
285
a61af66fc99e Initial load
duke
parents:
diff changeset
286 IDebugAdvanced* ptrIDebugAdvanced = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
287 if (ptrIDebugClient->QueryInterface(__uuidof(IDebugAdvanced), (PVOID*) &ptrIDebugAdvanced)
a61af66fc99e Initial load
duke
parents:
diff changeset
288 != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
289 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugAdvanced object!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
291 env->SetLongField(obj, ptrIDebugAdvanced_ID, (jlong) ptrIDebugAdvanced);
a61af66fc99e Initial load
duke
parents:
diff changeset
292
a61af66fc99e Initial load
duke
parents:
diff changeset
293 IDebugSymbols* ptrIDebugSymbols = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
294 if (ptrIDebugClient->QueryInterface(__uuidof(IDebugSymbols), (PVOID*) &ptrIDebugSymbols)
a61af66fc99e Initial load
duke
parents:
diff changeset
295 != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
296 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugSymbols object!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
298 env->SetLongField(obj, ptrIDebugSymbols_ID, (jlong) ptrIDebugSymbols);
a61af66fc99e Initial load
duke
parents:
diff changeset
299
a61af66fc99e Initial load
duke
parents:
diff changeset
300 IDebugSystemObjects* ptrIDebugSystemObjects = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
301 if (ptrIDebugClient->QueryInterface(__uuidof(IDebugSystemObjects), (PVOID*) &ptrIDebugSystemObjects)
a61af66fc99e Initial load
duke
parents:
diff changeset
302 != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugSystemObjects object!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
304 }
a61af66fc99e Initial load
duke
parents:
diff changeset
305 env->SetLongField(obj, ptrIDebugSystemObjects_ID, (jlong) ptrIDebugSystemObjects);
a61af66fc99e Initial load
duke
parents:
diff changeset
306
a61af66fc99e Initial load
duke
parents:
diff changeset
307 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
308 }
a61af66fc99e Initial load
duke
parents:
diff changeset
309
a61af66fc99e Initial load
duke
parents:
diff changeset
310 static bool setImageAndSymbolPath(JNIEnv* env, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 jboolean isCopy;
a61af66fc99e Initial load
duke
parents:
diff changeset
312 jclass clazz = env->GetObjectClass(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
313 jstring path;
a61af66fc99e Initial load
duke
parents:
diff changeset
314 const char* buf;
a61af66fc99e Initial load
duke
parents:
diff changeset
315
a61af66fc99e Initial load
duke
parents:
diff changeset
316 path = (jstring) env->GetStaticObjectField(clazz, imagePath_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
317 buf = env->GetStringUTFChars(path, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
318 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
319 AutoJavaString imagePath(env, path, buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
320
a61af66fc99e Initial load
duke
parents:
diff changeset
321 path = (jstring) env->GetStaticObjectField(clazz, symbolPath_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
322 buf = env->GetStringUTFChars(path, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
323 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
324 AutoJavaString symbolPath(env, path, buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
325
a61af66fc99e Initial load
duke
parents:
diff changeset
326 IDebugSymbols* ptrIDebugSymbols = (IDebugSymbols*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
327 ptrIDebugSymbols_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
328 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
329
a61af66fc99e Initial load
duke
parents:
diff changeset
330 ptrIDebugSymbols->SetImagePath(imagePath);
a61af66fc99e Initial load
duke
parents:
diff changeset
331 ptrIDebugSymbols->SetSymbolPath(symbolPath);
a61af66fc99e Initial load
duke
parents:
diff changeset
332 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
333 }
a61af66fc99e Initial load
duke
parents:
diff changeset
334
a61af66fc99e Initial load
duke
parents:
diff changeset
335 static bool openDumpFile(JNIEnv* env, jobject obj, jstring coreFileName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
336 // open the dump file
a61af66fc99e Initial load
duke
parents:
diff changeset
337 jboolean isCopy;
a61af66fc99e Initial load
duke
parents:
diff changeset
338 const char* buf = env->GetStringUTFChars(coreFileName, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
339 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
340 AutoJavaString coreFile(env, coreFileName, buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
341 if (setImageAndSymbolPath(env, obj) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
342 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
343 }
a61af66fc99e Initial load
duke
parents:
diff changeset
344
a61af66fc99e Initial load
duke
parents:
diff changeset
345 IDebugClient* ptrIDebugClient = (IDebugClient*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
346 ptrIDebugClient_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
347 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
348 if (ptrIDebugClient->OpenDumpFile(coreFile) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: OpenDumpFile failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
351
a61af66fc99e Initial load
duke
parents:
diff changeset
352 IDebugControl* ptrIDebugControl = (IDebugControl*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
353 ptrIDebugControl_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
354 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
355 if (ptrIDebugControl->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: WaitForEvent failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
357 }
a61af66fc99e Initial load
duke
parents:
diff changeset
358
a61af66fc99e Initial load
duke
parents:
diff changeset
359 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
361
a61af66fc99e Initial load
duke
parents:
diff changeset
362
a61af66fc99e Initial load
duke
parents:
diff changeset
363 static bool attachToProcess(JNIEnv* env, jobject obj, jint pid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
364 if (setImageAndSymbolPath(env, obj) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
365 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
366 }
a61af66fc99e Initial load
duke
parents:
diff changeset
367 IDebugClient* ptrIDebugClient = (IDebugClient*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
368 ptrIDebugClient_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
369 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
370
a61af66fc99e Initial load
duke
parents:
diff changeset
371 /***********************************************************************************
a61af66fc99e Initial load
duke
parents:
diff changeset
372
a61af66fc99e Initial load
duke
parents:
diff changeset
373 We are attaching to a process in 'read-only' mode. i.e., we do not want to
a61af66fc99e Initial load
duke
parents:
diff changeset
374 put breakpoints, suspend/resume threads etc. For read-only JDI and HSDB kind of
8103
5ed317b25e23 7165259: Remove BugSpot
sla
parents: 7994
diff changeset
375 usage this should suffice.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
376
a61af66fc99e Initial load
duke
parents:
diff changeset
377 Please refer to DEBUG_ATTACH_NONINVASIVE mode source comments from dbgeng.h.
a61af66fc99e Initial load
duke
parents:
diff changeset
378 In this mode, debug engine does not call DebugActiveProrcess. i.e., we are not
a61af66fc99e Initial load
duke
parents:
diff changeset
379 actually debugging at all. We can safely 'detach' from the process anytime
a61af66fc99e Initial load
duke
parents:
diff changeset
380 we want and debuggee process is left as is on all Windows variants.
a61af66fc99e Initial load
duke
parents:
diff changeset
381
a61af66fc99e Initial load
duke
parents:
diff changeset
382 This also makes JDI-on-SA installation/usage simpler because with this we would
a61af66fc99e Initial load
duke
parents:
diff changeset
383 not need a tool like ServiceInstaller from http://www.kcmultimedia.com/smaster.
a61af66fc99e Initial load
duke
parents:
diff changeset
384
a61af66fc99e Initial load
duke
parents:
diff changeset
385 ***********************************************************************************/
a61af66fc99e Initial load
duke
parents:
diff changeset
386
a61af66fc99e Initial load
duke
parents:
diff changeset
387
a61af66fc99e Initial load
duke
parents:
diff changeset
388 if (ptrIDebugClient->AttachProcess(0, pid, DEBUG_ATTACH_NONINVASIVE) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
389 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: AttachProcess failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
390 }
a61af66fc99e Initial load
duke
parents:
diff changeset
391
a61af66fc99e Initial load
duke
parents:
diff changeset
392 IDebugControl* ptrIDebugControl = (IDebugControl*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
393 ptrIDebugControl_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
394 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
395 if (ptrIDebugControl->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
396 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: WaitForEvent failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
397 }
a61af66fc99e Initial load
duke
parents:
diff changeset
398
a61af66fc99e Initial load
duke
parents:
diff changeset
399 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
400 }
a61af66fc99e Initial load
duke
parents:
diff changeset
401
a61af66fc99e Initial load
duke
parents:
diff changeset
402
a61af66fc99e Initial load
duke
parents:
diff changeset
403 static bool addLoadObjects(JNIEnv* env, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
404 IDebugSymbols* ptrIDebugSymbols = (IDebugSymbols*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
405 ptrIDebugSymbols_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
406 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
407 ULONG loaded = 0, unloaded = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
408 if (ptrIDebugSymbols->GetNumberModules(&loaded, &unloaded) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
409 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetNumberModules failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
411
a61af66fc99e Initial load
duke
parents:
diff changeset
412 AutoArrayPtr<DEBUG_MODULE_PARAMETERS> params(new DEBUG_MODULE_PARAMETERS[loaded]);
a61af66fc99e Initial load
duke
parents:
diff changeset
413
a61af66fc99e Initial load
duke
parents:
diff changeset
414 if (params.asPtr() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
415 THROW_NEW_DEBUGGER_EXCEPTION_("out of memory to allocate debug module params!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
416 }
a61af66fc99e Initial load
duke
parents:
diff changeset
417
a61af66fc99e Initial load
duke
parents:
diff changeset
418 if (ptrIDebugSymbols->GetModuleParameters(loaded, 0, NULL, params.asPtr()) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
419 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetModuleParameters failed!", 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 for (int u = 0; u < (int)loaded; u++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
423 TCHAR imageName[MAX_PATH];
a61af66fc99e Initial load
duke
parents:
diff changeset
424 if (ptrIDebugSymbols->GetModuleNames(DEBUG_ANY_ID, params.asPtr()[u].Base,
a61af66fc99e Initial load
duke
parents:
diff changeset
425 imageName, MAX_PATH, NULL, NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
426 0, NULL, NULL, 0, NULL) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
427 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetModuleNames failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
428 }
a61af66fc99e Initial load
duke
parents:
diff changeset
429
a61af66fc99e Initial load
duke
parents:
diff changeset
430 jstring strName = env->NewStringUTF(imageName);
a61af66fc99e Initial load
duke
parents:
diff changeset
431 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
432 env->CallVoidMethod(obj, addLoadObject_ID, strName, (jlong) params.asPtr()[u].Size,
a61af66fc99e Initial load
duke
parents:
diff changeset
433 (jlong) params.asPtr()[u].Base);
a61af66fc99e Initial load
duke
parents:
diff changeset
434 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
435 }
a61af66fc99e Initial load
duke
parents:
diff changeset
436
a61af66fc99e Initial load
duke
parents:
diff changeset
437 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
438 }
a61af66fc99e Initial load
duke
parents:
diff changeset
439
a61af66fc99e Initial load
duke
parents:
diff changeset
440 static bool addThreads(JNIEnv* env, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
441 IDebugSystemObjects* ptrIDebugSystemObjects = (IDebugSystemObjects*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
442 ptrIDebugSystemObjects_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
443 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
444
a61af66fc99e Initial load
duke
parents:
diff changeset
445 ULONG numThreads = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
446 if (ptrIDebugSystemObjects->GetNumberThreads(&numThreads) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
447 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetNumberThreads failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
448 }
a61af66fc99e Initial load
duke
parents:
diff changeset
449
a61af66fc99e Initial load
duke
parents:
diff changeset
450 AutoArrayPtr<ULONG> ptrSysThreadIds = new ULONG[numThreads];
a61af66fc99e Initial load
duke
parents:
diff changeset
451
a61af66fc99e Initial load
duke
parents:
diff changeset
452 if (ptrSysThreadIds.asPtr() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
453 THROW_NEW_DEBUGGER_EXCEPTION_("out of memory to allocate thread ids!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
454 }
a61af66fc99e Initial load
duke
parents:
diff changeset
455
a61af66fc99e Initial load
duke
parents:
diff changeset
456 AutoArrayPtr<ULONG> ptrThreadIds = new ULONG[numThreads];
a61af66fc99e Initial load
duke
parents:
diff changeset
457
a61af66fc99e Initial load
duke
parents:
diff changeset
458 if (ptrThreadIds.asPtr() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 THROW_NEW_DEBUGGER_EXCEPTION_("out of memory to allocate thread ids!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462 if (ptrIDebugSystemObjects->GetThreadIdsByIndex(0, numThreads,
a61af66fc99e Initial load
duke
parents:
diff changeset
463 ptrThreadIds.asPtr(), ptrSysThreadIds.asPtr()) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
464 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetThreadIdsByIndex failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
465 }
a61af66fc99e Initial load
duke
parents:
diff changeset
466
a61af66fc99e Initial load
duke
parents:
diff changeset
467
a61af66fc99e Initial load
duke
parents:
diff changeset
468 IDebugAdvanced* ptrIDebugAdvanced = (IDebugAdvanced*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
469 ptrIDebugAdvanced_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
470 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
471
a61af66fc99e Initial load
duke
parents:
diff changeset
472 // for each thread, get register context and save it.
a61af66fc99e Initial load
duke
parents:
diff changeset
473 for (ULONG t = 0; t < numThreads; t++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
474 if (ptrIDebugSystemObjects->SetCurrentThreadId(ptrThreadIds.asPtr()[t]) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
475 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: SetCurrentThread failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
476 }
a61af66fc99e Initial load
duke
parents:
diff changeset
477
a61af66fc99e Initial load
duke
parents:
diff changeset
478 jlongArray regs = env->NewLongArray(NPRGREG);
a61af66fc99e Initial load
duke
parents:
diff changeset
479 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
480
a61af66fc99e Initial load
duke
parents:
diff changeset
481 jboolean isCopy = JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
482 jlong* ptrRegs = env->GetLongArrayElements(regs, &isCopy);
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 // copy register values from the CONTEXT struct
a61af66fc99e Initial load
duke
parents:
diff changeset
486 CONTEXT context;
a61af66fc99e Initial load
duke
parents:
diff changeset
487 memset(&context, 0, sizeof(CONTEXT));
a61af66fc99e Initial load
duke
parents:
diff changeset
488
a61af66fc99e Initial load
duke
parents:
diff changeset
489 #undef REG_INDEX
7994
9fae07c31641 6518907: cleanup IA64 specific code in Hotspot
morris
parents: 1552
diff changeset
490 #ifdef _M_IX86
0
a61af66fc99e Initial load
duke
parents:
diff changeset
491 #define REG_INDEX(x) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##x
a61af66fc99e Initial load
duke
parents:
diff changeset
492
a61af66fc99e Initial load
duke
parents:
diff changeset
493 context.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
a61af66fc99e Initial load
duke
parents:
diff changeset
494 ptrIDebugAdvanced->GetThreadContext(&context, sizeof(CONTEXT));
a61af66fc99e Initial load
duke
parents:
diff changeset
495
a61af66fc99e Initial load
duke
parents:
diff changeset
496 ptrRegs[REG_INDEX(GS)] = context.SegGs;
a61af66fc99e Initial load
duke
parents:
diff changeset
497 ptrRegs[REG_INDEX(FS)] = context.SegFs;
a61af66fc99e Initial load
duke
parents:
diff changeset
498 ptrRegs[REG_INDEX(ES)] = context.SegEs;
a61af66fc99e Initial load
duke
parents:
diff changeset
499 ptrRegs[REG_INDEX(DS)] = context.SegDs;
a61af66fc99e Initial load
duke
parents:
diff changeset
500
a61af66fc99e Initial load
duke
parents:
diff changeset
501 ptrRegs[REG_INDEX(EDI)] = context.Edi;
a61af66fc99e Initial load
duke
parents:
diff changeset
502 ptrRegs[REG_INDEX(ESI)] = context.Esi;
a61af66fc99e Initial load
duke
parents:
diff changeset
503 ptrRegs[REG_INDEX(EBX)] = context.Ebx;
a61af66fc99e Initial load
duke
parents:
diff changeset
504 ptrRegs[REG_INDEX(EDX)] = context.Edx;
a61af66fc99e Initial load
duke
parents:
diff changeset
505 ptrRegs[REG_INDEX(ECX)] = context.Ecx;
a61af66fc99e Initial load
duke
parents:
diff changeset
506 ptrRegs[REG_INDEX(EAX)] = context.Eax;
a61af66fc99e Initial load
duke
parents:
diff changeset
507
a61af66fc99e Initial load
duke
parents:
diff changeset
508 ptrRegs[REG_INDEX(FP)] = context.Ebp;
a61af66fc99e Initial load
duke
parents:
diff changeset
509 ptrRegs[REG_INDEX(PC)] = context.Eip;
a61af66fc99e Initial load
duke
parents:
diff changeset
510 ptrRegs[REG_INDEX(CS)] = context.SegCs;
a61af66fc99e Initial load
duke
parents:
diff changeset
511 ptrRegs[REG_INDEX(EFL)] = context.EFlags;
a61af66fc99e Initial load
duke
parents:
diff changeset
512 ptrRegs[REG_INDEX(SP)] = context.Esp;
a61af66fc99e Initial load
duke
parents:
diff changeset
513 ptrRegs[REG_INDEX(SS)] = context.SegSs;
a61af66fc99e Initial load
duke
parents:
diff changeset
514
a61af66fc99e Initial load
duke
parents:
diff changeset
515 ptrRegs[REG_INDEX(DR0)] = context.Dr0;
a61af66fc99e Initial load
duke
parents:
diff changeset
516 ptrRegs[REG_INDEX(DR1)] = context.Dr1;
a61af66fc99e Initial load
duke
parents:
diff changeset
517 ptrRegs[REG_INDEX(DR2)] = context.Dr2;
a61af66fc99e Initial load
duke
parents:
diff changeset
518 ptrRegs[REG_INDEX(DR3)] = context.Dr3;
a61af66fc99e Initial load
duke
parents:
diff changeset
519 ptrRegs[REG_INDEX(DR6)] = context.Dr6;
a61af66fc99e Initial load
duke
parents:
diff changeset
520 ptrRegs[REG_INDEX(DR7)] = context.Dr7;
a61af66fc99e Initial load
duke
parents:
diff changeset
521
a61af66fc99e Initial load
duke
parents:
diff changeset
522 #elif _M_AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
523 #define REG_INDEX(x) sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_##x
a61af66fc99e Initial load
duke
parents:
diff changeset
524
a61af66fc99e Initial load
duke
parents:
diff changeset
525 context.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
a61af66fc99e Initial load
duke
parents:
diff changeset
526 ptrIDebugAdvanced->GetThreadContext(&context, sizeof(CONTEXT));
a61af66fc99e Initial load
duke
parents:
diff changeset
527
a61af66fc99e Initial load
duke
parents:
diff changeset
528 // Segment Registers and processor flags
a61af66fc99e Initial load
duke
parents:
diff changeset
529 ptrRegs[REG_INDEX(CS)] = context.SegCs;
a61af66fc99e Initial load
duke
parents:
diff changeset
530 ptrRegs[REG_INDEX(DS)] = context.SegDs;
a61af66fc99e Initial load
duke
parents:
diff changeset
531 ptrRegs[REG_INDEX(ES)] = context.SegEs;
a61af66fc99e Initial load
duke
parents:
diff changeset
532 ptrRegs[REG_INDEX(FS)] = context.SegFs;
a61af66fc99e Initial load
duke
parents:
diff changeset
533 ptrRegs[REG_INDEX(GS)] = context.SegGs;
a61af66fc99e Initial load
duke
parents:
diff changeset
534 ptrRegs[REG_INDEX(SS)] = context.SegSs;
a61af66fc99e Initial load
duke
parents:
diff changeset
535 ptrRegs[REG_INDEX(RFL)] = context.EFlags;
a61af66fc99e Initial load
duke
parents:
diff changeset
536
a61af66fc99e Initial load
duke
parents:
diff changeset
537 // Integer registers
a61af66fc99e Initial load
duke
parents:
diff changeset
538 ptrRegs[REG_INDEX(RDI)] = context.Rdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
539 ptrRegs[REG_INDEX(RSI)] = context.Rsi;
a61af66fc99e Initial load
duke
parents:
diff changeset
540 ptrRegs[REG_INDEX(RAX)] = context.Rax;
a61af66fc99e Initial load
duke
parents:
diff changeset
541 ptrRegs[REG_INDEX(RCX)] = context.Rcx;
a61af66fc99e Initial load
duke
parents:
diff changeset
542 ptrRegs[REG_INDEX(RDX)] = context.Rdx;
a61af66fc99e Initial load
duke
parents:
diff changeset
543 ptrRegs[REG_INDEX(RBX)] = context.Rbx;
a61af66fc99e Initial load
duke
parents:
diff changeset
544 ptrRegs[REG_INDEX(RBP)] = context.Rbp;
a61af66fc99e Initial load
duke
parents:
diff changeset
545 ptrRegs[REG_INDEX(RSP)] = context.Rsp;
a61af66fc99e Initial load
duke
parents:
diff changeset
546
a61af66fc99e Initial load
duke
parents:
diff changeset
547 ptrRegs[REG_INDEX(R8)] = context.R8;
a61af66fc99e Initial load
duke
parents:
diff changeset
548 ptrRegs[REG_INDEX(R9)] = context.R9;
a61af66fc99e Initial load
duke
parents:
diff changeset
549 ptrRegs[REG_INDEX(R10)] = context.R10;
a61af66fc99e Initial load
duke
parents:
diff changeset
550 ptrRegs[REG_INDEX(R11)] = context.R11;
a61af66fc99e Initial load
duke
parents:
diff changeset
551 ptrRegs[REG_INDEX(R12)] = context.R12;
a61af66fc99e Initial load
duke
parents:
diff changeset
552 ptrRegs[REG_INDEX(R13)] = context.R13;
a61af66fc99e Initial load
duke
parents:
diff changeset
553 ptrRegs[REG_INDEX(R14)] = context.R14;
a61af66fc99e Initial load
duke
parents:
diff changeset
554 ptrRegs[REG_INDEX(R15)] = context.R15;
a61af66fc99e Initial load
duke
parents:
diff changeset
555
a61af66fc99e Initial load
duke
parents:
diff changeset
556 // Program counter
a61af66fc99e Initial load
duke
parents:
diff changeset
557 ptrRegs[REG_INDEX(RIP)] = context.Rip;
a61af66fc99e Initial load
duke
parents:
diff changeset
558 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
559
a61af66fc99e Initial load
duke
parents:
diff changeset
560 env->ReleaseLongArrayElements(regs, ptrRegs, JNI_COMMIT);
a61af66fc99e Initial load
duke
parents:
diff changeset
561 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
562
a61af66fc99e Initial load
duke
parents:
diff changeset
563 env->CallVoidMethod(obj, setThreadIntegerRegisterSet_ID,
a61af66fc99e Initial load
duke
parents:
diff changeset
564 (jlong) ptrThreadIds.asPtr()[t], regs);
a61af66fc99e Initial load
duke
parents:
diff changeset
565 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
566
a61af66fc99e Initial load
duke
parents:
diff changeset
567 ULONG sysId;
a61af66fc99e Initial load
duke
parents:
diff changeset
568 if (ptrIDebugSystemObjects->GetCurrentThreadSystemId(&sysId) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
569 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetCurrentThreadSystemId failed!", false);
a61af66fc99e Initial load
duke
parents:
diff changeset
570 }
a61af66fc99e Initial load
duke
parents:
diff changeset
571
a61af66fc99e Initial load
duke
parents:
diff changeset
572 env->CallVoidMethod(obj, addThread_ID, (jlong) sysId);
a61af66fc99e Initial load
duke
parents:
diff changeset
573 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
574 }
a61af66fc99e Initial load
duke
parents:
diff changeset
575
a61af66fc99e Initial load
duke
parents:
diff changeset
576 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
577 }
a61af66fc99e Initial load
duke
parents:
diff changeset
578
a61af66fc99e Initial load
duke
parents:
diff changeset
579 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
580 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
581 * Method: attach0
a61af66fc99e Initial load
duke
parents:
diff changeset
582 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
a61af66fc99e Initial load
duke
parents:
diff changeset
583 */
a61af66fc99e Initial load
duke
parents:
diff changeset
584 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
585 (JNIEnv *env, jobject obj, jstring execName, jstring coreFileName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
586
a61af66fc99e Initial load
duke
parents:
diff changeset
587 if (getWindbgInterfaces(env, obj) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
588 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
589 }
a61af66fc99e Initial load
duke
parents:
diff changeset
590
a61af66fc99e Initial load
duke
parents:
diff changeset
591 if (openDumpFile(env, obj, coreFileName) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
592 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
593 }
a61af66fc99e Initial load
duke
parents:
diff changeset
594
a61af66fc99e Initial load
duke
parents:
diff changeset
595 if (addLoadObjects(env, obj) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
596 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
597 }
a61af66fc99e Initial load
duke
parents:
diff changeset
598
a61af66fc99e Initial load
duke
parents:
diff changeset
599 if (addThreads(env, obj) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
600 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
601 }
a61af66fc99e Initial load
duke
parents:
diff changeset
602 }
a61af66fc99e Initial load
duke
parents:
diff changeset
603
a61af66fc99e Initial load
duke
parents:
diff changeset
604 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
605 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
606 * Method: attach0
a61af66fc99e Initial load
duke
parents:
diff changeset
607 * Signature: (I)V
a61af66fc99e Initial load
duke
parents:
diff changeset
608 */
a61af66fc99e Initial load
duke
parents:
diff changeset
609 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_attach0__I
a61af66fc99e Initial load
duke
parents:
diff changeset
610 (JNIEnv *env, jobject obj, jint pid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
611
a61af66fc99e Initial load
duke
parents:
diff changeset
612 if (getWindbgInterfaces(env, obj) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
613 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
614 }
a61af66fc99e Initial load
duke
parents:
diff changeset
615
a61af66fc99e Initial load
duke
parents:
diff changeset
616 if (attachToProcess(env, obj, pid) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
617 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
618 }
a61af66fc99e Initial load
duke
parents:
diff changeset
619
a61af66fc99e Initial load
duke
parents:
diff changeset
620 if (addLoadObjects(env, obj) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
621 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
622 }
a61af66fc99e Initial load
duke
parents:
diff changeset
623
a61af66fc99e Initial load
duke
parents:
diff changeset
624 if (addThreads(env, obj) == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
625 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
626 }
a61af66fc99e Initial load
duke
parents:
diff changeset
627 }
a61af66fc99e Initial load
duke
parents:
diff changeset
628
a61af66fc99e Initial load
duke
parents:
diff changeset
629
a61af66fc99e Initial load
duke
parents:
diff changeset
630 static bool releaseWindbgInterfaces(JNIEnv* env, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
631 IDebugDataSpaces* ptrIDebugDataSpaces = (IDebugDataSpaces*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
632 ptrIDebugDataSpaces_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
633 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
634 if (ptrIDebugDataSpaces != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
635 ptrIDebugDataSpaces->Release();
a61af66fc99e Initial load
duke
parents:
diff changeset
636 }
a61af66fc99e Initial load
duke
parents:
diff changeset
637
a61af66fc99e Initial load
duke
parents:
diff changeset
638 IDebugOutputCallbacks* ptrIDebugOutputCallbacks = (IDebugOutputCallbacks*)
a61af66fc99e Initial load
duke
parents:
diff changeset
639 env->GetLongField(obj, ptrIDebugOutputCallbacks_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
640 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
641 if (ptrIDebugOutputCallbacks != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
642 ptrIDebugOutputCallbacks->Release();
a61af66fc99e Initial load
duke
parents:
diff changeset
643 }
a61af66fc99e Initial load
duke
parents:
diff changeset
644
a61af66fc99e Initial load
duke
parents:
diff changeset
645 IDebugAdvanced* ptrIDebugAdvanced = (IDebugAdvanced*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
646 ptrIDebugAdvanced_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
647 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
648
a61af66fc99e Initial load
duke
parents:
diff changeset
649 if (ptrIDebugAdvanced != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
650 ptrIDebugAdvanced->Release();
a61af66fc99e Initial load
duke
parents:
diff changeset
651 }
a61af66fc99e Initial load
duke
parents:
diff changeset
652
a61af66fc99e Initial load
duke
parents:
diff changeset
653 IDebugSymbols* ptrIDebugSymbols = (IDebugSymbols*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
654 ptrIDebugSymbols_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
655 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
656 if (ptrIDebugSymbols != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
657 ptrIDebugSymbols->Release();
a61af66fc99e Initial load
duke
parents:
diff changeset
658 }
a61af66fc99e Initial load
duke
parents:
diff changeset
659
a61af66fc99e Initial load
duke
parents:
diff changeset
660 IDebugSystemObjects* ptrIDebugSystemObjects = (IDebugSystemObjects*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
661 ptrIDebugSystemObjects_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
662 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
663 if (ptrIDebugSystemObjects != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
664 ptrIDebugSystemObjects->Release();
a61af66fc99e Initial load
duke
parents:
diff changeset
665 }
a61af66fc99e Initial load
duke
parents:
diff changeset
666
a61af66fc99e Initial load
duke
parents:
diff changeset
667 IDebugControl* ptrIDebugControl = (IDebugControl*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
668 ptrIDebugControl_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
669 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
670 if (ptrIDebugControl != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
671 ptrIDebugControl->Release();
a61af66fc99e Initial load
duke
parents:
diff changeset
672 }
a61af66fc99e Initial load
duke
parents:
diff changeset
673
a61af66fc99e Initial load
duke
parents:
diff changeset
674 IDebugClient* ptrIDebugClient = (IDebugClient*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
675 ptrIDebugClient_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
676 CHECK_EXCEPTION_(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
677 if (ptrIDebugClient != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
678 ptrIDebugClient->Release();
a61af66fc99e Initial load
duke
parents:
diff changeset
679 }
a61af66fc99e Initial load
duke
parents:
diff changeset
680
a61af66fc99e Initial load
duke
parents:
diff changeset
681 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
682 }
a61af66fc99e Initial load
duke
parents:
diff changeset
683
a61af66fc99e Initial load
duke
parents:
diff changeset
684 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
685 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
686 * Method: detach0
a61af66fc99e Initial load
duke
parents:
diff changeset
687 * Signature: ()V
a61af66fc99e Initial load
duke
parents:
diff changeset
688 */
a61af66fc99e Initial load
duke
parents:
diff changeset
689 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_detach0
a61af66fc99e Initial load
duke
parents:
diff changeset
690 (JNIEnv *env, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
691 IDebugClient* ptrIDebugClient = (IDebugClient*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
692 ptrIDebugClient_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
693 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
694 ptrIDebugClient->DetachProcesses();
a61af66fc99e Initial load
duke
parents:
diff changeset
695 releaseWindbgInterfaces(env, obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
696 }
a61af66fc99e Initial load
duke
parents:
diff changeset
697
a61af66fc99e Initial load
duke
parents:
diff changeset
698
a61af66fc99e Initial load
duke
parents:
diff changeset
699 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
700 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
701 * Method: readBytesFromProcess0
a61af66fc99e Initial load
duke
parents:
diff changeset
702 * Signature: (JJ)[B
a61af66fc99e Initial load
duke
parents:
diff changeset
703 */
a61af66fc99e Initial load
duke
parents:
diff changeset
704 JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_readBytesFromProcess0
a61af66fc99e Initial load
duke
parents:
diff changeset
705 (JNIEnv *env, jobject obj, jlong address, jlong numBytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
706 jbyteArray byteArray = env->NewByteArray((long) numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
707 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
708
a61af66fc99e Initial load
duke
parents:
diff changeset
709 jboolean isCopy = JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
710 jbyte* bytePtr = env->GetByteArrayElements(byteArray, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
711 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
712
a61af66fc99e Initial load
duke
parents:
diff changeset
713 IDebugDataSpaces* ptrIDebugDataSpaces = (IDebugDataSpaces*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
714 ptrIDebugDataSpaces_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
715 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
716
a61af66fc99e Initial load
duke
parents:
diff changeset
717 ULONG bytesRead;
a61af66fc99e Initial load
duke
parents:
diff changeset
718 if (ptrIDebugDataSpaces->ReadVirtual((ULONG64) address, (PVOID) bytePtr,
a61af66fc99e Initial load
duke
parents:
diff changeset
719 (ULONG)numBytes, &bytesRead) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
720 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: ReadVirtual failed!", 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
721 }
a61af66fc99e Initial load
duke
parents:
diff changeset
722
a61af66fc99e Initial load
duke
parents:
diff changeset
723 if (bytesRead != numBytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
724 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
725 }
a61af66fc99e Initial load
duke
parents:
diff changeset
726
a61af66fc99e Initial load
duke
parents:
diff changeset
727 env->ReleaseByteArrayElements(byteArray, bytePtr, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
728 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
729
a61af66fc99e Initial load
duke
parents:
diff changeset
730 return byteArray;
a61af66fc99e Initial load
duke
parents:
diff changeset
731 }
a61af66fc99e Initial load
duke
parents:
diff changeset
732
a61af66fc99e Initial load
duke
parents:
diff changeset
733 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
734 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
735 * Method: getThreadIdFromSysId0
a61af66fc99e Initial load
duke
parents:
diff changeset
736 * Signature: (J)J
a61af66fc99e Initial load
duke
parents:
diff changeset
737 */
a61af66fc99e Initial load
duke
parents:
diff changeset
738 JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_getThreadIdFromSysId0
a61af66fc99e Initial load
duke
parents:
diff changeset
739 (JNIEnv *env, jobject obj, jlong sysId) {
a61af66fc99e Initial load
duke
parents:
diff changeset
740 IDebugSystemObjects* ptrIDebugSystemObjects = (IDebugSystemObjects*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
741 ptrIDebugSystemObjects_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
742 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
743
a61af66fc99e Initial load
duke
parents:
diff changeset
744 ULONG id = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
745 if (ptrIDebugSystemObjects->GetThreadIdBySystemId((ULONG)sysId, &id) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
746 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetThreadIdBySystemId failed!", 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
747 }
a61af66fc99e Initial load
duke
parents:
diff changeset
748
a61af66fc99e Initial load
duke
parents:
diff changeset
749 return (jlong) id;
a61af66fc99e Initial load
duke
parents:
diff changeset
750 }
a61af66fc99e Initial load
duke
parents:
diff changeset
751
a61af66fc99e Initial load
duke
parents:
diff changeset
752 // manage COM 'auto' pointers (to avoid multiple Release
a61af66fc99e Initial load
duke
parents:
diff changeset
753 // calls at every early (exception) returns). Similar to AutoArrayPtr.
a61af66fc99e Initial load
duke
parents:
diff changeset
754
a61af66fc99e Initial load
duke
parents:
diff changeset
755 template <class T>
a61af66fc99e Initial load
duke
parents:
diff changeset
756 class AutoCOMPtr {
a61af66fc99e Initial load
duke
parents:
diff changeset
757 T* m_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
758
a61af66fc99e Initial load
duke
parents:
diff changeset
759 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
760 AutoCOMPtr(T* ptr) : m_ptr(ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
761 }
a61af66fc99e Initial load
duke
parents:
diff changeset
762
a61af66fc99e Initial load
duke
parents:
diff changeset
763 ~AutoCOMPtr() {
a61af66fc99e Initial load
duke
parents:
diff changeset
764 if (m_ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
765 m_ptr->Release();
a61af66fc99e Initial load
duke
parents:
diff changeset
766 }
a61af66fc99e Initial load
duke
parents:
diff changeset
767 }
a61af66fc99e Initial load
duke
parents:
diff changeset
768
a61af66fc99e Initial load
duke
parents:
diff changeset
769 T* operator->() {
a61af66fc99e Initial load
duke
parents:
diff changeset
770 return m_ptr;
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 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
775 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
776 * Method: consoleExecuteCommand0
a61af66fc99e Initial load
duke
parents:
diff changeset
777 * Signature: (Ljava/lang/String;)Ljava/lang/String;
a61af66fc99e Initial load
duke
parents:
diff changeset
778 */
a61af66fc99e Initial load
duke
parents:
diff changeset
779 JNIEXPORT jstring JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_consoleExecuteCommand0
a61af66fc99e Initial load
duke
parents:
diff changeset
780 (JNIEnv *env, jobject obj, jstring cmd) {
a61af66fc99e Initial load
duke
parents:
diff changeset
781 jboolean isCopy = JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
782 const char* buf = env->GetStringUTFChars(cmd, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
783 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
784 AutoJavaString command(env, cmd, buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
785
a61af66fc99e Initial load
duke
parents:
diff changeset
786 IDebugClient* ptrIDebugClient = (IDebugClient*) env->GetLongField(obj, ptrIDebugClient_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
787 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
788
a61af66fc99e Initial load
duke
parents:
diff changeset
789 IDebugClient* tmpClientPtr = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
790 if (ptrIDebugClient->CreateClient(&tmpClientPtr) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
791 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: CreateClient failed!", 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
792 }
a61af66fc99e Initial load
duke
parents:
diff changeset
793 AutoCOMPtr<IDebugClient> tmpClient(tmpClientPtr);
a61af66fc99e Initial load
duke
parents:
diff changeset
794
a61af66fc99e Initial load
duke
parents:
diff changeset
795 IDebugControl* tmpControlPtr = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
796 if (tmpClient->QueryInterface(__uuidof(IDebugControl), (PVOID*) &tmpControlPtr) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
797 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: QueryInterface (IDebugControl) failed", 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
798 }
a61af66fc99e Initial load
duke
parents:
diff changeset
799 AutoCOMPtr<IDebugControl> tmpControl(tmpControlPtr);
a61af66fc99e Initial load
duke
parents:
diff changeset
800
a61af66fc99e Initial load
duke
parents:
diff changeset
801 SAOutputCallbacks* saOutputCallbacks = (SAOutputCallbacks*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
802 ptrIDebugOutputCallbacks_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
803 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
804
a61af66fc99e Initial load
duke
parents:
diff changeset
805 saOutputCallbacks->clearBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
806
a61af66fc99e Initial load
duke
parents:
diff changeset
807 if (tmpClient->SetOutputCallbacks(saOutputCallbacks) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
808 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: SetOutputCallbacks failed!", 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
809 }
a61af66fc99e Initial load
duke
parents:
diff changeset
810
a61af66fc99e Initial load
duke
parents:
diff changeset
811 tmpControl->Execute(DEBUG_OUTPUT_VERBOSE, command, DEBUG_EXECUTE_DEFAULT);
a61af66fc99e Initial load
duke
parents:
diff changeset
812
a61af66fc99e Initial load
duke
parents:
diff changeset
813 const char* output = saOutputCallbacks->getBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
814 if (output == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
815 output = "";
a61af66fc99e Initial load
duke
parents:
diff changeset
816 }
a61af66fc99e Initial load
duke
parents:
diff changeset
817
a61af66fc99e Initial load
duke
parents:
diff changeset
818 jstring res = env->NewStringUTF(output);
a61af66fc99e Initial load
duke
parents:
diff changeset
819 saOutputCallbacks->clearBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
820 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
821 }
a61af66fc99e Initial load
duke
parents:
diff changeset
822
a61af66fc99e Initial load
duke
parents:
diff changeset
823 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
824 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
825 * Method: lookupByName0
a61af66fc99e Initial load
duke
parents:
diff changeset
826 * Signature: (Ljava/lang/String;Ljava/lang/String;)J
a61af66fc99e Initial load
duke
parents:
diff changeset
827 */
a61af66fc99e Initial load
duke
parents:
diff changeset
828
a61af66fc99e Initial load
duke
parents:
diff changeset
829 JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_lookupByName0
a61af66fc99e Initial load
duke
parents:
diff changeset
830 (JNIEnv *env, jobject obj, jstring objName, jstring sym) {
a61af66fc99e Initial load
duke
parents:
diff changeset
831 IDebugSymbols* ptrIDebugSymbols = (IDebugSymbols*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
832 ptrIDebugSymbols_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
833 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
834
a61af66fc99e Initial load
duke
parents:
diff changeset
835 jboolean isCopy;
a61af66fc99e Initial load
duke
parents:
diff changeset
836 const char* buf = env->GetStringUTFChars(sym, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
837 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
838 AutoJavaString name(env, sym, buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
839
a61af66fc99e Initial load
duke
parents:
diff changeset
840 ULONG64 offset = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
841 if (strstr(name, "::") != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
842 ptrIDebugSymbols->AddSymbolOptions(SYMOPT_UNDNAME);
a61af66fc99e Initial load
duke
parents:
diff changeset
843 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
844 ptrIDebugSymbols->RemoveSymbolOptions(SYMOPT_UNDNAME);
a61af66fc99e Initial load
duke
parents:
diff changeset
845 }
a61af66fc99e Initial load
duke
parents:
diff changeset
846 if (ptrIDebugSymbols->GetOffsetByName(name, &offset) != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
847 return (jlong) 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
848 }
a61af66fc99e Initial load
duke
parents:
diff changeset
849 return (jlong) offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
850 }
a61af66fc99e Initial load
duke
parents:
diff changeset
851
a61af66fc99e Initial load
duke
parents:
diff changeset
852 #define SYMBOL_BUFSIZE 512
a61af66fc99e Initial load
duke
parents:
diff changeset
853 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
854 * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
855 * Method: lookupByAddress0
a61af66fc99e Initial load
duke
parents:
diff changeset
856 * Signature: (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;
a61af66fc99e Initial load
duke
parents:
diff changeset
857 */
a61af66fc99e Initial load
duke
parents:
diff changeset
858 JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_lookupByAddress0
a61af66fc99e Initial load
duke
parents:
diff changeset
859 (JNIEnv *env, jobject obj, jlong address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
860 IDebugSymbols* ptrIDebugSymbols = (IDebugSymbols*) env->GetLongField(obj,
a61af66fc99e Initial load
duke
parents:
diff changeset
861 ptrIDebugSymbols_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
862 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
863
a61af66fc99e Initial load
duke
parents:
diff changeset
864 ULONG64 disp = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
865 char buf[SYMBOL_BUFSIZE];
a61af66fc99e Initial load
duke
parents:
diff changeset
866 memset(buf, 0, sizeof(buf));
a61af66fc99e Initial load
duke
parents:
diff changeset
867
a61af66fc99e Initial load
duke
parents:
diff changeset
868 if (ptrIDebugSymbols->GetNameByOffset(address, buf, sizeof(buf),0,&disp)
a61af66fc99e Initial load
duke
parents:
diff changeset
869 != S_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
870 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
871 }
a61af66fc99e Initial load
duke
parents:
diff changeset
872
a61af66fc99e Initial load
duke
parents:
diff changeset
873 jstring sym = env->NewStringUTF(buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
874 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
875 jobject res = env->CallObjectMethod(obj, createClosestSymbol_ID, sym, disp);
a61af66fc99e Initial load
duke
parents:
diff changeset
876 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
877 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
878 }