author | jgeorge |
Thu, 26 Apr 2018 12:25:36 +0530 | |
changeset 49896 | ec2dd30adbc1 |
parent 49440 | 396ea30afbd5 |
child 50268 | 5f4f5b52ee39 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
49896
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
2 |
* Copyright (c) 2002, 2018, 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:
3592
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3592
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:
3592
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
#include "salibproc.h" |
|
26 |
#include "sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal.h" |
|
27 |
#include <thread_db.h> |
|
28 |
#include <strings.h> |
|
29 |
#include <limits.h> |
|
30 |
#include <demangle.h> |
|
31 |
#include <stdarg.h> |
|
32 |
#include <stdlib.h> |
|
33 |
#include <errno.h> |
|
34 |
||
35 |
#define CHECK_EXCEPTION_(value) if(env->ExceptionOccurred()) { return value; } |
|
36 |
#define CHECK_EXCEPTION if(env->ExceptionOccurred()) { return;} |
|
37 |
#define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throwNewDebuggerException(env, str); return value; } |
|
38 |
#define THROW_NEW_DEBUGGER_EXCEPTION(str) { throwNewDebuggerException(env, str); return;} |
|
39 |
||
40 |
#define SYMBOL_BUF_SIZE 256 |
|
41 |
#define ERR_MSG_SIZE (PATH_MAX + 256) |
|
42 |
||
9407
c985006c2940
7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents:
5547
diff
changeset
|
43 |
// debug modes |
1 | 44 |
static int _libsaproc_debug = 0; |
45 |
||
46 |
static void print_debug(const char* format,...) { |
|
47 |
if (_libsaproc_debug) { |
|
48 |
va_list alist; |
|
49 |
||
50 |
va_start(alist, format); |
|
51 |
fputs("libsaproc DEBUG: ", stderr); |
|
52 |
vfprintf(stderr, format, alist); |
|
53 |
va_end(alist); |
|
54 |
} |
|
55 |
} |
|
56 |
||
57 |
struct Debugger { |
|
58 |
JNIEnv* env; |
|
59 |
jobject this_obj; |
|
60 |
}; |
|
61 |
||
62 |
struct DebuggerWithObject : Debugger { |
|
63 |
jobject obj; |
|
64 |
}; |
|
65 |
||
66 |
struct DebuggerWith2Objects : DebuggerWithObject { |
|
67 |
jobject obj2; |
|
68 |
}; |
|
69 |
||
70 |
/* |
|
71 |
* Portions of user thread level detail gathering code is from pstack source |
|
72 |
* code. See pstack.c in Solaris 2.8 user commands source code. |
|
73 |
*/ |
|
74 |
||
75 |
static void throwNewDebuggerException(JNIEnv* env, const char* errMsg) { |
|
26410
a34c8032e674
8031583: warnings from b03 for hotspot/agent/src/os/solaris/proc: JNI exception pending
dsamersoff
parents:
25945
diff
changeset
|
76 |
jclass clazz = env->FindClass("sun/jvm/hotspot/debugger/DebuggerException"); |
a34c8032e674
8031583: warnings from b03 for hotspot/agent/src/os/solaris/proc: JNI exception pending
dsamersoff
parents:
25945
diff
changeset
|
77 |
CHECK_EXCEPTION; |
a34c8032e674
8031583: warnings from b03 for hotspot/agent/src/os/solaris/proc: JNI exception pending
dsamersoff
parents:
25945
diff
changeset
|
78 |
env->ThrowNew(clazz, errMsg); |
1 | 79 |
} |
80 |
||
81 |
// JNI ids for some fields, methods |
|
82 |
||
83 |
// libproc handler pointer |
|
84 |
static jfieldID p_ps_prochandle_ID = 0; |
|
85 |
||
86 |
// libthread.so dlopen handle, thread agent ptr and function pointers |
|
87 |
static jfieldID libthread_db_handle_ID = 0; |
|
88 |
static jfieldID p_td_thragent_t_ID = 0; |
|
89 |
static jfieldID p_td_init_ID = 0; |
|
90 |
static jfieldID p_td_ta_new_ID = 0; |
|
91 |
static jfieldID p_td_ta_delete_ID = 0; |
|
92 |
static jfieldID p_td_ta_thr_iter_ID = 0; |
|
93 |
static jfieldID p_td_thr_get_info_ID = 0; |
|
94 |
static jfieldID p_td_ta_map_id2thr_ID = 0; |
|
95 |
static jfieldID p_td_thr_getgregs_ID = 0; |
|
96 |
||
97 |
// reg index fields |
|
98 |
static jfieldID pcRegIndex_ID = 0; |
|
99 |
static jfieldID fpRegIndex_ID = 0; |
|
100 |
||
101 |
// part of the class sharing workaround |
|
102 |
static jfieldID classes_jsa_fd_ID = 0; |
|
103 |
static jfieldID p_file_map_header_ID = 0; |
|
104 |
||
105 |
// method ids |
|
106 |
||
107 |
static jmethodID getThreadForThreadId_ID = 0; |
|
108 |
static jmethodID createSenderFrame_ID = 0; |
|
109 |
static jmethodID createLoadObject_ID = 0; |
|
110 |
static jmethodID createClosestSymbol_ID = 0; |
|
111 |
static jmethodID listAdd_ID = 0; |
|
112 |
||
113 |
/* |
|
114 |
* Functions we need from libthread_db |
|
115 |
*/ |
|
116 |
typedef td_err_e |
|
117 |
(*p_td_init_t)(void); |
|
118 |
typedef td_err_e |
|
119 |
(*p_td_ta_new_t)(void *, td_thragent_t **); |
|
120 |
typedef td_err_e |
|
121 |
(*p_td_ta_delete_t)(td_thragent_t *); |
|
122 |
typedef td_err_e |
|
123 |
(*p_td_ta_thr_iter_t)(const td_thragent_t *, td_thr_iter_f *, void *, |
|
124 |
td_thr_state_e, int, sigset_t *, unsigned); |
|
125 |
typedef td_err_e |
|
126 |
(*p_td_thr_get_info_t)(const td_thrhandle_t *, td_thrinfo_t *); |
|
127 |
typedef td_err_e |
|
128 |
(*p_td_ta_map_id2thr_t)(const td_thragent_t *, thread_t, td_thrhandle_t *); |
|
129 |
typedef td_err_e |
|
130 |
(*p_td_thr_getgregs_t)(const td_thrhandle_t *, prgregset_t); |
|
131 |
||
132 |
static void |
|
133 |
clear_libthread_db_ptrs(JNIEnv* env, jobject this_obj) { |
|
134 |
// release libthread_db agent, if we had created |
|
135 |
p_td_ta_delete_t p_td_ta_delete = 0; |
|
136 |
p_td_ta_delete = (p_td_ta_delete_t) env->GetLongField(this_obj, p_td_ta_delete_ID); |
|
137 |
||
138 |
td_thragent_t *p_td_thragent_t = 0; |
|
139 |
p_td_thragent_t = (td_thragent_t*) env->GetLongField(this_obj, p_td_thragent_t_ID); |
|
140 |
if (p_td_thragent_t != 0 && p_td_ta_delete != 0) { |
|
141 |
p_td_ta_delete(p_td_thragent_t); |
|
142 |
} |
|
143 |
||
144 |
// dlclose libthread_db.so |
|
145 |
void* libthread_db_handle = (void*) env->GetLongField(this_obj, libthread_db_handle_ID); |
|
146 |
if (libthread_db_handle != 0) { |
|
147 |
dlclose(libthread_db_handle); |
|
148 |
} |
|
149 |
||
150 |
env->SetLongField(this_obj, libthread_db_handle_ID, (jlong)0); |
|
151 |
env->SetLongField(this_obj, p_td_init_ID, (jlong)0); |
|
152 |
env->SetLongField(this_obj, p_td_ta_new_ID, (jlong)0); |
|
153 |
env->SetLongField(this_obj, p_td_ta_delete_ID, (jlong)0); |
|
154 |
env->SetLongField(this_obj, p_td_ta_thr_iter_ID, (jlong)0); |
|
155 |
env->SetLongField(this_obj, p_td_thr_get_info_ID, (jlong)0); |
|
156 |
env->SetLongField(this_obj, p_td_ta_map_id2thr_ID, (jlong)0); |
|
157 |
env->SetLongField(this_obj, p_td_thr_getgregs_ID, (jlong)0); |
|
158 |
} |
|
159 |
||
160 |
||
161 |
static void detach_internal(JNIEnv* env, jobject this_obj) { |
|
162 |
// clear libthread_db stuff |
|
163 |
clear_libthread_db_ptrs(env, this_obj); |
|
164 |
||
165 |
// release ptr to ps_prochandle |
|
166 |
jlong p_ps_prochandle; |
|
167 |
p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID); |
|
168 |
if (p_ps_prochandle != 0L) { |
|
169 |
Prelease((struct ps_prochandle*) p_ps_prochandle, PRELEASE_CLEAR); |
|
170 |
} |
|
171 |
||
172 |
// part of the class sharing workaround |
|
173 |
int classes_jsa_fd = env->GetIntField(this_obj, classes_jsa_fd_ID); |
|
174 |
if (classes_jsa_fd != -1) { |
|
175 |
close(classes_jsa_fd); |
|
176 |
struct FileMapHeader* pheader = (struct FileMapHeader*) env->GetLongField(this_obj, p_file_map_header_ID); |
|
177 |
if (pheader != NULL) { |
|
178 |
free(pheader); |
|
179 |
} |
|
180 |
} |
|
181 |
} |
|
182 |
||
183 |
// Is it okay to ignore libthread_db failure? Set env var to ignore |
|
184 |
// libthread_db failure. You can still debug, but will miss threads |
|
185 |
// related functionality. |
|
186 |
static bool sa_ignore_threaddb = (getenv("SA_IGNORE_THREADDB") != 0); |
|
187 |
||
188 |
#define HANDLE_THREADDB_FAILURE(msg) \ |
|
189 |
if (sa_ignore_threaddb) { \ |
|
190 |
printf("libsaproc WARNING: %s\n", msg); \ |
|
191 |
return; \ |
|
192 |
} else { \ |
|
193 |
THROW_NEW_DEBUGGER_EXCEPTION(msg); \ |
|
194 |
} |
|
195 |
||
196 |
#define HANDLE_THREADDB_FAILURE_(msg, ret) \ |
|
197 |
if (sa_ignore_threaddb) { \ |
|
198 |
printf("libsaproc WARNING: %s\n", msg); \ |
|
199 |
return ret; \ |
|
200 |
} else { \ |
|
201 |
THROW_NEW_DEBUGGER_EXCEPTION_(msg, ret); \ |
|
202 |
} |
|
203 |
||
204 |
static const char * alt_root = NULL; |
|
205 |
static int alt_root_len = -1; |
|
206 |
||
207 |
#define SA_ALTROOT "SA_ALTROOT" |
|
208 |
||
209 |
static void init_alt_root() { |
|
210 |
if (alt_root_len == -1) { |
|
211 |
alt_root = getenv(SA_ALTROOT); |
|
212 |
if (alt_root) |
|
213 |
alt_root_len = strlen(alt_root); |
|
214 |
else |
|
215 |
alt_root_len = 0; |
|
216 |
} |
|
217 |
} |
|
218 |
||
3592
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
219 |
// This function is a complete substitute for the open system call |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
220 |
// since it's also used to override open calls from libproc to |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
221 |
// implement as a pathmap style facility for the SA. If libproc |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
222 |
// starts using other interfaces then this might have to extended to |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
223 |
// cover other calls. |
49440 | 224 |
extern "C" JNIEXPORT int JNICALL |
225 |
libsaproc_open(const char * name, int oflag, ...) { |
|
3592
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
226 |
if (oflag == O_RDONLY) { |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
227 |
init_alt_root(); |
1 | 228 |
|
3592
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
229 |
if (_libsaproc_debug) { |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
230 |
printf("libsaproc DEBUG: libsaproc_open %s\n", name); |
1 | 231 |
} |
232 |
||
3592
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
233 |
if (alt_root_len > 0) { |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
234 |
int fd = -1; |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
235 |
char alt_path[PATH_MAX+1]; |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
236 |
|
1 | 237 |
strcpy(alt_path, alt_root); |
3592
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
238 |
strcat(alt_path, name); |
1 | 239 |
fd = open(alt_path, O_RDONLY); |
240 |
if (fd >= 0) { |
|
241 |
if (_libsaproc_debug) { |
|
3592
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
242 |
printf("libsaproc DEBUG: libsaproc_open substituted %s\n", alt_path); |
1 | 243 |
} |
244 |
return fd; |
|
245 |
} |
|
3592
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
246 |
|
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
247 |
if (strrchr(name, '/')) { |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
248 |
strcpy(alt_path, alt_root); |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
249 |
strcat(alt_path, strrchr(name, '/')); |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
250 |
fd = open(alt_path, O_RDONLY); |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
251 |
if (fd >= 0) { |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
252 |
if (_libsaproc_debug) { |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
253 |
printf("libsaproc DEBUG: libsaproc_open substituted %s\n", alt_path); |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
254 |
} |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
255 |
return fd; |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
256 |
} |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
257 |
} |
1 | 258 |
} |
259 |
} |
|
3592
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
260 |
|
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
261 |
{ |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
262 |
mode_t mode; |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
263 |
va_list ap; |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
264 |
va_start(ap, oflag); |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
265 |
mode = va_arg(ap, mode_t); |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
266 |
va_end(ap); |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
267 |
|
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
268 |
return open(name, oflag, mode); |
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
269 |
} |
1 | 270 |
} |
271 |
||
272 |
||
273 |
static void * pathmap_dlopen(const char * name, int mode) { |
|
274 |
init_alt_root(); |
|
275 |
||
276 |
if (_libsaproc_debug) { |
|
277 |
printf("libsaproc DEBUG: pathmap_dlopen %s\n", name); |
|
278 |
} |
|
279 |
||
280 |
void * handle = NULL; |
|
281 |
if (alt_root_len > 0) { |
|
282 |
char alt_path[PATH_MAX+1]; |
|
283 |
strcpy(alt_path, alt_root); |
|
284 |
strcat(alt_path, name); |
|
285 |
handle = dlopen(alt_path, mode); |
|
286 |
if (_libsaproc_debug && handle) { |
|
287 |
printf("libsaproc DEBUG: pathmap_dlopen substituted %s\n", alt_path); |
|
288 |
} |
|
289 |
||
290 |
if (handle == NULL && strrchr(name, '/')) { |
|
291 |
strcpy(alt_path, alt_root); |
|
292 |
strcat(alt_path, strrchr(name, '/')); |
|
293 |
handle = dlopen(alt_path, mode); |
|
294 |
if (_libsaproc_debug && handle) { |
|
295 |
printf("libsaproc DEBUG: pathmap_dlopen substituted %s\n", alt_path); |
|
296 |
} |
|
297 |
} |
|
298 |
} |
|
299 |
if (handle == NULL) { |
|
300 |
handle = dlopen(name, mode); |
|
301 |
} |
|
302 |
if (_libsaproc_debug) { |
|
25945
cb5dcc388aff
8049049: Unportable format string argument mismatch in hotspot/agent/src/os/solaris/proc/saproc.cpp
dsamersoff
parents:
25901
diff
changeset
|
303 |
printf("libsaproc DEBUG: pathmap_dlopen %s return 0x%lx\n", name, (unsigned long) handle); |
1 | 304 |
} |
305 |
return handle; |
|
306 |
} |
|
307 |
||
308 |
// libproc and libthread_db callback functions |
|
309 |
||
310 |
extern "C" { |
|
311 |
||
312 |
static int |
|
313 |
init_libthread_db_ptrs(void *cd, const prmap_t *pmp, const char *object_name) { |
|
314 |
Debugger* dbg = (Debugger*) cd; |
|
315 |
JNIEnv* env = dbg->env; |
|
316 |
jobject this_obj = dbg->this_obj; |
|
317 |
struct ps_prochandle* ph = (struct ps_prochandle*) env->GetLongField(this_obj, p_ps_prochandle_ID); |
|
318 |
||
319 |
char *s1 = 0, *s2 = 0; |
|
320 |
char libthread_db[PATH_MAX]; |
|
321 |
||
322 |
if (strstr(object_name, "/libthread.so.") == NULL) |
|
323 |
return (0); |
|
324 |
||
325 |
/* |
|
326 |
* We found a libthread. |
|
327 |
* dlopen() the matching libthread_db and get the thread agent handle. |
|
328 |
*/ |
|
329 |
if (Pstatus(ph)->pr_dmodel == PR_MODEL_NATIVE) { |
|
330 |
(void) strcpy(libthread_db, object_name); |
|
331 |
s1 = (char*) strstr(object_name, ".so."); |
|
332 |
s2 = (char*) strstr(libthread_db, ".so."); |
|
333 |
(void) strcpy(s2, "_db"); |
|
334 |
s2 += 3; |
|
335 |
(void) strcpy(s2, s1); |
|
336 |
} else { |
|
337 |
#ifdef _LP64 |
|
338 |
/* |
|
339 |
* The victim process is 32-bit, we are 64-bit. |
|
340 |
* We have to find the 64-bit version of libthread_db |
|
341 |
* that matches the victim's 32-bit version of libthread. |
|
342 |
*/ |
|
343 |
(void) strcpy(libthread_db, object_name); |
|
344 |
s1 = (char*) strstr(object_name, "/libthread.so."); |
|
345 |
s2 = (char*) strstr(libthread_db, "/libthread.so."); |
|
346 |
(void) strcpy(s2, "/64"); |
|
347 |
s2 += 3; |
|
348 |
(void) strcpy(s2, s1); |
|
349 |
s1 = (char*) strstr(s1, ".so."); |
|
350 |
s2 = (char*) strstr(s2, ".so."); |
|
351 |
(void) strcpy(s2, "_db"); |
|
352 |
s2 += 3; |
|
353 |
(void) strcpy(s2, s1); |
|
354 |
#else |
|
355 |
return (0); |
|
356 |
#endif /* _LP64 */ |
|
357 |
} |
|
358 |
||
359 |
void* libthread_db_handle = 0; |
|
360 |
if ((libthread_db_handle = pathmap_dlopen(libthread_db, RTLD_LAZY|RTLD_LOCAL)) == NULL) { |
|
361 |
char errMsg[PATH_MAX + 256]; |
|
362 |
sprintf(errMsg, "Can't load %s!", libthread_db); |
|
363 |
HANDLE_THREADDB_FAILURE_(errMsg, 0); |
|
364 |
} |
|
365 |
env->SetLongField(this_obj, libthread_db_handle_ID, (jlong)(uintptr_t)libthread_db_handle); |
|
366 |
||
367 |
void* tmpPtr = 0; |
|
368 |
tmpPtr = dlsym(libthread_db_handle, "td_init"); |
|
369 |
if (tmpPtr == 0) { |
|
370 |
HANDLE_THREADDB_FAILURE_("dlsym failed on td_init!", 0); |
|
371 |
} |
|
372 |
env->SetLongField(this_obj, p_td_init_ID, (jlong)(uintptr_t) tmpPtr); |
|
373 |
||
374 |
tmpPtr =dlsym(libthread_db_handle, "td_ta_new"); |
|
375 |
if (tmpPtr == 0) { |
|
376 |
HANDLE_THREADDB_FAILURE_("dlsym failed on td_ta_new!", 0); |
|
377 |
} |
|
378 |
env->SetLongField(this_obj, p_td_ta_new_ID, (jlong)(uintptr_t) tmpPtr); |
|
379 |
||
380 |
tmpPtr = dlsym(libthread_db_handle, "td_ta_delete"); |
|
381 |
if (tmpPtr == 0) { |
|
382 |
HANDLE_THREADDB_FAILURE_("dlsym failed on td_ta_delete!", 0); |
|
383 |
} |
|
384 |
env->SetLongField(this_obj, p_td_ta_delete_ID, (jlong)(uintptr_t) tmpPtr); |
|
385 |
||
386 |
tmpPtr = dlsym(libthread_db_handle, "td_ta_thr_iter"); |
|
387 |
if (tmpPtr == 0) { |
|
388 |
HANDLE_THREADDB_FAILURE_("dlsym failed on td_ta_thr_iter!", 0); |
|
389 |
} |
|
390 |
env->SetLongField(this_obj, p_td_ta_thr_iter_ID, (jlong)(uintptr_t) tmpPtr); |
|
391 |
||
392 |
tmpPtr = dlsym(libthread_db_handle, "td_thr_get_info"); |
|
393 |
if (tmpPtr == 0) { |
|
394 |
HANDLE_THREADDB_FAILURE_("dlsym failed on td_thr_get_info!", 0); |
|
395 |
} |
|
396 |
env->SetLongField(this_obj, p_td_thr_get_info_ID, (jlong)(uintptr_t) tmpPtr); |
|
397 |
||
398 |
tmpPtr = dlsym(libthread_db_handle, "td_ta_map_id2thr"); |
|
399 |
if (tmpPtr == 0) { |
|
400 |
HANDLE_THREADDB_FAILURE_("dlsym failed on td_ta_map_id2thr!", 0); |
|
401 |
} |
|
402 |
env->SetLongField(this_obj, p_td_ta_map_id2thr_ID, (jlong)(uintptr_t) tmpPtr); |
|
403 |
||
404 |
tmpPtr = dlsym(libthread_db_handle, "td_thr_getgregs"); |
|
405 |
if (tmpPtr == 0) { |
|
406 |
HANDLE_THREADDB_FAILURE_("dlsym failed on td_thr_getgregs!", 0); |
|
407 |
} |
|
408 |
env->SetLongField(this_obj, p_td_thr_getgregs_ID, (jlong)(uintptr_t) tmpPtr); |
|
409 |
||
410 |
return 1; |
|
411 |
} |
|
412 |
||
413 |
static int |
|
414 |
fill_thread_list(const td_thrhandle_t *p_td_thragent_t, void* cd) { |
|
415 |
DebuggerWithObject* dbgo = (DebuggerWithObject*) cd; |
|
416 |
JNIEnv* env = dbgo->env; |
|
417 |
jobject this_obj = dbgo->this_obj; |
|
418 |
jobject list = dbgo->obj; |
|
419 |
||
420 |
td_thrinfo_t thrinfo; |
|
421 |
p_td_thr_get_info_t p_td_thr_get_info = (p_td_thr_get_info_t) env->GetLongField(this_obj, p_td_thr_get_info_ID); |
|
422 |
||
423 |
if (p_td_thr_get_info(p_td_thragent_t, &thrinfo) != TD_OK) |
|
424 |
return (0); |
|
425 |
||
426 |
jobject threadProxy = env->CallObjectMethod(this_obj, getThreadForThreadId_ID, (jlong)(uintptr_t) thrinfo.ti_tid); |
|
427 |
CHECK_EXCEPTION_(1); |
|
428 |
env->CallBooleanMethod(list, listAdd_ID, threadProxy); |
|
429 |
CHECK_EXCEPTION_(1); |
|
430 |
return 0; |
|
431 |
} |
|
432 |
||
433 |
static int |
|
434 |
fill_load_object_list(void *cd, const prmap_t* pmp, const char* obj_name) { |
|
435 |
||
436 |
if (obj_name) { |
|
437 |
DebuggerWithObject* dbgo = (DebuggerWithObject*) cd; |
|
438 |
JNIEnv* env = dbgo->env; |
|
439 |
jobject this_obj = dbgo->this_obj; |
|
440 |
jobject list = dbgo->obj; |
|
441 |
||
442 |
jstring objectName = env->NewStringUTF(obj_name); |
|
443 |
CHECK_EXCEPTION_(1); |
|
444 |
||
445 |
jlong mapSize = (jlong) pmp->pr_size; |
|
446 |
jobject sharedObject = env->CallObjectMethod(this_obj, createLoadObject_ID, |
|
447 |
objectName, mapSize, (jlong)(uintptr_t)pmp->pr_vaddr); |
|
448 |
CHECK_EXCEPTION_(1); |
|
449 |
env->CallBooleanMethod(list, listAdd_ID, sharedObject); |
|
450 |
CHECK_EXCEPTION_(1); |
|
451 |
} |
|
452 |
||
453 |
return 0; |
|
454 |
} |
|
455 |
||
9407
c985006c2940
7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents:
5547
diff
changeset
|
456 |
// Pstack_iter() proc_stack_f callback prior to Nevada-B159 |
1 | 457 |
static int |
458 |
fill_cframe_list(void *cd, const prgregset_t regs, uint_t argc, const long *argv) { |
|
459 |
DebuggerWith2Objects* dbgo2 = (DebuggerWith2Objects*) cd; |
|
460 |
JNIEnv* env = dbgo2->env; |
|
461 |
jobject this_obj = dbgo2->this_obj; |
|
462 |
jobject curFrame = dbgo2->obj2; |
|
463 |
||
464 |
jint pcRegIndex = env->GetIntField(this_obj, pcRegIndex_ID); |
|
465 |
jint fpRegIndex = env->GetIntField(this_obj, fpRegIndex_ID); |
|
466 |
||
467 |
jlong pc = (jlong) (uintptr_t) regs[pcRegIndex]; |
|
468 |
jlong fp = (jlong) (uintptr_t) regs[fpRegIndex]; |
|
469 |
||
470 |
dbgo2->obj2 = env->CallObjectMethod(this_obj, createSenderFrame_ID, |
|
471 |
curFrame, pc, fp); |
|
472 |
CHECK_EXCEPTION_(1); |
|
473 |
if (dbgo2->obj == 0) { |
|
474 |
dbgo2->obj = dbgo2->obj2; |
|
475 |
} |
|
476 |
return 0; |
|
477 |
} |
|
478 |
||
9407
c985006c2940
7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents:
5547
diff
changeset
|
479 |
// Pstack_iter() proc_stack_f callback in Nevada-B159 or later |
c985006c2940
7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents:
5547
diff
changeset
|
480 |
/*ARGSUSED*/ |
c985006c2940
7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents:
5547
diff
changeset
|
481 |
static int |
c985006c2940
7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents:
5547
diff
changeset
|
482 |
wrapper_fill_cframe_list(void *cd, const prgregset_t regs, uint_t argc, |
c985006c2940
7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents:
5547
diff
changeset
|
483 |
const long *argv, int frame_flags, int sig) { |
c985006c2940
7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents:
5547
diff
changeset
|
484 |
return(fill_cframe_list(cd, regs, argc, argv)); |
c985006c2940
7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents:
5547
diff
changeset
|
485 |
} |
c985006c2940
7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents:
5547
diff
changeset
|
486 |
|
1 | 487 |
// part of the class sharing workaround |
488 |
||
489 |
// FIXME: !!HACK ALERT!! |
|
490 |
||
491 |
// The format of sharing achive file header is needed to read shared heap |
|
492 |
// file mappings. For now, I am hard coding portion of FileMapHeader here. |
|
493 |
// Refer to filemap.hpp. |
|
494 |
||
495 |
// FileMapHeader describes the shared space data in the file to be |
|
496 |
// mapped. This structure gets written to a file. It is not a class, so |
|
497 |
// that the compilers don't add any compiler-private data to it. |
|
498 |
||
49896
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
499 |
const int NUM_SHARED_MAPS = 9; |
1 | 500 |
|
501 |
// Refer to FileMapInfo::_current_version in filemap.hpp |
|
49896
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
502 |
const int CURRENT_ARCHIVE_VERSION = 3; |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
503 |
|
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
504 |
typedef unsigned char* address; |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
505 |
typedef uintptr_t uintx; |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
506 |
typedef intptr_t intx; |
1 | 507 |
|
508 |
struct FileMapHeader { |
|
49896
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
509 |
int _magic; // identify file type. |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
510 |
int _crc; // header crc checksum. |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
511 |
int _version; // (from enum, above.) |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
512 |
size_t _alignment; // how shared archive should be aligned |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
513 |
int _obj_alignment; // value of ObjectAlignmentInBytes |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
514 |
address _narrow_oop_base; // compressed oop encoding base |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
515 |
int _narrow_oop_shift; // compressed oop encoding shift |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
516 |
bool _compact_strings; // value of CompactStrings |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
517 |
uintx _max_heap_size; // java max heap size during dumping |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
518 |
int _narrow_oop_mode; // compressed oop encoding mode |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
519 |
int _narrow_klass_shift; // save narrow klass base and shift |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
520 |
address _narrow_klass_base; |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
521 |
char* _misc_data_patching_start; |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
522 |
char* _read_only_tables_start; |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
523 |
address _cds_i2i_entry_code_buffers; |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
524 |
size_t _cds_i2i_entry_code_buffers_size; |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
525 |
size_t _core_spaces_size; // number of bytes allocated by the core spaces |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
526 |
// (mc, md, ro, rw and od). |
1 | 527 |
|
528 |
||
49896
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
529 |
struct space_info { |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
530 |
int _crc; // crc checksum of the current space |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
531 |
size_t _file_offset; // sizeof(this) rounded to vm page size |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
532 |
union { |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
533 |
char* _base; // copy-on-write base address |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
534 |
intx _offset; // offset from the compressed oop encoding base, only used |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
535 |
// by archive heap space |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
536 |
} _addr; |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
537 |
size_t _used; // for setting space top on read |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
538 |
// 4991491 NOTICE These are C++ bool's in filemap.hpp and must match up with |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
539 |
// the C type matching the C++ bool type on any given platform. |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
540 |
// We assume the corresponding C type is char but licensees |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
541 |
// may need to adjust the type of these fields. |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
542 |
char _read_only; // read only space? |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
543 |
char _allow_exec; // executable code in space? |
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
544 |
} _space[NUM_SHARED_MAPS]; |
1 | 545 |
|
49896
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
546 |
// Ignore the rest of the FileMapHeader. We don't need those fields here. |
1 | 547 |
}; |
548 |
||
549 |
static bool |
|
1905
059ce1b8f69e
6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
swamyv
parents:
1
diff
changeset
|
550 |
read_jboolean(struct ps_prochandle* ph, psaddr_t addr, jboolean* pvalue) { |
059ce1b8f69e
6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
swamyv
parents:
1
diff
changeset
|
551 |
jboolean i; |
1 | 552 |
if (ps_pread(ph, addr, &i, sizeof(i)) == PS_OK) { |
553 |
*pvalue = i; |
|
554 |
return true; |
|
555 |
} else { |
|
556 |
return false; |
|
557 |
} |
|
558 |
} |
|
559 |
||
560 |
static bool |
|
561 |
read_pointer(struct ps_prochandle* ph, psaddr_t addr, uintptr_t* pvalue) { |
|
562 |
uintptr_t uip; |
|
563 |
if (ps_pread(ph, addr, &uip, sizeof(uip)) == PS_OK) { |
|
564 |
*pvalue = uip; |
|
565 |
return true; |
|
566 |
} else { |
|
567 |
return false; |
|
568 |
} |
|
569 |
} |
|
570 |
||
571 |
static bool |
|
572 |
read_string(struct ps_prochandle* ph, psaddr_t addr, char* buf, size_t size) { |
|
573 |
char ch = ' '; |
|
574 |
size_t i = 0; |
|
575 |
||
576 |
while (ch != '\0') { |
|
577 |
if (ps_pread(ph, addr, &ch, sizeof(ch)) != PS_OK) |
|
578 |
return false; |
|
579 |
||
580 |
if (i < size - 1) { |
|
581 |
buf[i] = ch; |
|
582 |
} else { // smaller buffer |
|
583 |
return false; |
|
584 |
} |
|
585 |
||
586 |
i++; addr++; |
|
587 |
} |
|
588 |
||
589 |
buf[i] = '\0'; |
|
590 |
return true; |
|
591 |
} |
|
592 |
||
593 |
#define USE_SHARED_SPACES_SYM "UseSharedSpaces" |
|
594 |
// mangled symbol name for Arguments::SharedArchivePath |
|
595 |
#define SHARED_ARCHIVE_PATH_SYM "__1cJArgumentsRSharedArchivePath_" |
|
596 |
||
597 |
static int |
|
598 |
init_classsharing_workaround(void *cd, const prmap_t* pmap, const char* obj_name) { |
|
599 |
Debugger* dbg = (Debugger*) cd; |
|
600 |
JNIEnv* env = dbg->env; |
|
601 |
jobject this_obj = dbg->this_obj; |
|
602 |
const char* jvm_name = 0; |
|
17310 | 603 |
if ((jvm_name = strstr(obj_name, "libjvm.so")) != NULL) { |
1 | 604 |
jvm_name = obj_name; |
605 |
} else { |
|
606 |
return 0; |
|
607 |
} |
|
608 |
||
609 |
struct ps_prochandle* ph = (struct ps_prochandle*) env->GetLongField(this_obj, p_ps_prochandle_ID); |
|
610 |
||
17310 | 611 |
// initialize classes.jsa file descriptor field. |
1 | 612 |
dbg->env->SetIntField(this_obj, classes_jsa_fd_ID, -1); |
613 |
||
614 |
// check whether class sharing is on by reading variable "UseSharedSpaces" |
|
615 |
psaddr_t useSharedSpacesAddr = 0; |
|
616 |
ps_pglobal_lookup(ph, jvm_name, USE_SHARED_SPACES_SYM, &useSharedSpacesAddr); |
|
617 |
if (useSharedSpacesAddr == 0) { |
|
618 |
THROW_NEW_DEBUGGER_EXCEPTION_("can't find 'UseSharedSpaces' flag\n", 1); |
|
619 |
} |
|
620 |
||
621 |
// read the value of the flag "UseSharedSpaces" |
|
1905
059ce1b8f69e
6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
swamyv
parents:
1
diff
changeset
|
622 |
// Since hotspot types are not available to build this library. So |
059ce1b8f69e
6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
swamyv
parents:
1
diff
changeset
|
623 |
// equivalent type "jboolean" is used to read the value of "UseSharedSpaces" |
059ce1b8f69e
6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
swamyv
parents:
1
diff
changeset
|
624 |
// which is same as hotspot type "bool". |
059ce1b8f69e
6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
swamyv
parents:
1
diff
changeset
|
625 |
jboolean value = 0; |
059ce1b8f69e
6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
swamyv
parents:
1
diff
changeset
|
626 |
if (read_jboolean(ph, useSharedSpacesAddr, &value) != true) { |
1 | 627 |
THROW_NEW_DEBUGGER_EXCEPTION_("can't read 'UseSharedSpaces' flag", 1); |
1905
059ce1b8f69e
6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
swamyv
parents:
1
diff
changeset
|
628 |
} else if ((int)value == 0) { |
1 | 629 |
print_debug("UseSharedSpaces is false, assuming -Xshare:off!\n"); |
630 |
return 1; |
|
631 |
} |
|
632 |
||
633 |
char classes_jsa[PATH_MAX]; |
|
634 |
psaddr_t sharedArchivePathAddrAddr = 0; |
|
635 |
ps_pglobal_lookup(ph, jvm_name, SHARED_ARCHIVE_PATH_SYM, &sharedArchivePathAddrAddr); |
|
636 |
if (sharedArchivePathAddrAddr == 0) { |
|
637 |
print_debug("can't find symbol 'Arguments::SharedArchivePath'\n"); |
|
638 |
THROW_NEW_DEBUGGER_EXCEPTION_("can't get shared archive path from debuggee", 1); |
|
639 |
} |
|
640 |
||
641 |
uintptr_t sharedArchivePathAddr = 0; |
|
642 |
if (read_pointer(ph, sharedArchivePathAddrAddr, &sharedArchivePathAddr) != true) { |
|
643 |
print_debug("can't find read pointer 'Arguments::SharedArchivePath'\n"); |
|
644 |
THROW_NEW_DEBUGGER_EXCEPTION_("can't get shared archive path from debuggee", 1); |
|
645 |
} |
|
646 |
||
647 |
if (read_string(ph, (psaddr_t)sharedArchivePathAddr, classes_jsa, sizeof(classes_jsa)) != true) { |
|
648 |
print_debug("can't find read 'Arguments::SharedArchivePath' value\n"); |
|
649 |
THROW_NEW_DEBUGGER_EXCEPTION_("can't get shared archive path from debuggee", 1); |
|
650 |
} |
|
651 |
||
652 |
print_debug("looking for %s\n", classes_jsa); |
|
653 |
||
17310 | 654 |
// open the classes.jsa |
3592
857575a0a200
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
2105
diff
changeset
|
655 |
int fd = libsaproc_open(classes_jsa, O_RDONLY); |
1 | 656 |
if (fd < 0) { |
657 |
char errMsg[ERR_MSG_SIZE]; |
|
658 |
sprintf(errMsg, "can't open shared archive file %s", classes_jsa); |
|
659 |
THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1); |
|
660 |
} else { |
|
661 |
print_debug("opened shared archive file %s\n", classes_jsa); |
|
662 |
} |
|
663 |
||
17310 | 664 |
// parse classes.jsa |
1 | 665 |
struct FileMapHeader* pheader = (struct FileMapHeader*) malloc(sizeof(struct FileMapHeader)); |
666 |
if (pheader == NULL) { |
|
667 |
close(fd); |
|
668 |
THROW_NEW_DEBUGGER_EXCEPTION_("can't allocate memory for shared file map header", 1); |
|
669 |
} |
|
670 |
||
671 |
memset(pheader, 0, sizeof(struct FileMapHeader)); |
|
672 |
// read FileMapHeader |
|
673 |
size_t n = read(fd, pheader, sizeof(struct FileMapHeader)); |
|
674 |
if (n != sizeof(struct FileMapHeader)) { |
|
675 |
char errMsg[ERR_MSG_SIZE]; |
|
676 |
sprintf(errMsg, "unable to read shared archive file map header from %s", classes_jsa); |
|
25901
34036ccd1364
8025667: Warning from b62 for hotspot.agent.src.os.solaris.proc: use after free
dsamersoff
parents:
22234
diff
changeset
|
677 |
close(fd); |
34036ccd1364
8025667: Warning from b62 for hotspot.agent.src.os.solaris.proc: use after free
dsamersoff
parents:
22234
diff
changeset
|
678 |
free(pheader); |
1 | 679 |
THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1); |
680 |
} |
|
681 |
||
682 |
// check file magic |
|
683 |
if (pheader->_magic != 0xf00baba2) { |
|
684 |
char errMsg[ERR_MSG_SIZE]; |
|
685 |
sprintf(errMsg, "%s has bad shared archive magic 0x%x, expecting 0xf00baba2", |
|
686 |
classes_jsa, pheader->_magic); |
|
25901
34036ccd1364
8025667: Warning from b62 for hotspot.agent.src.os.solaris.proc: use after free
dsamersoff
parents:
22234
diff
changeset
|
687 |
close(fd); |
34036ccd1364
8025667: Warning from b62 for hotspot.agent.src.os.solaris.proc: use after free
dsamersoff
parents:
22234
diff
changeset
|
688 |
free(pheader); |
1 | 689 |
THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1); |
690 |
} |
|
691 |
||
692 |
// check version |
|
693 |
if (pheader->_version != CURRENT_ARCHIVE_VERSION) { |
|
694 |
char errMsg[ERR_MSG_SIZE]; |
|
695 |
sprintf(errMsg, "%s has wrong shared archive version %d, expecting %d", |
|
696 |
classes_jsa, pheader->_version, CURRENT_ARCHIVE_VERSION); |
|
25901
34036ccd1364
8025667: Warning from b62 for hotspot.agent.src.os.solaris.proc: use after free
dsamersoff
parents:
22234
diff
changeset
|
697 |
close(fd); |
34036ccd1364
8025667: Warning from b62 for hotspot.agent.src.os.solaris.proc: use after free
dsamersoff
parents:
22234
diff
changeset
|
698 |
free(pheader); |
1 | 699 |
THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1); |
700 |
} |
|
701 |
||
702 |
if (_libsaproc_debug) { |
|
703 |
for (int m = 0; m < NUM_SHARED_MAPS; m++) { |
|
704 |
print_debug("shared file offset %d mapped at 0x%lx, size = %ld, read only? = %d\n", |
|
49896
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
705 |
pheader->_space[m]._file_offset, pheader->_space[m]._addr._base, |
1 | 706 |
pheader->_space[m]._used, pheader->_space[m]._read_only); |
707 |
} |
|
708 |
} |
|
709 |
||
710 |
// FIXME: For now, omitting other checks such as VM version etc. |
|
711 |
||
712 |
// store class archive file fd and map header in debugger object fields |
|
713 |
dbg->env->SetIntField(this_obj, classes_jsa_fd_ID, fd); |
|
714 |
dbg->env->SetLongField(this_obj, p_file_map_header_ID, (jlong)(uintptr_t) pheader); |
|
715 |
return 1; |
|
716 |
} |
|
717 |
||
718 |
} // extern "C" |
|
719 |
||
720 |
// error messages for proc_arg_grab failure codes. The messages are |
|
721 |
// modified versions of comments against corresponding #defines in |
|
722 |
// libproc.h. |
|
723 |
static const char* proc_arg_grab_errmsgs[] = { |
|
724 |
"", |
|
725 |
/* G_NOPROC */ "No such process", |
|
726 |
/* G_NOCORE */ "No such core file", |
|
727 |
/* G_NOPROCORCORE */ "No such process or core", |
|
728 |
/* G_NOEXEC */ "Cannot locate executable file", |
|
729 |
/* G_ZOMB */ "Zombie processs", |
|
730 |
/* G_PERM */ "No permission to attach", |
|
731 |
/* G_BUSY */ "Another process has already attached", |
|
732 |
/* G_SYS */ "System process - can not attach", |
|
733 |
/* G_SELF */ "Process is self - can't debug myself!", |
|
734 |
/* G_INTR */ "Interrupt received while grabbing", |
|
735 |
/* G_LP64 */ "debuggee is 64 bit, use java -d64 for debugger", |
|
736 |
/* G_FORMAT */ "File is not an ELF format core file - corrupted core?", |
|
737 |
/* G_ELF */ "Libelf error while parsing an ELF file", |
|
738 |
/* G_NOTE */ "Required PT_NOTE Phdr not present - corrupted core?", |
|
739 |
}; |
|
740 |
||
741 |
static void attach_internal(JNIEnv* env, jobject this_obj, jstring cmdLine, jboolean isProcess) { |
|
742 |
jboolean isCopy; |
|
743 |
int gcode; |
|
744 |
const char* cmdLine_cstr = env->GetStringUTFChars(cmdLine, &isCopy); |
|
745 |
CHECK_EXCEPTION; |
|
746 |
||
747 |
// some older versions of libproc.so crash when trying to attach 32 bit |
|
748 |
// debugger to 64 bit core file. check and throw error. |
|
749 |
#ifndef _LP64 |
|
750 |
atoi(cmdLine_cstr); |
|
751 |
if (errno) { |
|
752 |
// core file |
|
753 |
int core_fd; |
|
754 |
if ((core_fd = open64(cmdLine_cstr, O_RDONLY)) >= 0) { |
|
755 |
Elf32_Ehdr e32; |
|
756 |
if (pread64(core_fd, &e32, sizeof (e32), 0) == sizeof (e32) && |
|
757 |
memcmp(&e32.e_ident[EI_MAG0], ELFMAG, SELFMAG) == 0 && |
|
758 |
e32.e_type == ET_CORE && e32.e_ident[EI_CLASS] == ELFCLASS64) { |
|
759 |
close(core_fd); |
|
760 |
THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 64 bit, use java -d64 for debugger"); |
|
761 |
} |
|
762 |
close(core_fd); |
|
763 |
} |
|
764 |
// all other conditions are handled by libproc.so. |
|
765 |
} |
|
766 |
#endif |
|
767 |
||
768 |
// connect to process/core |
|
42035
10e6e31dc1aa
8164383: jhsdb dumps core on Solaris 12 when loading dumped core
dsamersoff
parents:
35217
diff
changeset
|
769 |
ps_prochandle_t* ph = proc_arg_grab(cmdLine_cstr, (isProcess? PR_ARG_PIDS : PR_ARG_CORES), PGRAB_FORCE, &gcode, NULL); |
10e6e31dc1aa
8164383: jhsdb dumps core on Solaris 12 when loading dumped core
dsamersoff
parents:
35217
diff
changeset
|
770 |
|
1 | 771 |
env->ReleaseStringUTFChars(cmdLine, cmdLine_cstr); |
772 |
if (! ph) { |
|
773 |
if (gcode > 0 && gcode < sizeof(proc_arg_grab_errmsgs)/sizeof(const char*)) { |
|
774 |
char errMsg[ERR_MSG_SIZE]; |
|
775 |
sprintf(errMsg, "Attach failed : %s", proc_arg_grab_errmsgs[gcode]); |
|
776 |
THROW_NEW_DEBUGGER_EXCEPTION(errMsg); |
|
777 |
} else { |
|
778 |
if (_libsaproc_debug && gcode == G_STRANGE) { |
|
779 |
perror("libsaproc DEBUG: "); |
|
780 |
} |
|
781 |
if (isProcess) { |
|
782 |
THROW_NEW_DEBUGGER_EXCEPTION("Not able to attach to process!"); |
|
783 |
} else { |
|
784 |
THROW_NEW_DEBUGGER_EXCEPTION("Not able to attach to core file!"); |
|
785 |
} |
|
786 |
} |
|
787 |
} |
|
788 |
||
789 |
// even though libproc.so supports 64 bit debugger and 32 bit debuggee, we don't |
|
790 |
// support such cross-bit-debugging. check for that combination and throw error. |
|
791 |
#ifdef _LP64 |
|
792 |
int data_model; |
|
793 |
if (ps_pdmodel(ph, &data_model) != PS_OK) { |
|
794 |
Prelease(ph, PRELEASE_CLEAR); |
|
795 |
THROW_NEW_DEBUGGER_EXCEPTION("can't determine debuggee data model (ILP32? or LP64?)"); |
|
796 |
} |
|
797 |
if (data_model == PR_MODEL_ILP32) { |
|
798 |
Prelease(ph, PRELEASE_CLEAR); |
|
799 |
THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 32 bit, use 32 bit java for debugger"); |
|
800 |
} |
|
801 |
#endif |
|
802 |
||
803 |
env->SetLongField(this_obj, p_ps_prochandle_ID, (jlong)(uintptr_t)ph); |
|
804 |
||
805 |
Debugger dbg; |
|
806 |
dbg.env = env; |
|
807 |
dbg.this_obj = this_obj; |
|
808 |
jthrowable exception = 0; |
|
809 |
if (! isProcess) { |
|
810 |
/* |
|
811 |
* With class sharing, shared perm. gen heap is allocated in with MAP_SHARED|PROT_READ. |
|
17310 | 812 |
* These pages are mapped from the file "classes.jsa". MAP_SHARED pages are not dumped |
813 |
* in Solaris core.To read shared heap pages, we have to read classes.jsa file. |
|
1 | 814 |
*/ |
815 |
Pobject_iter(ph, init_classsharing_workaround, &dbg); |
|
816 |
exception = env->ExceptionOccurred(); |
|
817 |
if (exception) { |
|
818 |
env->ExceptionClear(); |
|
819 |
detach_internal(env, this_obj); |
|
820 |
env->Throw(exception); |
|
821 |
return; |
|
822 |
} |
|
823 |
} |
|
824 |
||
825 |
/* |
|
826 |
* Iterate over the process mappings looking |
|
827 |
* for libthread and then dlopen the appropriate |
|
828 |
* libthread_db and get function pointers. |
|
829 |
*/ |
|
830 |
Pobject_iter(ph, init_libthread_db_ptrs, &dbg); |
|
831 |
exception = env->ExceptionOccurred(); |
|
832 |
if (exception) { |
|
833 |
env->ExceptionClear(); |
|
834 |
if (!sa_ignore_threaddb) { |
|
835 |
detach_internal(env, this_obj); |
|
836 |
env->Throw(exception); |
|
837 |
} |
|
838 |
return; |
|
839 |
} |
|
840 |
||
841 |
// init libthread_db and create thread_db agent |
|
842 |
p_td_init_t p_td_init = (p_td_init_t) env->GetLongField(this_obj, p_td_init_ID); |
|
843 |
if (p_td_init == 0) { |
|
844 |
if (!sa_ignore_threaddb) { |
|
845 |
detach_internal(env, this_obj); |
|
846 |
} |
|
847 |
HANDLE_THREADDB_FAILURE("Did not find libthread in target process/core!"); |
|
848 |
} |
|
849 |
||
850 |
if (p_td_init() != TD_OK) { |
|
851 |
if (!sa_ignore_threaddb) { |
|
852 |
detach_internal(env, this_obj); |
|
853 |
} |
|
854 |
HANDLE_THREADDB_FAILURE("Can't initialize thread_db!"); |
|
855 |
} |
|
856 |
||
857 |
p_td_ta_new_t p_td_ta_new = (p_td_ta_new_t) env->GetLongField(this_obj, p_td_ta_new_ID); |
|
858 |
||
859 |
td_thragent_t *p_td_thragent_t = 0; |
|
860 |
if (p_td_ta_new(ph, &p_td_thragent_t) != TD_OK) { |
|
861 |
if (!sa_ignore_threaddb) { |
|
862 |
detach_internal(env, this_obj); |
|
863 |
} |
|
864 |
HANDLE_THREADDB_FAILURE("Can't create thread_db agent!"); |
|
865 |
} |
|
866 |
env->SetLongField(this_obj, p_td_thragent_t_ID, (jlong)(uintptr_t) p_td_thragent_t); |
|
867 |
||
868 |
} |
|
869 |
||
870 |
/* |
|
871 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
872 |
* Method: attach0 |
|
873 |
* Signature: (Ljava/lang/String;)V |
|
874 |
* Description: process detach |
|
875 |
*/ |
|
876 |
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_attach0__Ljava_lang_String_2 |
|
877 |
(JNIEnv *env, jobject this_obj, jstring pid) { |
|
878 |
attach_internal(env, this_obj, pid, JNI_TRUE); |
|
879 |
} |
|
880 |
||
881 |
/* |
|
882 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
883 |
* Method: attach0 |
|
884 |
* Signature: (Ljava/lang/String;Ljava/lang/String;)V |
|
885 |
* Description: core file detach |
|
886 |
*/ |
|
887 |
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2 |
|
888 |
(JNIEnv *env, jobject this_obj, jstring executable, jstring corefile) { |
|
889 |
// ignore executable file name, libproc.so can detect a.out name anyway. |
|
890 |
attach_internal(env, this_obj, corefile, JNI_FALSE); |
|
891 |
} |
|
892 |
||
893 |
||
894 |
/* |
|
895 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
896 |
* Method: detach0 |
|
897 |
* Signature: ()V |
|
898 |
* Description: process/core file detach |
|
899 |
*/ |
|
900 |
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_detach0 |
|
901 |
(JNIEnv *env, jobject this_obj) { |
|
902 |
detach_internal(env, this_obj); |
|
903 |
} |
|
904 |
||
905 |
/* |
|
906 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
907 |
* Method: getRemoteProcessAddressSize0 |
|
908 |
* Signature: ()I |
|
909 |
* Description: get process/core address size |
|
910 |
*/ |
|
911 |
JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_getRemoteProcessAddressSize0 |
|
912 |
(JNIEnv *env, jobject this_obj) { |
|
913 |
jlong p_ps_prochandle; |
|
914 |
p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID); |
|
915 |
int data_model = PR_MODEL_ILP32; |
|
916 |
ps_pdmodel((struct ps_prochandle*) p_ps_prochandle, &data_model); |
|
917 |
print_debug("debuggee is %d bit\n", data_model == PR_MODEL_ILP32? 32 : 64); |
|
918 |
return (jint) data_model == PR_MODEL_ILP32? 32 : 64; |
|
919 |
} |
|
920 |
||
921 |
/* |
|
922 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
923 |
* Method: getPageSize0 |
|
924 |
* Signature: ()I |
|
925 |
* Description: get process/core page size |
|
926 |
*/ |
|
927 |
JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_getPageSize0 |
|
928 |
(JNIEnv *env, jobject this_obj) { |
|
929 |
||
930 |
/* |
|
931 |
We are not yet attached to a java process or core file. getPageSize is called from |
|
932 |
the constructor of ProcDebuggerLocal. The following won't work! |
|
933 |
||
934 |
jlong p_ps_prochandle; |
|
935 |
p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID); |
|
936 |
CHECK_EXCEPTION_(-1); |
|
937 |
struct ps_prochandle* prochandle = (struct ps_prochandle*) p_ps_prochandle; |
|
938 |
return (Pstate(prochandle) == PS_DEAD) ? Pgetauxval(prochandle, AT_PAGESZ) |
|
939 |
: getpagesize(); |
|
940 |
||
941 |
So even though core may have been generated with a different page size settings, for now |
|
942 |
call getpagesize. |
|
943 |
*/ |
|
944 |
||
945 |
return getpagesize(); |
|
946 |
} |
|
947 |
||
948 |
/* |
|
949 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
950 |
* Method: getThreadIntegerRegisterSet0 |
|
951 |
* Signature: (J)[J |
|
952 |
* Description: get gregset for a given thread specified by thread id |
|
953 |
*/ |
|
954 |
JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_getThreadIntegerRegisterSet0 |
|
955 |
(JNIEnv *env, jobject this_obj, jlong tid) { |
|
956 |
// map the thread id to thread handle |
|
957 |
p_td_ta_map_id2thr_t p_td_ta_map_id2thr = (p_td_ta_map_id2thr_t) env->GetLongField(this_obj, p_td_ta_map_id2thr_ID); |
|
958 |
||
959 |
td_thragent_t* p_td_thragent_t = (td_thragent_t*) env->GetLongField(this_obj, p_td_thragent_t_ID); |
|
960 |
if (p_td_thragent_t == 0) { |
|
961 |
return 0; |
|
962 |
} |
|
963 |
||
964 |
td_thrhandle_t thr_handle; |
|
965 |
if (p_td_ta_map_id2thr(p_td_thragent_t, (thread_t) tid, &thr_handle) != TD_OK) { |
|
966 |
THROW_NEW_DEBUGGER_EXCEPTION_("can't map thread id to thread handle!", 0); |
|
967 |
} |
|
968 |
||
969 |
p_td_thr_getgregs_t p_td_thr_getgregs = (p_td_thr_getgregs_t) env->GetLongField(this_obj, p_td_thr_getgregs_ID); |
|
970 |
prgregset_t gregs; |
|
971 |
p_td_thr_getgregs(&thr_handle, gregs); |
|
972 |
||
973 |
jlongArray res = env->NewLongArray(NPRGREG); |
|
974 |
CHECK_EXCEPTION_(0); |
|
975 |
jboolean isCopy; |
|
976 |
jlong* ptr = env->GetLongArrayElements(res, &isCopy); |
|
26410
a34c8032e674
8031583: warnings from b03 for hotspot/agent/src/os/solaris/proc: JNI exception pending
dsamersoff
parents:
25945
diff
changeset
|
977 |
CHECK_EXCEPTION_(NULL); |
1 | 978 |
for (int i = 0; i < NPRGREG; i++) { |
979 |
ptr[i] = (jlong) (uintptr_t) gregs[i]; |
|
980 |
} |
|
981 |
env->ReleaseLongArrayElements(res, ptr, JNI_COMMIT); |
|
982 |
return res; |
|
983 |
} |
|
984 |
||
985 |
/* |
|
986 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
987 |
* Method: fillThreadList0 |
|
988 |
* Signature: (Ljava/util/List;)V |
|
989 |
* Description: fills thread list of the debuggee process/core |
|
990 |
*/ |
|
991 |
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_fillThreadList0 |
|
992 |
(JNIEnv *env, jobject this_obj, jobject list) { |
|
993 |
||
994 |
td_thragent_t* p_td_thragent_t = (td_thragent_t*) env->GetLongField(this_obj, p_td_thragent_t_ID); |
|
995 |
if (p_td_thragent_t == 0) { |
|
996 |
return; |
|
997 |
} |
|
998 |
||
999 |
p_td_ta_thr_iter_t p_td_ta_thr_iter = (p_td_ta_thr_iter_t) env->GetLongField(this_obj, p_td_ta_thr_iter_ID); |
|
1000 |
||
1001 |
DebuggerWithObject dbgo; |
|
1002 |
dbgo.env = env; |
|
1003 |
dbgo.this_obj = this_obj; |
|
1004 |
dbgo.obj = list; |
|
1005 |
||
1006 |
p_td_ta_thr_iter(p_td_thragent_t, fill_thread_list, &dbgo, |
|
1007 |
TD_THR_ANY_STATE, TD_THR_LOWEST_PRIORITY, TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS); |
|
1008 |
} |
|
1009 |
||
1010 |
/* |
|
1011 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
1012 |
* Method: fillCFrameList0 |
|
1013 |
* Signature: ([J)Lsun/jvm/hotspot/debugger/proc/ProcCFrame; |
|
1014 |
* Description: fills CFrame list for a given thread |
|
1015 |
*/ |
|
1016 |
JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_fillCFrameList0 |
|
1017 |
(JNIEnv *env, jobject this_obj, jlongArray regsArray) { |
|
1018 |
jlong p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID); |
|
1019 |
||
1020 |
DebuggerWith2Objects dbgo2; |
|
1021 |
dbgo2.env = env; |
|
1022 |
dbgo2.this_obj = this_obj; |
|
1023 |
dbgo2.obj = NULL; |
|
1024 |
dbgo2.obj2 = NULL; |
|
1025 |
||
1026 |
jboolean isCopy; |
|
1027 |
jlong* ptr = env->GetLongArrayElements(regsArray, &isCopy); |
|
1028 |
CHECK_EXCEPTION_(0); |
|
1029 |
||
1030 |
prgregset_t gregs; |
|
1031 |
for (int i = 0; i < NPRGREG; i++) { |
|
1032 |
gregs[i] = (uintptr_t) ptr[i]; |
|
1033 |
} |
|
1034 |
||
1035 |
env->ReleaseLongArrayElements(regsArray, ptr, JNI_ABORT); |
|
1036 |
CHECK_EXCEPTION_(0); |
|
9407
c985006c2940
7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents:
5547
diff
changeset
|
1037 |
|
c985006c2940
7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents:
5547
diff
changeset
|
1038 |
Pstack_iter((struct ps_prochandle*) p_ps_prochandle, gregs, |
c985006c2940
7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents:
5547
diff
changeset
|
1039 |
wrapper_fill_cframe_list, &dbgo2); |
1 | 1040 |
return dbgo2.obj; |
1041 |
} |
|
1042 |
||
1043 |
/* |
|
1044 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
1045 |
* Method: fillLoadObjectList0 |
|
1046 |
* Signature: (Ljava/util/List;)V |
|
1047 |
* Description: fills shared objects of the debuggee process/core |
|
1048 |
*/ |
|
1049 |
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_fillLoadObjectList0 |
|
1050 |
(JNIEnv *env, jobject this_obj, jobject list) { |
|
1051 |
DebuggerWithObject dbgo; |
|
1052 |
dbgo.env = env; |
|
1053 |
dbgo.this_obj = this_obj; |
|
1054 |
dbgo.obj = list; |
|
1055 |
||
1056 |
jlong p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID); |
|
1057 |
Pobject_iter((struct ps_prochandle*) p_ps_prochandle, fill_load_object_list, &dbgo); |
|
1058 |
} |
|
1059 |
||
1060 |
/* |
|
1061 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
1062 |
* Method: readBytesFromProcess0 |
|
1063 |
* Signature: (JJ)[B |
|
1064 |
* Description: read bytes from debuggee process/core |
|
1065 |
*/ |
|
1066 |
JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_readBytesFromProcess0 |
|
1067 |
(JNIEnv *env, jobject this_obj, jlong address, jlong numBytes) { |
|
1068 |
||
1069 |
jbyteArray array = env->NewByteArray(numBytes); |
|
1070 |
CHECK_EXCEPTION_(0); |
|
1071 |
jboolean isCopy; |
|
1072 |
jbyte* bufPtr = env->GetByteArrayElements(array, &isCopy); |
|
1073 |
CHECK_EXCEPTION_(0); |
|
1074 |
||
1075 |
jlong p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID); |
|
1076 |
ps_err_e ret = ps_pread((struct ps_prochandle*) p_ps_prochandle, |
|
1077 |
(psaddr_t)address, bufPtr, (size_t)numBytes); |
|
1078 |
||
1079 |
if (ret != PS_OK) { |
|
1080 |
// part of the class sharing workaround. try shared heap area |
|
1081 |
int classes_jsa_fd = env->GetIntField(this_obj, classes_jsa_fd_ID); |
|
1082 |
if (classes_jsa_fd != -1 && address != (jlong)0) { |
|
1083 |
print_debug("read failed at 0x%lx, attempting shared heap area\n", (long) address); |
|
1084 |
||
1085 |
struct FileMapHeader* pheader = (struct FileMapHeader*) env->GetLongField(this_obj, p_file_map_header_ID); |
|
49896
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
1086 |
// walk through the shared mappings -- we just have 9 of them. |
1 | 1087 |
// so, linear walking is okay. |
1088 |
for (int m = 0; m < NUM_SHARED_MAPS; m++) { |
|
1089 |
||
1090 |
// We can skip the non-read-only maps. These are mapped as MAP_PRIVATE |
|
1091 |
// and hence will be read by libproc. Besides, the file copy may be |
|
1092 |
// stale because the process might have modified those pages. |
|
1093 |
if (pheader->_space[m]._read_only) { |
|
49896
ec2dd30adbc1
8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents:
49440
diff
changeset
|
1094 |
jlong baseAddress = (jlong) (uintptr_t) pheader->_space[m]._addr._base; |
1 | 1095 |
size_t usedSize = pheader->_space[m]._used; |
1096 |
if (address >= baseAddress && address < (baseAddress + usedSize)) { |
|
1097 |
// the given address falls in this shared heap area |
|
1098 |
print_debug("found shared map at 0x%lx\n", (long) baseAddress); |
|
1099 |
||
1100 |
||
1101 |
// If more data is asked than actually mapped from file, we need to zero fill |
|
1102 |
// till the end-of-page boundary. But, java array new does that for us. we just |
|
1103 |
// need to read as much as data available. |
|
1104 |
||
1105 |
#define MIN2(x, y) (((x) < (y))? (x) : (y)) |
|
1106 |
||
1107 |
jlong diff = address - baseAddress; |
|
1108 |
jlong bytesToRead = MIN2(numBytes, usedSize - diff); |
|
1109 |
off_t offset = pheader->_space[m]._file_offset + off_t(diff); |
|
1110 |
ssize_t bytesRead = pread(classes_jsa_fd, bufPtr, bytesToRead, offset); |
|
1111 |
if (bytesRead != bytesToRead) { |
|
1112 |
env->ReleaseByteArrayElements(array, bufPtr, JNI_ABORT); |
|
1113 |
print_debug("shared map read failed\n"); |
|
1114 |
return jbyteArray(0); |
|
1115 |
} else { |
|
1116 |
print_debug("shared map read succeeded\n"); |
|
1117 |
env->ReleaseByteArrayElements(array, bufPtr, 0); |
|
1118 |
return array; |
|
1119 |
} |
|
1120 |
} // is in current map |
|
1121 |
} // is read only map |
|
1122 |
} // for shared maps |
|
1123 |
} // classes_jsa_fd != -1 |
|
1124 |
env->ReleaseByteArrayElements(array, bufPtr, JNI_ABORT); |
|
1125 |
return jbyteArray(0); |
|
1126 |
} else { |
|
1127 |
env->ReleaseByteArrayElements(array, bufPtr, 0); |
|
1128 |
return array; |
|
1129 |
} |
|
1130 |
} |
|
1131 |
||
1132 |
/* |
|
1133 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
1134 |
* Method: writeBytesToProcess0 |
|
1135 |
* Signature: (JJ[B)V |
|
1136 |
* Description: write bytes into debugger process |
|
1137 |
*/ |
|
1138 |
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_writeBytesToProcess0 |
|
1139 |
(JNIEnv *env, jobject this_obj, jlong address, jlong numBytes, jbyteArray data) { |
|
1140 |
jlong p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID); |
|
1141 |
jboolean isCopy; |
|
1142 |
jbyte* ptr = env->GetByteArrayElements(data, &isCopy); |
|
1143 |
CHECK_EXCEPTION; |
|
1144 |
||
1145 |
if (ps_pwrite((struct ps_prochandle*) p_ps_prochandle, address, ptr, numBytes) != PS_OK) { |
|
1146 |
env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
|
1147 |
THROW_NEW_DEBUGGER_EXCEPTION("Process write failed!"); |
|
1148 |
} |
|
1149 |
||
1150 |
env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
|
1151 |
} |
|
1152 |
||
1153 |
/* |
|
1154 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
1155 |
* Method: suspend0 |
|
1156 |
* Signature: ()V |
|
1157 |
*/ |
|
1158 |
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_suspend0 |
|
1159 |
(JNIEnv *env, jobject this_obj) { |
|
1160 |
jlong p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID); |
|
1161 |
// for now don't check return value. revisit this again. |
|
1162 |
Pstop((struct ps_prochandle*) p_ps_prochandle, 1000); |
|
1163 |
} |
|
1164 |
||
1165 |
/* |
|
1166 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
1167 |
* Method: resume0 |
|
1168 |
* Signature: ()V |
|
1169 |
*/ |
|
1170 |
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_resume0 |
|
1171 |
(JNIEnv *env, jobject this_obj) { |
|
1172 |
jlong p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID); |
|
1173 |
// for now don't check return value. revisit this again. |
|
1174 |
Psetrun((struct ps_prochandle*) p_ps_prochandle, 0, PRCFAULT|PRSTOP); |
|
1175 |
} |
|
1176 |
||
1177 |
/* |
|
1178 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
1179 |
* Method: lookupByName0 |
|
1180 |
* Signature: (Ljava/lang/String;Ljava/lang/String;)J |
|
1181 |
* Description: symbol lookup by name |
|
1182 |
*/ |
|
1183 |
JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_lookupByName0 |
|
1184 |
(JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) { |
|
1185 |
jlong p_ps_prochandle; |
|
1186 |
p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID); |
|
1187 |
||
1188 |
jboolean isCopy; |
|
1189 |
const char* objectName_cstr = NULL; |
|
1190 |
if (objectName != NULL) { |
|
1191 |
objectName_cstr = env->GetStringUTFChars(objectName, &isCopy); |
|
1192 |
CHECK_EXCEPTION_(0); |
|
1193 |
} else { |
|
1194 |
objectName_cstr = PR_OBJ_EVERY; |
|
1195 |
} |
|
1196 |
||
1197 |
const char* symbolName_cstr = env->GetStringUTFChars(symbolName, &isCopy); |
|
1198 |
CHECK_EXCEPTION_(0); |
|
1199 |
||
1200 |
psaddr_t symbol_addr = (psaddr_t) 0; |
|
1201 |
ps_pglobal_lookup((struct ps_prochandle*) p_ps_prochandle, objectName_cstr, |
|
1202 |
symbolName_cstr, &symbol_addr); |
|
1203 |
||
1204 |
if (symbol_addr == 0) { |
|
1205 |
print_debug("lookup for %s in %s failed\n", symbolName_cstr, objectName_cstr); |
|
1206 |
} |
|
1207 |
||
1208 |
if (objectName_cstr != PR_OBJ_EVERY) { |
|
1209 |
env->ReleaseStringUTFChars(objectName, objectName_cstr); |
|
1210 |
} |
|
1211 |
env->ReleaseStringUTFChars(symbolName, symbolName_cstr); |
|
1212 |
return (jlong) (uintptr_t) symbol_addr; |
|
1213 |
} |
|
1214 |
||
1215 |
/* |
|
1216 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
1217 |
* Method: lookupByAddress0 |
|
1218 |
* Signature: (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol; |
|
1219 |
* Description: lookup symbol name for a given address |
|
1220 |
*/ |
|
1221 |
JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_lookupByAddress0 |
|
1222 |
(JNIEnv *env, jobject this_obj, jlong address) { |
|
1223 |
jlong p_ps_prochandle; |
|
1224 |
p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID); |
|
1225 |
||
1226 |
char nameBuf[SYMBOL_BUF_SIZE + 1]; |
|
1227 |
GElf_Sym sym; |
|
1228 |
int res = Plookup_by_addr((struct ps_prochandle*) p_ps_prochandle, (uintptr_t) address, |
|
42035
10e6e31dc1aa
8164383: jhsdb dumps core on Solaris 12 when loading dumped core
dsamersoff
parents:
35217
diff
changeset
|
1229 |
nameBuf, sizeof(nameBuf), &sym, NULL); |
10e6e31dc1aa
8164383: jhsdb dumps core on Solaris 12 when loading dumped core
dsamersoff
parents:
35217
diff
changeset
|
1230 |
|
1 | 1231 |
if (res != 0) { // failed |
1232 |
return 0; |
|
1233 |
} |
|
1234 |
||
1235 |
jstring resSym = env->NewStringUTF(nameBuf); |
|
1236 |
CHECK_EXCEPTION_(0); |
|
1237 |
||
1238 |
return env->CallObjectMethod(this_obj, createClosestSymbol_ID, resSym, (address - sym.st_value)); |
|
1239 |
} |
|
1240 |
||
1241 |
/* |
|
1242 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
1243 |
* Method: demangle0 |
|
1244 |
* Signature: (Ljava/lang/String;)Ljava/lang/String; |
|
1245 |
*/ |
|
1246 |
JNIEXPORT jstring JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_demangle0 |
|
1247 |
(JNIEnv *env, jobject this_object, jstring name) { |
|
1248 |
jboolean isCopy; |
|
1249 |
const char* ptr = env->GetStringUTFChars(name, &isCopy); |
|
26410
a34c8032e674
8031583: warnings from b03 for hotspot/agent/src/os/solaris/proc: JNI exception pending
dsamersoff
parents:
25945
diff
changeset
|
1250 |
CHECK_EXCEPTION_(NULL); |
1 | 1251 |
char buf[2*SYMBOL_BUF_SIZE + 1]; |
1252 |
jstring res = 0; |
|
1253 |
if (cplus_demangle((char*) ptr, buf, sizeof(buf)) != DEMANGLE_ESPACE) { |
|
1254 |
res = env->NewStringUTF(buf); |
|
1255 |
} else { |
|
1256 |
res = name; |
|
1257 |
} |
|
1258 |
env->ReleaseStringUTFChars(name, ptr); |
|
1259 |
return res; |
|
1260 |
} |
|
1261 |
||
1262 |
/* |
|
1263 |
* Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal |
|
1264 |
* Method: initIDs |
|
1265 |
* Signature: ()V |
|
1266 |
* Description: get JNI ids for fields and methods of ProcDebuggerLocal class |
|
1267 |
*/ |
|
1268 |
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_initIDs |
|
1269 |
(JNIEnv *env, jclass clazz) { |
|
1270 |
_libsaproc_debug = getenv("LIBSAPROC_DEBUG") != NULL; |
|
1271 |
if (_libsaproc_debug) { |
|
1272 |
// propagate debug mode to libproc.so |
|
1273 |
static const char* var = "LIBPROC_DEBUG=1"; |
|
1274 |
putenv((char*)var); |
|
1275 |
} |
|
1276 |
||
1277 |
void* libproc_handle = dlopen("libproc.so", RTLD_LAZY | RTLD_GLOBAL); |
|
1278 |
if (libproc_handle == 0) |
|
1279 |
THROW_NEW_DEBUGGER_EXCEPTION("can't load libproc.so, if you are using Solaris 5.7 or below, copy libproc.so from 5.8!"); |
|
1280 |
||
1281 |
p_ps_prochandle_ID = env->GetFieldID(clazz, "p_ps_prochandle", "J"); |
|
1282 |
CHECK_EXCEPTION; |
|
1283 |
||
1284 |
libthread_db_handle_ID = env->GetFieldID(clazz, "libthread_db_handle", "J"); |
|
1285 |
CHECK_EXCEPTION; |
|
1286 |
||
1287 |
p_td_thragent_t_ID = env->GetFieldID(clazz, "p_td_thragent_t", "J"); |
|
1288 |
CHECK_EXCEPTION; |
|
1289 |
||
1290 |
p_td_init_ID = env->GetFieldID(clazz, "p_td_init", "J"); |
|
1291 |
CHECK_EXCEPTION; |
|
1292 |
||
1293 |
p_td_ta_new_ID = env->GetFieldID(clazz, "p_td_ta_new", "J"); |
|
1294 |
CHECK_EXCEPTION; |
|
1295 |
||
1296 |
p_td_ta_delete_ID = env->GetFieldID(clazz, "p_td_ta_delete", "J"); |
|
1297 |
CHECK_EXCEPTION; |
|
1298 |
||
1299 |
p_td_ta_thr_iter_ID = env->GetFieldID(clazz, "p_td_ta_thr_iter", "J"); |
|
1300 |
CHECK_EXCEPTION; |
|
1301 |
||
1302 |
p_td_thr_get_info_ID = env->GetFieldID(clazz, "p_td_thr_get_info", "J"); |
|
1303 |
CHECK_EXCEPTION; |
|
1304 |
||
1305 |
p_td_ta_map_id2thr_ID = env->GetFieldID(clazz, "p_td_ta_map_id2thr", "J"); |
|
1306 |
CHECK_EXCEPTION; |
|
1307 |
||
1308 |
p_td_thr_getgregs_ID = env->GetFieldID(clazz, "p_td_thr_getgregs", "J"); |
|
1309 |
CHECK_EXCEPTION; |
|
1310 |
||
1311 |
getThreadForThreadId_ID = env->GetMethodID(clazz, |
|
1312 |
"getThreadForThreadId", "(J)Lsun/jvm/hotspot/debugger/ThreadProxy;"); |
|
1313 |
CHECK_EXCEPTION; |
|
1314 |
||
1315 |
pcRegIndex_ID = env->GetFieldID(clazz, "pcRegIndex", "I"); |
|
1316 |
CHECK_EXCEPTION; |
|
1317 |
||
1318 |
fpRegIndex_ID = env->GetFieldID(clazz, "fpRegIndex", "I"); |
|
1319 |
CHECK_EXCEPTION; |
|
1320 |
||
1321 |
createSenderFrame_ID = env->GetMethodID(clazz, |
|
1322 |
"createSenderFrame", "(Lsun/jvm/hotspot/debugger/proc/ProcCFrame;JJ)Lsun/jvm/hotspot/debugger/proc/ProcCFrame;"); |
|
1323 |
CHECK_EXCEPTION; |
|
1324 |
||
1325 |
createLoadObject_ID = env->GetMethodID(clazz, |
|
1326 |
"createLoadObject", "(Ljava/lang/String;JJ)Lsun/jvm/hotspot/debugger/cdbg/LoadObject;"); |
|
1327 |
CHECK_EXCEPTION; |
|
1328 |
||
1329 |
createClosestSymbol_ID = env->GetMethodID(clazz, |
|
1330 |
"createClosestSymbol", "(Ljava/lang/String;J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;"); |
|
1331 |
CHECK_EXCEPTION; |
|
1332 |
||
26410
a34c8032e674
8031583: warnings from b03 for hotspot/agent/src/os/solaris/proc: JNI exception pending
dsamersoff
parents:
25945
diff
changeset
|
1333 |
jclass list_clazz = env->FindClass("java/util/List"); |
a34c8032e674
8031583: warnings from b03 for hotspot/agent/src/os/solaris/proc: JNI exception pending
dsamersoff
parents:
25945
diff
changeset
|
1334 |
CHECK_EXCEPTION; |
a34c8032e674
8031583: warnings from b03 for hotspot/agent/src/os/solaris/proc: JNI exception pending
dsamersoff
parents:
25945
diff
changeset
|
1335 |
listAdd_ID = env->GetMethodID(list_clazz, "add", "(Ljava/lang/Object;)Z"); |
1 | 1336 |
CHECK_EXCEPTION; |
1337 |
||
1338 |
// part of the class sharing workaround |
|
1339 |
classes_jsa_fd_ID = env->GetFieldID(clazz, "classes_jsa_fd", "I"); |
|
1340 |
CHECK_EXCEPTION; |
|
1341 |
p_file_map_header_ID = env->GetFieldID(clazz, "p_file_map_header", "J"); |
|
1342 |
CHECK_EXCEPTION; |
|
1343 |
} |