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