author | sangheki |
Mon, 07 Mar 2016 10:01:38 +0000 | |
changeset 36575 | a61a9898d623 |
parent 35217 | ce4b5303a813 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
15850
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
2 |
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
#include <jni.h> |
|
26 |
#include "libproc.h" |
|
27 |
||
15850
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
28 |
#include <elf.h> |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
29 |
#include <sys/types.h> |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
30 |
#include <sys/stat.h> |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
31 |
#include <fcntl.h> |
20295 | 32 |
#include <stdlib.h> |
15850
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
33 |
#include <string.h> |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
34 |
#include <limits.h> |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
35 |
|
1 | 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 |
||
35075
ca79cbf3f106
8073139: PPC64: User-visible arch directory and os.arch value on ppc64le cause issues with Java tooling
asmundak
parents:
35049
diff
changeset
|
52 |
#if defined(ppc64) || defined(ppc64le) |
28369 | 53 |
#include "sun_jvm_hotspot_debugger_ppc64_PPC64ThreadContext.h" |
54 |
#endif |
|
55 |
||
31399 | 56 |
#ifdef aarch64 |
57 |
#include "sun_jvm_hotspot_debugger_aarch64_AARCH64ThreadContext.h" |
|
58 |
#endif |
|
59 |
||
1 | 60 |
static jfieldID p_ps_prochandle_ID = 0; |
61 |
static jfieldID threadList_ID = 0; |
|
62 |
static jfieldID loadObjectList_ID = 0; |
|
63 |
||
64 |
static jmethodID createClosestSymbol_ID = 0; |
|
65 |
static jmethodID createLoadObject_ID = 0; |
|
66 |
static jmethodID getThreadForThreadId_ID = 0; |
|
67 |
static jmethodID listAdd_ID = 0; |
|
68 |
||
69 |
#define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; } |
|
70 |
#define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;} |
|
71 |
#define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throw_new_debugger_exception(env, str); return value; } |
|
72 |
#define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;} |
|
73 |
||
13529
dc25e69fd16d
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
5547
diff
changeset
|
74 |
void throw_new_debugger_exception(JNIEnv* env, const char* errMsg) { |
26411
8daa5fdf642f
8029172: warnings from b117 for hotspot.agent.src.os.linux: JNI exception pending
dsamersoff
parents:
20295
diff
changeset
|
75 |
jclass clazz; |
8daa5fdf642f
8029172: warnings from b117 for hotspot.agent.src.os.linux: JNI exception pending
dsamersoff
parents:
20295
diff
changeset
|
76 |
clazz = (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException"); |
8daa5fdf642f
8029172: warnings from b117 for hotspot.agent.src.os.linux: JNI exception pending
dsamersoff
parents:
20295
diff
changeset
|
77 |
CHECK_EXCEPTION; |
8daa5fdf642f
8029172: warnings from b117 for hotspot.agent.src.os.linux: JNI exception pending
dsamersoff
parents:
20295
diff
changeset
|
78 |
(*env)->ThrowNew(env, clazz, errMsg); |
1 | 79 |
} |
80 |
||
13529
dc25e69fd16d
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
5547
diff
changeset
|
81 |
struct ps_prochandle* get_proc_handle(JNIEnv* env, jobject this_obj) { |
1 | 82 |
jlong ptr = (*env)->GetLongField(env, this_obj, p_ps_prochandle_ID); |
83 |
return (struct ps_prochandle*)(intptr_t)ptr; |
|
84 |
} |
|
85 |
||
86 |
/* |
|
87 |
* Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal |
|
88 |
* Method: init0 |
|
89 |
* Signature: ()V |
|
90 |
*/ |
|
91 |
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_init0 |
|
92 |
(JNIEnv *env, jclass cls) { |
|
93 |
jclass listClass; |
|
94 |
||
20295 | 95 |
if (init_libproc(getenv("LIBSAPROC_DEBUG") != NULL) != true) { |
1 | 96 |
THROW_NEW_DEBUGGER_EXCEPTION("can't initialize libproc"); |
97 |
} |
|
98 |
||
99 |
// fields we use |
|
100 |
p_ps_prochandle_ID = (*env)->GetFieldID(env, cls, "p_ps_prochandle", "J"); |
|
101 |
CHECK_EXCEPTION; |
|
102 |
threadList_ID = (*env)->GetFieldID(env, cls, "threadList", "Ljava/util/List;"); |
|
103 |
CHECK_EXCEPTION; |
|
104 |
loadObjectList_ID = (*env)->GetFieldID(env, cls, "loadObjectList", "Ljava/util/List;"); |
|
105 |
CHECK_EXCEPTION; |
|
106 |
||
107 |
// methods we use |
|
108 |
createClosestSymbol_ID = (*env)->GetMethodID(env, cls, "createClosestSymbol", |
|
109 |
"(Ljava/lang/String;J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;"); |
|
110 |
CHECK_EXCEPTION; |
|
111 |
createLoadObject_ID = (*env)->GetMethodID(env, cls, "createLoadObject", |
|
112 |
"(Ljava/lang/String;JJ)Lsun/jvm/hotspot/debugger/cdbg/LoadObject;"); |
|
113 |
CHECK_EXCEPTION; |
|
114 |
getThreadForThreadId_ID = (*env)->GetMethodID(env, cls, "getThreadForThreadId", |
|
115 |
"(J)Lsun/jvm/hotspot/debugger/ThreadProxy;"); |
|
116 |
CHECK_EXCEPTION; |
|
117 |
// java.util.List method we call |
|
118 |
listClass = (*env)->FindClass(env, "java/util/List"); |
|
119 |
CHECK_EXCEPTION; |
|
120 |
listAdd_ID = (*env)->GetMethodID(env, listClass, "add", "(Ljava/lang/Object;)Z"); |
|
121 |
CHECK_EXCEPTION; |
|
122 |
} |
|
123 |
||
124 |
JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_getAddressSize |
|
125 |
(JNIEnv *env, jclass cls) |
|
126 |
{ |
|
127 |
#ifdef _LP64 |
|
128 |
return 8; |
|
129 |
#else |
|
130 |
return 4; |
|
131 |
#endif |
|
132 |
||
133 |
} |
|
134 |
||
135 |
||
136 |
static void fillThreadsAndLoadObjects(JNIEnv* env, jobject this_obj, struct ps_prochandle* ph) { |
|
137 |
int n = 0, i = 0; |
|
138 |
||
139 |
// add threads |
|
140 |
n = get_num_threads(ph); |
|
141 |
for (i = 0; i < n; i++) { |
|
142 |
jobject thread; |
|
143 |
jobject threadList; |
|
144 |
lwpid_t lwpid; |
|
145 |
||
146 |
lwpid = get_lwp_id(ph, i); |
|
147 |
thread = (*env)->CallObjectMethod(env, this_obj, getThreadForThreadId_ID, |
|
148 |
(jlong)lwpid); |
|
149 |
CHECK_EXCEPTION; |
|
150 |
threadList = (*env)->GetObjectField(env, this_obj, threadList_ID); |
|
151 |
CHECK_EXCEPTION; |
|
152 |
(*env)->CallBooleanMethod(env, threadList, listAdd_ID, thread); |
|
153 |
CHECK_EXCEPTION; |
|
154 |
} |
|
155 |
||
156 |
// add load objects |
|
157 |
n = get_num_libs(ph); |
|
158 |
for (i = 0; i < n; i++) { |
|
159 |
uintptr_t base; |
|
160 |
const char* name; |
|
161 |
jobject loadObject; |
|
162 |
jobject loadObjectList; |
|
26411
8daa5fdf642f
8029172: warnings from b117 for hotspot.agent.src.os.linux: JNI exception pending
dsamersoff
parents:
20295
diff
changeset
|
163 |
jstring str; |
1 | 164 |
|
165 |
base = get_lib_base(ph, i); |
|
166 |
name = get_lib_name(ph, i); |
|
26411
8daa5fdf642f
8029172: warnings from b117 for hotspot.agent.src.os.linux: JNI exception pending
dsamersoff
parents:
20295
diff
changeset
|
167 |
|
8daa5fdf642f
8029172: warnings from b117 for hotspot.agent.src.os.linux: JNI exception pending
dsamersoff
parents:
20295
diff
changeset
|
168 |
str = (*env)->NewStringUTF(env, name); |
8daa5fdf642f
8029172: warnings from b117 for hotspot.agent.src.os.linux: JNI exception pending
dsamersoff
parents:
20295
diff
changeset
|
169 |
CHECK_EXCEPTION; |
8daa5fdf642f
8029172: warnings from b117 for hotspot.agent.src.os.linux: JNI exception pending
dsamersoff
parents:
20295
diff
changeset
|
170 |
loadObject = (*env)->CallObjectMethod(env, this_obj, createLoadObject_ID, str, (jlong)0, (jlong)base); |
1 | 171 |
CHECK_EXCEPTION; |
172 |
loadObjectList = (*env)->GetObjectField(env, this_obj, loadObjectList_ID); |
|
173 |
CHECK_EXCEPTION; |
|
174 |
(*env)->CallBooleanMethod(env, loadObjectList, listAdd_ID, loadObject); |
|
175 |
CHECK_EXCEPTION; |
|
176 |
} |
|
177 |
} |
|
178 |
||
15850
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
179 |
|
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
180 |
/* |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
181 |
* Verify that a named ELF binary file (core or executable) has the same |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
182 |
* bitness as ourselves. |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
183 |
* Throw an exception if there is a mismatch or other problem. |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
184 |
* |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
185 |
* If we proceed using a mismatched debugger/debuggee, the best to hope |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
186 |
* for is a missing symbol, the worst is a crash searching for debug symbols. |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
187 |
*/ |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
188 |
void verifyBitness(JNIEnv *env, const char *binaryName) { |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
189 |
int fd = open(binaryName, O_RDONLY); |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
190 |
if (fd < 0) { |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
191 |
THROW_NEW_DEBUGGER_EXCEPTION("cannot open binary file"); |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
192 |
} |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
193 |
unsigned char elf_ident[EI_NIDENT]; |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
194 |
int i = read(fd, &elf_ident, sizeof(elf_ident)); |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
195 |
close(fd); |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
196 |
|
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
197 |
if (i < 0) { |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
198 |
THROW_NEW_DEBUGGER_EXCEPTION("cannot read binary file"); |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
199 |
} |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
200 |
#ifndef _LP64 |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
201 |
if (elf_ident[EI_CLASS] == ELFCLASS64) { |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
202 |
THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 64 bit, use 64-bit java for debugger"); |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
203 |
} |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
204 |
#else |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
205 |
if (elf_ident[EI_CLASS] != ELFCLASS64) { |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
206 |
THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 32 bit, use 32 bit java for debugger"); |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
207 |
} |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
208 |
#endif |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
209 |
} |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
210 |
|
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
211 |
|
1 | 212 |
/* |
213 |
* Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal |
|
214 |
* Method: attach0 |
|
215 |
* Signature: (I)V |
|
216 |
*/ |
|
217 |
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__I |
|
218 |
(JNIEnv *env, jobject this_obj, jint jpid) { |
|
219 |
||
15850
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
220 |
// For bitness checking, locate binary at /proc/jpid/exe |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
221 |
char buf[PATH_MAX]; |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
222 |
snprintf((char *) &buf, PATH_MAX, "/proc/%d/exe", jpid); |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
223 |
verifyBitness(env, (char *) &buf); |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
224 |
CHECK_EXCEPTION; |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
225 |
|
35049
5a30aa672689
8145099: Better error message when SA can't attach to a process
sla
parents:
31399
diff
changeset
|
226 |
char err_buf[200]; |
1 | 227 |
struct ps_prochandle* ph; |
35049
5a30aa672689
8145099: Better error message when SA can't attach to a process
sla
parents:
31399
diff
changeset
|
228 |
if ( (ph = Pgrab(jpid, err_buf, sizeof(err_buf))) == NULL) { |
5a30aa672689
8145099: Better error message when SA can't attach to a process
sla
parents:
31399
diff
changeset
|
229 |
char msg[230]; |
5a30aa672689
8145099: Better error message when SA can't attach to a process
sla
parents:
31399
diff
changeset
|
230 |
snprintf(msg, sizeof(msg), "Can't attach to the process: %s", err_buf); |
5a30aa672689
8145099: Better error message when SA can't attach to a process
sla
parents:
31399
diff
changeset
|
231 |
THROW_NEW_DEBUGGER_EXCEPTION(msg); |
1 | 232 |
} |
233 |
(*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph); |
|
234 |
fillThreadsAndLoadObjects(env, this_obj, ph); |
|
235 |
} |
|
236 |
||
237 |
/* |
|
238 |
* Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal |
|
239 |
* Method: attach0 |
|
240 |
* Signature: (Ljava/lang/String;Ljava/lang/String;)V |
|
241 |
*/ |
|
242 |
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2 |
|
243 |
(JNIEnv *env, jobject this_obj, jstring execName, jstring coreName) { |
|
244 |
const char *execName_cstr; |
|
245 |
const char *coreName_cstr; |
|
246 |
jboolean isCopy; |
|
247 |
struct ps_prochandle* ph; |
|
248 |
||
249 |
execName_cstr = (*env)->GetStringUTFChars(env, execName, &isCopy); |
|
250 |
CHECK_EXCEPTION; |
|
251 |
coreName_cstr = (*env)->GetStringUTFChars(env, coreName, &isCopy); |
|
252 |
CHECK_EXCEPTION; |
|
253 |
||
15850
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
254 |
verifyBitness(env, execName_cstr); |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
255 |
CHECK_EXCEPTION; |
0d2f541fd6ed
8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents:
15475
diff
changeset
|
256 |
|
1 | 257 |
if ( (ph = Pgrab_core(execName_cstr, coreName_cstr)) == NULL) { |
258 |
(*env)->ReleaseStringUTFChars(env, execName, execName_cstr); |
|
259 |
(*env)->ReleaseStringUTFChars(env, coreName, coreName_cstr); |
|
260 |
THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the core file"); |
|
261 |
} |
|
262 |
(*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph); |
|
263 |
(*env)->ReleaseStringUTFChars(env, execName, execName_cstr); |
|
264 |
(*env)->ReleaseStringUTFChars(env, coreName, coreName_cstr); |
|
265 |
fillThreadsAndLoadObjects(env, this_obj, ph); |
|
266 |
} |
|
267 |
||
268 |
/* |
|
269 |
* Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal |
|
270 |
* Method: detach0 |
|
271 |
* Signature: ()V |
|
272 |
*/ |
|
273 |
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_detach0 |
|
274 |
(JNIEnv *env, jobject this_obj) { |
|
275 |
struct ps_prochandle* ph = get_proc_handle(env, this_obj); |
|
276 |
if (ph != NULL) { |
|
277 |
Prelease(ph); |
|
278 |
} |
|
279 |
} |
|
280 |
||
281 |
/* |
|
282 |
* Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal |
|
283 |
* Method: lookupByName0 |
|
284 |
* Signature: (Ljava/lang/String;Ljava/lang/String;)J |
|
285 |
*/ |
|
286 |
JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_lookupByName0 |
|
287 |
(JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) { |
|
288 |
const char *objectName_cstr, *symbolName_cstr; |
|
289 |
jlong addr; |
|
290 |
jboolean isCopy; |
|
291 |
struct ps_prochandle* ph = get_proc_handle(env, this_obj); |
|
292 |
||
293 |
objectName_cstr = NULL; |
|
294 |
if (objectName != NULL) { |
|
295 |
objectName_cstr = (*env)->GetStringUTFChars(env, objectName, &isCopy); |
|
296 |
CHECK_EXCEPTION_(0); |
|
297 |
} |
|
298 |
symbolName_cstr = (*env)->GetStringUTFChars(env, symbolName, &isCopy); |
|
299 |
CHECK_EXCEPTION_(0); |
|
300 |
||
301 |
addr = (jlong) lookup_symbol(ph, objectName_cstr, symbolName_cstr); |
|
302 |
||
303 |
if (objectName_cstr != NULL) { |
|
304 |
(*env)->ReleaseStringUTFChars(env, objectName, objectName_cstr); |
|
305 |
} |
|
306 |
(*env)->ReleaseStringUTFChars(env, symbolName, symbolName_cstr); |
|
307 |
return addr; |
|
308 |
} |
|
309 |
||
310 |
/* |
|
311 |
* Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal |
|
312 |
* Method: lookupByAddress0 |
|
313 |
* Signature: (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol; |
|
314 |
*/ |
|
315 |
JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_lookupByAddress0 |
|
316 |
(JNIEnv *env, jobject this_obj, jlong addr) { |
|
317 |
uintptr_t offset; |
|
26411
8daa5fdf642f
8029172: warnings from b117 for hotspot.agent.src.os.linux: JNI exception pending
dsamersoff
parents:
20295
diff
changeset
|
318 |
jobject obj; |
8daa5fdf642f
8029172: warnings from b117 for hotspot.agent.src.os.linux: JNI exception pending
dsamersoff
parents:
20295
diff
changeset
|
319 |
jstring str; |
1 | 320 |
const char* sym = NULL; |
321 |
||
322 |
struct ps_prochandle* ph = get_proc_handle(env, this_obj); |
|
323 |
sym = symbol_for_pc(ph, (uintptr_t) addr, &offset); |
|
324 |
if (sym == NULL) return 0; |
|
26411
8daa5fdf642f
8029172: warnings from b117 for hotspot.agent.src.os.linux: JNI exception pending
dsamersoff
parents:
20295
diff
changeset
|
325 |
str = (*env)->NewStringUTF(env, sym); |
8daa5fdf642f
8029172: warnings from b117 for hotspot.agent.src.os.linux: JNI exception pending
dsamersoff
parents:
20295
diff
changeset
|
326 |
CHECK_EXCEPTION_(NULL); |
8daa5fdf642f
8029172: warnings from b117 for hotspot.agent.src.os.linux: JNI exception pending
dsamersoff
parents:
20295
diff
changeset
|
327 |
obj = (*env)->CallObjectMethod(env, this_obj, createClosestSymbol_ID, str, (jlong)offset); |
8daa5fdf642f
8029172: warnings from b117 for hotspot.agent.src.os.linux: JNI exception pending
dsamersoff
parents:
20295
diff
changeset
|
328 |
CHECK_EXCEPTION_(NULL); |
8daa5fdf642f
8029172: warnings from b117 for hotspot.agent.src.os.linux: JNI exception pending
dsamersoff
parents:
20295
diff
changeset
|
329 |
return obj; |
1 | 330 |
} |
331 |
||
332 |
/* |
|
333 |
* Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal |
|
334 |
* Method: readBytesFromProcess0 |
|
335 |
* Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult; |
|
336 |
*/ |
|
337 |
JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_readBytesFromProcess0 |
|
338 |
(JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) { |
|
339 |
||
340 |
jboolean isCopy; |
|
341 |
jbyteArray array; |
|
342 |
jbyte *bufPtr; |
|
343 |
ps_err_e err; |
|
344 |
||
345 |
array = (*env)->NewByteArray(env, numBytes); |
|
346 |
CHECK_EXCEPTION_(0); |
|
347 |
bufPtr = (*env)->GetByteArrayElements(env, array, &isCopy); |
|
348 |
CHECK_EXCEPTION_(0); |
|
349 |
||
350 |
err = ps_pdread(get_proc_handle(env, this_obj), (psaddr_t) (uintptr_t)addr, bufPtr, numBytes); |
|
351 |
(*env)->ReleaseByteArrayElements(env, array, bufPtr, 0); |
|
352 |
return (err == PS_OK)? array : 0; |
|
353 |
} |
|
354 |
||
35075
ca79cbf3f106
8073139: PPC64: User-visible arch directory and os.arch value on ppc64le cause issues with Java tooling
asmundak
parents:
35049
diff
changeset
|
355 |
#if defined(i386) || defined(amd64) || defined(sparc) || defined(sparcv9) | defined(ppc64) || defined(ppc64le) || defined(aarch64) |
1 | 356 |
JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_getThreadIntegerRegisterSet0 |
357 |
(JNIEnv *env, jobject this_obj, jint lwp_id) { |
|
358 |
||
359 |
struct user_regs_struct gregs; |
|
360 |
jboolean isCopy; |
|
361 |
jlongArray array; |
|
362 |
jlong *regs; |
|
363 |
int i; |
|
364 |
||
365 |
struct ps_prochandle* ph = get_proc_handle(env, this_obj); |
|
366 |
if (get_lwp_regs(ph, lwp_id, &gregs) != true) { |
|
367 |
THROW_NEW_DEBUGGER_EXCEPTION_("get_thread_regs failed for a lwp", 0); |
|
368 |
} |
|
369 |
||
370 |
#undef NPRGREG |
|
371 |
#ifdef i386 |
|
372 |
#define NPRGREG sun_jvm_hotspot_debugger_x86_X86ThreadContext_NPRGREG |
|
373 |
#endif |
|
374 |
#ifdef amd64 |
|
375 |
#define NPRGREG sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_NPRGREG |
|
376 |
#endif |
|
29180 | 377 |
#ifdef aarch64 |
31399 | 378 |
#define NPRGREG sun_jvm_hotspot_debugger_aarch64_AARCH64ThreadContext_NPRGREG |
29180 | 379 |
#endif |
1 | 380 |
#if defined(sparc) || defined(sparcv9) |
381 |
#define NPRGREG sun_jvm_hotspot_debugger_sparc_SPARCThreadContext_NPRGREG |
|
382 |
#endif |
|
35075
ca79cbf3f106
8073139: PPC64: User-visible arch directory and os.arch value on ppc64le cause issues with Java tooling
asmundak
parents:
35049
diff
changeset
|
383 |
#if defined(ppc64) || defined(ppc64le) |
28369 | 384 |
#define NPRGREG sun_jvm_hotspot_debugger_ppc64_PPC64ThreadContext_NPRGREG |
385 |
#endif |
|
386 |
||
1 | 387 |
|
388 |
array = (*env)->NewLongArray(env, NPRGREG); |
|
389 |
CHECK_EXCEPTION_(0); |
|
390 |
regs = (*env)->GetLongArrayElements(env, array, &isCopy); |
|
391 |
||
392 |
#undef REG_INDEX |
|
393 |
||
394 |
#ifdef i386 |
|
395 |
#define REG_INDEX(reg) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##reg |
|
396 |
||
397 |
regs[REG_INDEX(GS)] = (uintptr_t) gregs.xgs; |
|
398 |
regs[REG_INDEX(FS)] = (uintptr_t) gregs.xfs; |
|
399 |
regs[REG_INDEX(ES)] = (uintptr_t) gregs.xes; |
|
400 |
regs[REG_INDEX(DS)] = (uintptr_t) gregs.xds; |
|
401 |
regs[REG_INDEX(EDI)] = (uintptr_t) gregs.edi; |
|
402 |
regs[REG_INDEX(ESI)] = (uintptr_t) gregs.esi; |
|
403 |
regs[REG_INDEX(FP)] = (uintptr_t) gregs.ebp; |
|
404 |
regs[REG_INDEX(SP)] = (uintptr_t) gregs.esp; |
|
405 |
regs[REG_INDEX(EBX)] = (uintptr_t) gregs.ebx; |
|
406 |
regs[REG_INDEX(EDX)] = (uintptr_t) gregs.edx; |
|
407 |
regs[REG_INDEX(ECX)] = (uintptr_t) gregs.ecx; |
|
408 |
regs[REG_INDEX(EAX)] = (uintptr_t) gregs.eax; |
|
409 |
regs[REG_INDEX(PC)] = (uintptr_t) gregs.eip; |
|
410 |
regs[REG_INDEX(CS)] = (uintptr_t) gregs.xcs; |
|
411 |
regs[REG_INDEX(SS)] = (uintptr_t) gregs.xss; |
|
412 |
||
413 |
#endif /* i386 */ |
|
414 |
||
415 |
#ifdef amd64 |
|
416 |
#define REG_INDEX(reg) sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_##reg |
|
417 |
||
418 |
regs[REG_INDEX(R15)] = gregs.r15; |
|
419 |
regs[REG_INDEX(R14)] = gregs.r14; |
|
420 |
regs[REG_INDEX(R13)] = gregs.r13; |
|
421 |
regs[REG_INDEX(R12)] = gregs.r12; |
|
422 |
regs[REG_INDEX(RBP)] = gregs.rbp; |
|
423 |
regs[REG_INDEX(RBX)] = gregs.rbx; |
|
424 |
regs[REG_INDEX(R11)] = gregs.r11; |
|
425 |
regs[REG_INDEX(R10)] = gregs.r10; |
|
426 |
regs[REG_INDEX(R9)] = gregs.r9; |
|
427 |
regs[REG_INDEX(R8)] = gregs.r8; |
|
428 |
regs[REG_INDEX(RAX)] = gregs.rax; |
|
429 |
regs[REG_INDEX(RCX)] = gregs.rcx; |
|
430 |
regs[REG_INDEX(RDX)] = gregs.rdx; |
|
431 |
regs[REG_INDEX(RSI)] = gregs.rsi; |
|
432 |
regs[REG_INDEX(RDI)] = gregs.rdi; |
|
433 |
regs[REG_INDEX(RIP)] = gregs.rip; |
|
434 |
regs[REG_INDEX(CS)] = gregs.cs; |
|
435 |
regs[REG_INDEX(RSP)] = gregs.rsp; |
|
436 |
regs[REG_INDEX(SS)] = gregs.ss; |
|
437 |
regs[REG_INDEX(FSBASE)] = gregs.fs_base; |
|
438 |
regs[REG_INDEX(GSBASE)] = gregs.gs_base; |
|
439 |
regs[REG_INDEX(DS)] = gregs.ds; |
|
440 |
regs[REG_INDEX(ES)] = gregs.es; |
|
441 |
regs[REG_INDEX(FS)] = gregs.fs; |
|
442 |
regs[REG_INDEX(GS)] = gregs.gs; |
|
443 |
||
444 |
#endif /* amd64 */ |
|
445 |
||
446 |
#if defined(sparc) || defined(sparcv9) |
|
447 |
||
448 |
#define REG_INDEX(reg) sun_jvm_hotspot_debugger_sparc_SPARCThreadContext_##reg |
|
449 |
||
450 |
#ifdef _LP64 |
|
451 |
regs[REG_INDEX(R_PSR)] = gregs.tstate; |
|
452 |
regs[REG_INDEX(R_PC)] = gregs.tpc; |
|
453 |
regs[REG_INDEX(R_nPC)] = gregs.tnpc; |
|
454 |
regs[REG_INDEX(R_Y)] = gregs.y; |
|
455 |
#else |
|
456 |
regs[REG_INDEX(R_PSR)] = gregs.psr; |
|
457 |
regs[REG_INDEX(R_PC)] = gregs.pc; |
|
458 |
regs[REG_INDEX(R_nPC)] = gregs.npc; |
|
459 |
regs[REG_INDEX(R_Y)] = gregs.y; |
|
460 |
#endif |
|
461 |
regs[REG_INDEX(R_G0)] = 0 ; |
|
462 |
regs[REG_INDEX(R_G1)] = gregs.u_regs[0]; |
|
463 |
regs[REG_INDEX(R_G2)] = gregs.u_regs[1]; |
|
464 |
regs[REG_INDEX(R_G3)] = gregs.u_regs[2]; |
|
465 |
regs[REG_INDEX(R_G4)] = gregs.u_regs[3]; |
|
466 |
regs[REG_INDEX(R_G5)] = gregs.u_regs[4]; |
|
467 |
regs[REG_INDEX(R_G6)] = gregs.u_regs[5]; |
|
468 |
regs[REG_INDEX(R_G7)] = gregs.u_regs[6]; |
|
469 |
regs[REG_INDEX(R_O0)] = gregs.u_regs[7]; |
|
470 |
regs[REG_INDEX(R_O1)] = gregs.u_regs[8]; |
|
471 |
regs[REG_INDEX(R_O2)] = gregs.u_regs[ 9]; |
|
472 |
regs[REG_INDEX(R_O3)] = gregs.u_regs[10]; |
|
473 |
regs[REG_INDEX(R_O4)] = gregs.u_regs[11]; |
|
474 |
regs[REG_INDEX(R_O5)] = gregs.u_regs[12]; |
|
475 |
regs[REG_INDEX(R_O6)] = gregs.u_regs[13]; |
|
476 |
regs[REG_INDEX(R_O7)] = gregs.u_regs[14]; |
|
477 |
#endif /* sparc */ |
|
478 |
||
29180 | 479 |
#if defined(aarch64) |
480 |
||
481 |
#define REG_INDEX(reg) sun_jvm_hotspot_debugger_aarch64_AARCH64ThreadContext_##reg |
|
482 |
||
31399 | 483 |
{ |
484 |
int i; |
|
485 |
for (i = 0; i < 31; i++) |
|
486 |
regs[i] = gregs.regs[i]; |
|
487 |
regs[REG_INDEX(SP)] = gregs.sp; |
|
488 |
regs[REG_INDEX(PC)] = gregs.pc; |
|
489 |
} |
|
29180 | 490 |
#endif /* aarch64 */ |
491 |
||
35075
ca79cbf3f106
8073139: PPC64: User-visible arch directory and os.arch value on ppc64le cause issues with Java tooling
asmundak
parents:
35049
diff
changeset
|
492 |
#if defined(ppc64) || defined(ppc64le) |
28369 | 493 |
#define REG_INDEX(reg) sun_jvm_hotspot_debugger_ppc64_PPC64ThreadContext_##reg |
494 |
||
495 |
regs[REG_INDEX(LR)] = gregs.link; |
|
496 |
regs[REG_INDEX(NIP)] = gregs.nip; |
|
497 |
regs[REG_INDEX(R0)] = gregs.gpr[0]; |
|
498 |
regs[REG_INDEX(R1)] = gregs.gpr[1]; |
|
499 |
regs[REG_INDEX(R2)] = gregs.gpr[2]; |
|
500 |
regs[REG_INDEX(R3)] = gregs.gpr[3]; |
|
501 |
regs[REG_INDEX(R4)] = gregs.gpr[4]; |
|
502 |
regs[REG_INDEX(R5)] = gregs.gpr[5]; |
|
503 |
regs[REG_INDEX(R6)] = gregs.gpr[6]; |
|
504 |
regs[REG_INDEX(R7)] = gregs.gpr[7]; |
|
505 |
regs[REG_INDEX(R8)] = gregs.gpr[8]; |
|
506 |
regs[REG_INDEX(R9)] = gregs.gpr[9]; |
|
507 |
regs[REG_INDEX(R10)] = gregs.gpr[10]; |
|
508 |
regs[REG_INDEX(R11)] = gregs.gpr[11]; |
|
509 |
regs[REG_INDEX(R12)] = gregs.gpr[12]; |
|
510 |
regs[REG_INDEX(R13)] = gregs.gpr[13]; |
|
511 |
regs[REG_INDEX(R14)] = gregs.gpr[14]; |
|
512 |
regs[REG_INDEX(R15)] = gregs.gpr[15]; |
|
513 |
regs[REG_INDEX(R16)] = gregs.gpr[16]; |
|
514 |
regs[REG_INDEX(R17)] = gregs.gpr[17]; |
|
515 |
regs[REG_INDEX(R18)] = gregs.gpr[18]; |
|
516 |
regs[REG_INDEX(R19)] = gregs.gpr[19]; |
|
517 |
regs[REG_INDEX(R20)] = gregs.gpr[20]; |
|
518 |
regs[REG_INDEX(R21)] = gregs.gpr[21]; |
|
519 |
regs[REG_INDEX(R22)] = gregs.gpr[22]; |
|
520 |
regs[REG_INDEX(R23)] = gregs.gpr[23]; |
|
521 |
regs[REG_INDEX(R24)] = gregs.gpr[24]; |
|
522 |
regs[REG_INDEX(R25)] = gregs.gpr[25]; |
|
523 |
regs[REG_INDEX(R26)] = gregs.gpr[26]; |
|
524 |
regs[REG_INDEX(R27)] = gregs.gpr[27]; |
|
525 |
regs[REG_INDEX(R28)] = gregs.gpr[28]; |
|
526 |
regs[REG_INDEX(R29)] = gregs.gpr[29]; |
|
527 |
regs[REG_INDEX(R30)] = gregs.gpr[30]; |
|
528 |
regs[REG_INDEX(R31)] = gregs.gpr[31]; |
|
529 |
||
530 |
#endif |
|
1 | 531 |
|
532 |
(*env)->ReleaseLongArrayElements(env, array, regs, JNI_COMMIT); |
|
533 |
return array; |
|
534 |
} |
|
13529
dc25e69fd16d
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
5547
diff
changeset
|
535 |
#endif |