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