rd_err_e rd_reset(struct rd_agent *rap) { rd_err_e err; RDAGLOCK(rap); rap->rd_flags = 0; #ifdef _LP64 /* * Determine if client is 32-bit or 64-bit. */ if (ps_pdmodel(rap->rd_psp, &rap->rd_dmodel) != PS_OK) { LOG(ps_plog(MSG_ORIG(MSG_DB_DMLOOKFAIL))); RDAGUNLOCK(rap); return (RD_DBERR); } if (rap->rd_dmodel == PR_MODEL_LP64) err = _rd_reset64(rap); else #endif err = _rd_reset32(rap); RDAGUNLOCK(rap); return (err); }
/* * Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal * Method: getRemoteProcessAddressSize0 * Signature: ()I */ JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_getRemoteProcessAddressSize0 (JNIEnv *env, jobject this_obj) { jlong ps_prochandle_ptr; ps_prochandle_ptr = env->GetLongField(this_obj, ps_prochandle_ptr_ID); int data_model = PR_MODEL_ILP32; ps_pdmodel((struct ps_prochandle*) ps_prochandle_ptr, &data_model); return (jint) data_model == PR_MODEL_ILP32? 32 : 64; }
static void attach_internal(JNIEnv* env, jobject this_obj, jstring cmdLine, jboolean isProcess) { jboolean isCopy; int gcode; const char* cmdLine_cstr = env->GetStringUTFChars(cmdLine, &isCopy); CHECK_EXCEPTION; // some older versions of libproc.so crash when trying to attach 32 bit // debugger to 64 bit core file. check and throw error. #ifndef _LP64 atoi(cmdLine_cstr); if (errno) { // core file int core_fd; if ((core_fd = open64(cmdLine_cstr, O_RDONLY)) >= 0) { Elf32_Ehdr e32; if (pread64(core_fd, &e32, sizeof (e32), 0) == sizeof (e32) && memcmp(&e32.e_ident[EI_MAG0], ELFMAG, SELFMAG) == 0 && e32.e_type == ET_CORE && e32.e_ident[EI_CLASS] == ELFCLASS64) { close(core_fd); THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 64 bit, use java -d64 for debugger"); } close(core_fd); } // all other conditions are handled by libproc.so. } #endif // connect to process/core ps_prochandle_t* ph = proc_arg_grab(cmdLine_cstr, (isProcess? PR_ARG_PIDS : PR_ARG_CORES), PGRAB_FORCE, &gcode, NULL); env->ReleaseStringUTFChars(cmdLine, cmdLine_cstr); if (! ph) { if (gcode > 0 && gcode < sizeof(proc_arg_grab_errmsgs)/sizeof(const char*)) { char errMsg[ERR_MSG_SIZE]; sprintf(errMsg, "Attach failed : %s", proc_arg_grab_errmsgs[gcode]); THROW_NEW_DEBUGGER_EXCEPTION(errMsg); } else { if (_libsaproc_debug && gcode == G_STRANGE) { perror("libsaproc DEBUG: "); } if (isProcess) { THROW_NEW_DEBUGGER_EXCEPTION("Not able to attach to process!"); } else { THROW_NEW_DEBUGGER_EXCEPTION("Not able to attach to core file!"); } } } // even though libproc.so supports 64 bit debugger and 32 bit debuggee, we don't // support such cross-bit-debugging. check for that combination and throw error. #ifdef _LP64 int data_model; if (ps_pdmodel(ph, &data_model) != PS_OK) { Prelease(ph, PRELEASE_CLEAR); THROW_NEW_DEBUGGER_EXCEPTION("can't determine debuggee data model (ILP32? or LP64?)"); } if (data_model == PR_MODEL_ILP32) { Prelease(ph, PRELEASE_CLEAR); THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 32 bit, use 32 bit java for debugger"); } #endif env->SetLongField(this_obj, p_ps_prochandle_ID, (jlong)(uintptr_t)ph); Debugger dbg; dbg.env = env; dbg.this_obj = this_obj; jthrowable exception = 0; if (! isProcess) { /* * With class sharing, shared perm. gen heap is allocated in with MAP_SHARED|PROT_READ. * These pages are mapped from the file "classes.jsa". MAP_SHARED pages are not dumped * in Solaris core.To read shared heap pages, we have to read classes.jsa file. */ Pobject_iter(ph, init_classsharing_workaround, &dbg); exception = env->ExceptionOccurred(); if (exception) { env->ExceptionClear(); detach_internal(env, this_obj); env->Throw(exception); return; } } /* * Iterate over the process mappings looking * for libthread and then dlopen the appropriate * libthread_db and get function pointers. */ Pobject_iter(ph, init_libthread_db_ptrs, &dbg); exception = env->ExceptionOccurred(); if (exception) { env->ExceptionClear(); if (!sa_ignore_threaddb) { detach_internal(env, this_obj); env->Throw(exception); } return; } // init libthread_db and create thread_db agent p_td_init_t p_td_init = (p_td_init_t) env->GetLongField(this_obj, p_td_init_ID); if (p_td_init == 0) { if (!sa_ignore_threaddb) { detach_internal(env, this_obj); } HANDLE_THREADDB_FAILURE("Did not find libthread in target process/core!"); } if (p_td_init() != TD_OK) { if (!sa_ignore_threaddb) { detach_internal(env, this_obj); } HANDLE_THREADDB_FAILURE("Can't initialize thread_db!"); } p_td_ta_new_t p_td_ta_new = (p_td_ta_new_t) env->GetLongField(this_obj, p_td_ta_new_ID); td_thragent_t *p_td_thragent_t = 0; if (p_td_ta_new(ph, &p_td_thragent_t) != TD_OK) { if (!sa_ignore_threaddb) { detach_internal(env, this_obj); } HANDLE_THREADDB_FAILURE("Can't create thread_db agent!"); } env->SetLongField(this_obj, p_td_thragent_t_ID, (jlong)(uintptr_t) p_td_thragent_t); }