提交 c372c58b 编写于 作者: S sla

8145099: Better error message when SA can't attach to a process

Reviewed-by: jbachorik, stuefe
上级 2d191657
...@@ -209,9 +209,12 @@ JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_at ...@@ -209,9 +209,12 @@ JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_at
verifyBitness(env, (char *) &buf); verifyBitness(env, (char *) &buf);
CHECK_EXCEPTION; CHECK_EXCEPTION;
char err_buf[200];
struct ps_prochandle* ph; struct ps_prochandle* ph;
if ( (ph = Pgrab(jpid)) == NULL) { if ( (ph = Pgrab(jpid, err_buf, sizeof(err_buf))) == NULL) {
THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the process"); char msg[230];
snprintf(msg, sizeof(msg), "Can't attach to the process: %s", err_buf);
THROW_NEW_DEBUGGER_EXCEPTION(msg);
} }
(*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph); (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);
fillThreadsAndLoadObjects(env, this_obj, ph); fillThreadsAndLoadObjects(env, this_obj, ph);
......
...@@ -82,7 +82,7 @@ typedef int bool; ...@@ -82,7 +82,7 @@ typedef int bool;
struct ps_prochandle; struct ps_prochandle;
// attach to a process // attach to a process
struct ps_prochandle* Pgrab(pid_t pid); struct ps_prochandle* Pgrab(pid_t pid, char* err_buf, size_t err_buf_len);
// attach to a core dump // attach to a core dump
struct ps_prochandle* Pgrab_core(const char* execfile, const char* corefile); struct ps_prochandle* Pgrab_core(const char* execfile, const char* corefile);
......
...@@ -215,9 +215,12 @@ static bool ptrace_waitpid(pid_t pid) { ...@@ -215,9 +215,12 @@ static bool ptrace_waitpid(pid_t pid) {
} }
// attach to a process/thread specified by "pid" // attach to a process/thread specified by "pid"
static bool ptrace_attach(pid_t pid) { static bool ptrace_attach(pid_t pid, char* err_buf, size_t err_buf_len) {
if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) < 0) { if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) < 0) {
print_debug("ptrace(PTRACE_ATTACH, ..) failed for %d\n", pid); char buf[200];
char* msg = strerror_r(errno, buf, sizeof(buf));
snprintf(err_buf, err_buf_len, "ptrace(PTRACE_ATTACH, ..) failed for %d: %s", pid, msg);
print_debug("%s\n", err_buf);
return false; return false;
} else { } else {
return ptrace_waitpid(pid); return ptrace_waitpid(pid);
...@@ -339,16 +342,17 @@ static ps_prochandle_ops process_ops = { ...@@ -339,16 +342,17 @@ static ps_prochandle_ops process_ops = {
}; };
// attach to the process. One and only one exposed stuff // attach to the process. One and only one exposed stuff
struct ps_prochandle* Pgrab(pid_t pid) { struct ps_prochandle* Pgrab(pid_t pid, char* err_buf, size_t err_buf_len) {
struct ps_prochandle* ph = NULL; struct ps_prochandle* ph = NULL;
thread_info* thr = NULL; thread_info* thr = NULL;
if ( (ph = (struct ps_prochandle*) calloc(1, sizeof(struct ps_prochandle))) == NULL) { if ( (ph = (struct ps_prochandle*) calloc(1, sizeof(struct ps_prochandle))) == NULL) {
print_debug("can't allocate memory for ps_prochandle\n"); snprintf(err_buf, err_buf_len, "can't allocate memory for ps_prochandle");
print_debug("%s\n", err_buf);
return NULL; return NULL;
} }
if (ptrace_attach(pid) != true) { if (ptrace_attach(pid, err_buf, err_buf_len) != true) {
free(ph); free(ph);
return NULL; return NULL;
} }
...@@ -371,7 +375,7 @@ struct ps_prochandle* Pgrab(pid_t pid) { ...@@ -371,7 +375,7 @@ struct ps_prochandle* Pgrab(pid_t pid) {
thr = ph->threads; thr = ph->threads;
while (thr) { while (thr) {
// don't attach to the main thread again // don't attach to the main thread again
if (ph->pid != thr->lwp_id && ptrace_attach(thr->lwp_id) != true) { if (ph->pid != thr->lwp_id && ptrace_attach(thr->lwp_id, err_buf, err_buf_len) != true) {
// even if one attach fails, we get return NULL // even if one attach fails, we get return NULL
Prelease(ph); Prelease(ph);
return NULL; return NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册