comparison agent/src/os/bsd/MacosxDebuggerLocal.m @ 10158:9f96b7a853bc

8013466: SA crashes when attaching to a process on OS X Reviewed-by: coleenp, rbackman, minqi
author sla
date Tue, 30 Apr 2013 10:53:58 +0200
parents 39432a1cefdd
children e4614b063fe1
comparison
equal deleted inserted replaced
10153:3c9b7ef92c61 10158:9f96b7a853bc
202 Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0( 202 Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0(
203 JNIEnv *env, jobject this_obj, 203 JNIEnv *env, jobject this_obj,
204 jstring objectName, jstring symbolName) 204 jstring objectName, jstring symbolName)
205 { 205 {
206 struct ps_prochandle* ph = get_proc_handle(env, this_obj); 206 struct ps_prochandle* ph = get_proc_handle(env, this_obj);
207 if (ph->core != NULL) { 207 if (ph != NULL && ph->core != NULL) {
208 return lookupByNameIncore(env, ph, this_obj, objectName, symbolName); 208 return lookupByNameIncore(env, ph, this_obj, objectName, symbolName);
209 } 209 }
210 210
211 jlong address = 0; 211 jlong address = 0;
212 212
236 (JNIEnv *env, jobject this_obj, jlong addr) { 236 (JNIEnv *env, jobject this_obj, jlong addr) {
237 uintptr_t offset; 237 uintptr_t offset;
238 const char* sym = NULL; 238 const char* sym = NULL;
239 239
240 struct ps_prochandle* ph = get_proc_handle(env, this_obj); 240 struct ps_prochandle* ph = get_proc_handle(env, this_obj);
241 sym = symbol_for_pc(ph, (uintptr_t) addr, &offset); 241 if (ph != NULL && ph->core != NULL) {
242 if (sym == NULL) return 0; 242 sym = symbol_for_pc(ph, (uintptr_t) addr, &offset);
243 return (*env)->CallObjectMethod(env, this_obj, createClosestSymbol_ID, 243 if (sym == NULL) return 0;
244 return (*env)->CallObjectMethod(env, this_obj, createClosestSymbol_ID,
244 (*env)->NewStringUTF(env, sym), (jlong)offset); 245 (*env)->NewStringUTF(env, sym), (jlong)offset);
246 }
247 return 0;
245 } 248 }
246 249
247 /** called from Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0 */ 250 /** called from Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0 */
248 jbyteArray readBytesFromCore( 251 jbyteArray readBytesFromCore(
249 JNIEnv *env, struct ps_prochandle *ph, jobject this_obj, jlong addr, jlong numBytes) 252 JNIEnv *env, struct ps_prochandle *ph, jobject this_obj, jlong addr, jlong numBytes)
277 280
278 // must allocate storage instead of using former parameter buf 281 // must allocate storage instead of using former parameter buf
279 jbyteArray array; 282 jbyteArray array;
280 283
281 struct ps_prochandle* ph = get_proc_handle(env, this_obj); 284 struct ps_prochandle* ph = get_proc_handle(env, this_obj);
282 if (ph->core != NULL) { 285 if (ph != NULL && ph->core != NULL) {
283 return readBytesFromCore(env, ph, this_obj, addr, numBytes); 286 return readBytesFromCore(env, ph, this_obj, addr, numBytes);
284 } 287 }
285 288
286 array = (*env)->NewByteArray(env, numBytes); 289 array = (*env)->NewByteArray(env, numBytes);
287 CHECK_EXCEPTION_(0); 290 CHECK_EXCEPTION_(0);
392 } 395 }
393 396
394 /* For core file only, called from 397 /* For core file only, called from
395 * Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0 398 * Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0
396 */ 399 */
397 jlongArray getThreadIntegerRegisterSetFromCore(JNIEnv *env, jobject this_obj, long lwp_id) { 400 jlongArray getThreadIntegerRegisterSetFromCore(JNIEnv *env, jobject this_obj, long lwp_id, struct ps_prochandle* ph) {
398 if (!_threads_filled) { 401 if (!_threads_filled) {
399 if (!fill_java_threads(env, this_obj, get_proc_handle(env, this_obj))) { 402 if (!fill_java_threads(env, this_obj, ph)) {
400 throw_new_debugger_exception(env, "Failed to fill in threads"); 403 throw_new_debugger_exception(env, "Failed to fill in threads");
401 return 0; 404 return 0;
402 } else { 405 } else {
403 _threads_filled = true; 406 _threads_filled = true;
404 } 407 }
407 struct reg gregs; 410 struct reg gregs;
408 jboolean isCopy; 411 jboolean isCopy;
409 jlongArray array; 412 jlongArray array;
410 jlong *regs; 413 jlong *regs;
411 414
412 struct ps_prochandle* ph = get_proc_handle(env, this_obj);
413 if (get_lwp_regs(ph, lwp_id, &gregs) != true) { 415 if (get_lwp_regs(ph, lwp_id, &gregs) != true) {
414 THROW_NEW_DEBUGGER_EXCEPTION_("get_thread_regs failed for a lwp", 0); 416 THROW_NEW_DEBUGGER_EXCEPTION_("get_thread_regs failed for a lwp", 0);
415 } 417 }
416 418
417 #undef NPRGREG 419 #undef NPRGREG
519 jlong thread_id) 521 jlong thread_id)
520 { 522 {
521 print_debug("getThreadRegisterSet0 called\n"); 523 print_debug("getThreadRegisterSet0 called\n");
522 524
523 struct ps_prochandle* ph = get_proc_handle(env, this_obj); 525 struct ps_prochandle* ph = get_proc_handle(env, this_obj);
524 if (ph->core != NULL) { 526 if (ph != NULL && ph->core != NULL) {
525 return getThreadIntegerRegisterSetFromCore(env, this_obj, thread_id); 527 return getThreadIntegerRegisterSetFromCore(env, this_obj, thread_id, ph);
526 } 528 }
527 529
528 kern_return_t result; 530 kern_return_t result;
529 thread_t tid; 531 thread_t tid;
530 mach_msg_type_number_t count = HSDB_THREAD_STATE_COUNT; 532 mach_msg_type_number_t count = HSDB_THREAD_STATE_COUNT;