Mercurial > hg > truffle
annotate agent/src/os/linux/LinuxDebuggerLocal.c @ 12190:edb5ab0f3fe5
8001107: @Stable annotation for constant folding of lazily evaluated variables
Reviewed-by: rbackman, twisti, kvn
Contributed-by: john.r.rose@oracle.com, vladimir.x.ivanov@oracle.com
author | vlivanov |
---|---|
date | Tue, 10 Sep 2013 14:51:48 -0700 |
parents | 96bd4772ec62 |
children | f2512d89ad0c |
rev | line source |
---|---|
0 | 1 /* |
8670
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
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 | 22 * |
23 */ | |
24 | |
25 #include <jni.h> | |
26 #include "libproc.h" | |
27 | |
8670
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
28 #include <elf.h> |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
29 #include <sys/types.h> |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
30 #include <sys/stat.h> |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
31 #include <fcntl.h> |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
32 #include <string.h> |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
33 #include <limits.h> |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
34 |
0 | 35 #if defined(x86_64) && !defined(amd64) |
36 #define amd64 1 | |
37 #endif | |
38 | |
39 #ifdef i386 | |
40 #include "sun_jvm_hotspot_debugger_x86_X86ThreadContext.h" | |
41 #endif | |
42 | |
43 #ifdef amd64 | |
44 #include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h" | |
45 #endif | |
46 | |
47 #if defined(sparc) || defined(sparcv9) | |
48 #include "sun_jvm_hotspot_debugger_sparc_SPARCThreadContext.h" | |
49 #endif | |
50 | |
51 static jfieldID p_ps_prochandle_ID = 0; | |
52 static jfieldID threadList_ID = 0; | |
53 static jfieldID loadObjectList_ID = 0; | |
54 | |
55 static jmethodID createClosestSymbol_ID = 0; | |
56 static jmethodID createLoadObject_ID = 0; | |
57 static jmethodID getThreadForThreadId_ID = 0; | |
58 static jmethodID listAdd_ID = 0; | |
59 | |
60 #define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; } | |
61 #define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;} | |
62 #define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throw_new_debugger_exception(env, str); return value; } | |
63 #define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;} | |
64 | |
6641
a9fed06c01d2
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
1552
diff
changeset
|
65 void throw_new_debugger_exception(JNIEnv* env, const char* errMsg) { |
0 | 66 (*env)->ThrowNew(env, (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException"), errMsg); |
67 } | |
68 | |
6641
a9fed06c01d2
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
1552
diff
changeset
|
69 struct ps_prochandle* get_proc_handle(JNIEnv* env, jobject this_obj) { |
0 | 70 jlong ptr = (*env)->GetLongField(env, this_obj, p_ps_prochandle_ID); |
71 return (struct ps_prochandle*)(intptr_t)ptr; | |
72 } | |
73 | |
74 /* | |
75 * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal | |
76 * Method: init0 | |
77 * Signature: ()V | |
78 */ | |
79 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_init0 | |
80 (JNIEnv *env, jclass cls) { | |
81 jclass listClass; | |
82 | |
83 if (init_libproc(getenv("LIBSAPROC_DEBUG")) != true) { | |
84 THROW_NEW_DEBUGGER_EXCEPTION("can't initialize libproc"); | |
85 } | |
86 | |
87 // fields we use | |
88 p_ps_prochandle_ID = (*env)->GetFieldID(env, cls, "p_ps_prochandle", "J"); | |
89 CHECK_EXCEPTION; | |
90 threadList_ID = (*env)->GetFieldID(env, cls, "threadList", "Ljava/util/List;"); | |
91 CHECK_EXCEPTION; | |
92 loadObjectList_ID = (*env)->GetFieldID(env, cls, "loadObjectList", "Ljava/util/List;"); | |
93 CHECK_EXCEPTION; | |
94 | |
95 // methods we use | |
96 createClosestSymbol_ID = (*env)->GetMethodID(env, cls, "createClosestSymbol", | |
97 "(Ljava/lang/String;J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;"); | |
98 CHECK_EXCEPTION; | |
99 createLoadObject_ID = (*env)->GetMethodID(env, cls, "createLoadObject", | |
100 "(Ljava/lang/String;JJ)Lsun/jvm/hotspot/debugger/cdbg/LoadObject;"); | |
101 CHECK_EXCEPTION; | |
102 getThreadForThreadId_ID = (*env)->GetMethodID(env, cls, "getThreadForThreadId", | |
103 "(J)Lsun/jvm/hotspot/debugger/ThreadProxy;"); | |
104 CHECK_EXCEPTION; | |
105 // java.util.List method we call | |
106 listClass = (*env)->FindClass(env, "java/util/List"); | |
107 CHECK_EXCEPTION; | |
108 listAdd_ID = (*env)->GetMethodID(env, listClass, "add", "(Ljava/lang/Object;)Z"); | |
109 CHECK_EXCEPTION; | |
110 } | |
111 | |
112 JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_getAddressSize | |
113 (JNIEnv *env, jclass cls) | |
114 { | |
115 #ifdef _LP64 | |
116 return 8; | |
117 #else | |
118 return 4; | |
119 #endif | |
120 | |
121 } | |
122 | |
123 | |
124 static void fillThreadsAndLoadObjects(JNIEnv* env, jobject this_obj, struct ps_prochandle* ph) { | |
125 int n = 0, i = 0; | |
126 | |
127 // add threads | |
128 n = get_num_threads(ph); | |
129 for (i = 0; i < n; i++) { | |
130 jobject thread; | |
131 jobject threadList; | |
132 lwpid_t lwpid; | |
133 | |
134 lwpid = get_lwp_id(ph, i); | |
135 thread = (*env)->CallObjectMethod(env, this_obj, getThreadForThreadId_ID, | |
136 (jlong)lwpid); | |
137 CHECK_EXCEPTION; | |
138 threadList = (*env)->GetObjectField(env, this_obj, threadList_ID); | |
139 CHECK_EXCEPTION; | |
140 (*env)->CallBooleanMethod(env, threadList, listAdd_ID, thread); | |
141 CHECK_EXCEPTION; | |
142 } | |
143 | |
144 // add load objects | |
145 n = get_num_libs(ph); | |
146 for (i = 0; i < n; i++) { | |
147 uintptr_t base; | |
148 const char* name; | |
149 jobject loadObject; | |
150 jobject loadObjectList; | |
151 | |
152 base = get_lib_base(ph, i); | |
153 name = get_lib_name(ph, i); | |
154 loadObject = (*env)->CallObjectMethod(env, this_obj, createLoadObject_ID, | |
155 (*env)->NewStringUTF(env, name), (jlong)0, (jlong)base); | |
156 CHECK_EXCEPTION; | |
157 loadObjectList = (*env)->GetObjectField(env, this_obj, loadObjectList_ID); | |
158 CHECK_EXCEPTION; | |
159 (*env)->CallBooleanMethod(env, loadObjectList, listAdd_ID, loadObject); | |
160 CHECK_EXCEPTION; | |
161 } | |
162 } | |
163 | |
8670
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
164 |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
165 /* |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
166 * Verify that a named ELF binary file (core or executable) has the same |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
167 * bitness as ourselves. |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
168 * Throw an exception if there is a mismatch or other problem. |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
169 * |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
170 * If we proceed using a mismatched debugger/debuggee, the best to hope |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
171 * for is a missing symbol, the worst is a crash searching for debug symbols. |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
172 */ |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
173 void verifyBitness(JNIEnv *env, const char *binaryName) { |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
174 int fd = open(binaryName, O_RDONLY); |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
175 if (fd < 0) { |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
176 THROW_NEW_DEBUGGER_EXCEPTION("cannot open binary file"); |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
177 } |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
178 unsigned char elf_ident[EI_NIDENT]; |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
179 int i = read(fd, &elf_ident, sizeof(elf_ident)); |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
180 close(fd); |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
181 |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
182 if (i < 0) { |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
183 THROW_NEW_DEBUGGER_EXCEPTION("cannot read binary file"); |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
184 } |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
185 #ifndef _LP64 |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
186 if (elf_ident[EI_CLASS] == ELFCLASS64) { |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
187 THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 64 bit, use 64-bit java for debugger"); |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
188 } |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
189 #else |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
190 if (elf_ident[EI_CLASS] != ELFCLASS64) { |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
191 THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 32 bit, use 32 bit java for debugger"); |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
192 } |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
193 #endif |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
194 } |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
195 |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
196 |
0 | 197 /* |
198 * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal | |
199 * Method: attach0 | |
200 * Signature: (I)V | |
201 */ | |
202 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__I | |
203 (JNIEnv *env, jobject this_obj, jint jpid) { | |
204 | |
8670
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
205 // For bitness checking, locate binary at /proc/jpid/exe |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
206 char buf[PATH_MAX]; |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
207 snprintf((char *) &buf, PATH_MAX, "/proc/%d/exe", jpid); |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
208 verifyBitness(env, (char *) &buf); |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
209 CHECK_EXCEPTION; |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
210 |
0 | 211 struct ps_prochandle* ph; |
212 if ( (ph = Pgrab(jpid)) == NULL) { | |
213 THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the process"); | |
214 } | |
215 (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph); | |
216 fillThreadsAndLoadObjects(env, this_obj, ph); | |
217 } | |
218 | |
219 /* | |
220 * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal | |
221 * Method: attach0 | |
222 * Signature: (Ljava/lang/String;Ljava/lang/String;)V | |
223 */ | |
224 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2 | |
225 (JNIEnv *env, jobject this_obj, jstring execName, jstring coreName) { | |
226 const char *execName_cstr; | |
227 const char *coreName_cstr; | |
228 jboolean isCopy; | |
229 struct ps_prochandle* ph; | |
230 | |
231 execName_cstr = (*env)->GetStringUTFChars(env, execName, &isCopy); | |
232 CHECK_EXCEPTION; | |
233 coreName_cstr = (*env)->GetStringUTFChars(env, coreName, &isCopy); | |
234 CHECK_EXCEPTION; | |
235 | |
8670
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
236 verifyBitness(env, execName_cstr); |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
237 CHECK_EXCEPTION; |
96bd4772ec62
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
7994
diff
changeset
|
238 |
0 | 239 if ( (ph = Pgrab_core(execName_cstr, coreName_cstr)) == NULL) { |
240 (*env)->ReleaseStringUTFChars(env, execName, execName_cstr); | |
241 (*env)->ReleaseStringUTFChars(env, coreName, coreName_cstr); | |
242 THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the core file"); | |
243 } | |
244 (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph); | |
245 (*env)->ReleaseStringUTFChars(env, execName, execName_cstr); | |
246 (*env)->ReleaseStringUTFChars(env, coreName, coreName_cstr); | |
247 fillThreadsAndLoadObjects(env, this_obj, ph); | |
248 } | |
249 | |
250 /* | |
251 * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal | |
252 * Method: detach0 | |
253 * Signature: ()V | |
254 */ | |
255 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_detach0 | |
256 (JNIEnv *env, jobject this_obj) { | |
257 struct ps_prochandle* ph = get_proc_handle(env, this_obj); | |
258 if (ph != NULL) { | |
259 Prelease(ph); | |
260 } | |
261 } | |
262 | |
263 /* | |
264 * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal | |
265 * Method: lookupByName0 | |
266 * Signature: (Ljava/lang/String;Ljava/lang/String;)J | |
267 */ | |
268 JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_lookupByName0 | |
269 (JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) { | |
270 const char *objectName_cstr, *symbolName_cstr; | |
271 jlong addr; | |
272 jboolean isCopy; | |
273 struct ps_prochandle* ph = get_proc_handle(env, this_obj); | |
274 | |
275 objectName_cstr = NULL; | |
276 if (objectName != NULL) { | |
277 objectName_cstr = (*env)->GetStringUTFChars(env, objectName, &isCopy); | |
278 CHECK_EXCEPTION_(0); | |
279 } | |
280 symbolName_cstr = (*env)->GetStringUTFChars(env, symbolName, &isCopy); | |
281 CHECK_EXCEPTION_(0); | |
282 | |
283 addr = (jlong) lookup_symbol(ph, objectName_cstr, symbolName_cstr); | |
284 | |
285 if (objectName_cstr != NULL) { | |
286 (*env)->ReleaseStringUTFChars(env, objectName, objectName_cstr); | |
287 } | |
288 (*env)->ReleaseStringUTFChars(env, symbolName, symbolName_cstr); | |
289 return addr; | |
290 } | |
291 | |
292 /* | |
293 * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal | |
294 * Method: lookupByAddress0 | |
295 * Signature: (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol; | |
296 */ | |
297 JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_lookupByAddress0 | |
298 (JNIEnv *env, jobject this_obj, jlong addr) { | |
299 uintptr_t offset; | |
300 const char* sym = NULL; | |
301 | |
302 struct ps_prochandle* ph = get_proc_handle(env, this_obj); | |
303 sym = symbol_for_pc(ph, (uintptr_t) addr, &offset); | |
304 if (sym == NULL) return 0; | |
305 return (*env)->CallObjectMethod(env, this_obj, createClosestSymbol_ID, | |
306 (*env)->NewStringUTF(env, sym), (jlong)offset); | |
307 } | |
308 | |
309 /* | |
310 * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal | |
311 * Method: readBytesFromProcess0 | |
312 * Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult; | |
313 */ | |
314 JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_readBytesFromProcess0 | |
315 (JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) { | |
316 | |
317 jboolean isCopy; | |
318 jbyteArray array; | |
319 jbyte *bufPtr; | |
320 ps_err_e err; | |
321 | |
322 array = (*env)->NewByteArray(env, numBytes); | |
323 CHECK_EXCEPTION_(0); | |
324 bufPtr = (*env)->GetByteArrayElements(env, array, &isCopy); | |
325 CHECK_EXCEPTION_(0); | |
326 | |
327 err = ps_pdread(get_proc_handle(env, this_obj), (psaddr_t) (uintptr_t)addr, bufPtr, numBytes); | |
328 (*env)->ReleaseByteArrayElements(env, array, bufPtr, 0); | |
329 return (err == PS_OK)? array : 0; | |
330 } | |
331 | |
7994 | 332 #if defined(i386) || defined(amd64) || defined(sparc) || defined(sparcv9) |
0 | 333 JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_getThreadIntegerRegisterSet0 |
334 (JNIEnv *env, jobject this_obj, jint lwp_id) { | |
335 | |
336 struct user_regs_struct gregs; | |
337 jboolean isCopy; | |
338 jlongArray array; | |
339 jlong *regs; | |
340 int i; | |
341 | |
342 struct ps_prochandle* ph = get_proc_handle(env, this_obj); | |
343 if (get_lwp_regs(ph, lwp_id, &gregs) != true) { | |
344 THROW_NEW_DEBUGGER_EXCEPTION_("get_thread_regs failed for a lwp", 0); | |
345 } | |
346 | |
347 #undef NPRGREG | |
348 #ifdef i386 | |
349 #define NPRGREG sun_jvm_hotspot_debugger_x86_X86ThreadContext_NPRGREG | |
350 #endif | |
351 #ifdef amd64 | |
352 #define NPRGREG sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_NPRGREG | |
353 #endif | |
354 #if defined(sparc) || defined(sparcv9) | |
355 #define NPRGREG sun_jvm_hotspot_debugger_sparc_SPARCThreadContext_NPRGREG | |
356 #endif | |
357 | |
358 array = (*env)->NewLongArray(env, NPRGREG); | |
359 CHECK_EXCEPTION_(0); | |
360 regs = (*env)->GetLongArrayElements(env, array, &isCopy); | |
361 | |
362 #undef REG_INDEX | |
363 | |
364 #ifdef i386 | |
365 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##reg | |
366 | |
367 regs[REG_INDEX(GS)] = (uintptr_t) gregs.xgs; | |
368 regs[REG_INDEX(FS)] = (uintptr_t) gregs.xfs; | |
369 regs[REG_INDEX(ES)] = (uintptr_t) gregs.xes; | |
370 regs[REG_INDEX(DS)] = (uintptr_t) gregs.xds; | |
371 regs[REG_INDEX(EDI)] = (uintptr_t) gregs.edi; | |
372 regs[REG_INDEX(ESI)] = (uintptr_t) gregs.esi; | |
373 regs[REG_INDEX(FP)] = (uintptr_t) gregs.ebp; | |
374 regs[REG_INDEX(SP)] = (uintptr_t) gregs.esp; | |
375 regs[REG_INDEX(EBX)] = (uintptr_t) gregs.ebx; | |
376 regs[REG_INDEX(EDX)] = (uintptr_t) gregs.edx; | |
377 regs[REG_INDEX(ECX)] = (uintptr_t) gregs.ecx; | |
378 regs[REG_INDEX(EAX)] = (uintptr_t) gregs.eax; | |
379 regs[REG_INDEX(PC)] = (uintptr_t) gregs.eip; | |
380 regs[REG_INDEX(CS)] = (uintptr_t) gregs.xcs; | |
381 regs[REG_INDEX(SS)] = (uintptr_t) gregs.xss; | |
382 | |
383 #endif /* i386 */ | |
384 | |
385 #ifdef amd64 | |
386 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_##reg | |
387 | |
388 regs[REG_INDEX(R15)] = gregs.r15; | |
389 regs[REG_INDEX(R14)] = gregs.r14; | |
390 regs[REG_INDEX(R13)] = gregs.r13; | |
391 regs[REG_INDEX(R12)] = gregs.r12; | |
392 regs[REG_INDEX(RBP)] = gregs.rbp; | |
393 regs[REG_INDEX(RBX)] = gregs.rbx; | |
394 regs[REG_INDEX(R11)] = gregs.r11; | |
395 regs[REG_INDEX(R10)] = gregs.r10; | |
396 regs[REG_INDEX(R9)] = gregs.r9; | |
397 regs[REG_INDEX(R8)] = gregs.r8; | |
398 regs[REG_INDEX(RAX)] = gregs.rax; | |
399 regs[REG_INDEX(RCX)] = gregs.rcx; | |
400 regs[REG_INDEX(RDX)] = gregs.rdx; | |
401 regs[REG_INDEX(RSI)] = gregs.rsi; | |
402 regs[REG_INDEX(RDI)] = gregs.rdi; | |
403 regs[REG_INDEX(RIP)] = gregs.rip; | |
404 regs[REG_INDEX(CS)] = gregs.cs; | |
405 regs[REG_INDEX(RSP)] = gregs.rsp; | |
406 regs[REG_INDEX(SS)] = gregs.ss; | |
407 regs[REG_INDEX(FSBASE)] = gregs.fs_base; | |
408 regs[REG_INDEX(GSBASE)] = gregs.gs_base; | |
409 regs[REG_INDEX(DS)] = gregs.ds; | |
410 regs[REG_INDEX(ES)] = gregs.es; | |
411 regs[REG_INDEX(FS)] = gregs.fs; | |
412 regs[REG_INDEX(GS)] = gregs.gs; | |
413 | |
414 #endif /* amd64 */ | |
415 | |
416 #if defined(sparc) || defined(sparcv9) | |
417 | |
418 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_sparc_SPARCThreadContext_##reg | |
419 | |
420 #ifdef _LP64 | |
421 regs[REG_INDEX(R_PSR)] = gregs.tstate; | |
422 regs[REG_INDEX(R_PC)] = gregs.tpc; | |
423 regs[REG_INDEX(R_nPC)] = gregs.tnpc; | |
424 regs[REG_INDEX(R_Y)] = gregs.y; | |
425 #else | |
426 regs[REG_INDEX(R_PSR)] = gregs.psr; | |
427 regs[REG_INDEX(R_PC)] = gregs.pc; | |
428 regs[REG_INDEX(R_nPC)] = gregs.npc; | |
429 regs[REG_INDEX(R_Y)] = gregs.y; | |
430 #endif | |
431 regs[REG_INDEX(R_G0)] = 0 ; | |
432 regs[REG_INDEX(R_G1)] = gregs.u_regs[0]; | |
433 regs[REG_INDEX(R_G2)] = gregs.u_regs[1]; | |
434 regs[REG_INDEX(R_G3)] = gregs.u_regs[2]; | |
435 regs[REG_INDEX(R_G4)] = gregs.u_regs[3]; | |
436 regs[REG_INDEX(R_G5)] = gregs.u_regs[4]; | |
437 regs[REG_INDEX(R_G6)] = gregs.u_regs[5]; | |
438 regs[REG_INDEX(R_G7)] = gregs.u_regs[6]; | |
439 regs[REG_INDEX(R_O0)] = gregs.u_regs[7]; | |
440 regs[REG_INDEX(R_O1)] = gregs.u_regs[8]; | |
441 regs[REG_INDEX(R_O2)] = gregs.u_regs[ 9]; | |
442 regs[REG_INDEX(R_O3)] = gregs.u_regs[10]; | |
443 regs[REG_INDEX(R_O4)] = gregs.u_regs[11]; | |
444 regs[REG_INDEX(R_O5)] = gregs.u_regs[12]; | |
445 regs[REG_INDEX(R_O6)] = gregs.u_regs[13]; | |
446 regs[REG_INDEX(R_O7)] = gregs.u_regs[14]; | |
447 #endif /* sparc */ | |
448 | |
449 | |
450 (*env)->ReleaseLongArrayElements(env, array, regs, JNI_COMMIT); | |
451 return array; | |
452 } | |
6641
a9fed06c01d2
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
1552
diff
changeset
|
453 #endif |