diff options
author | Karol Lewandowski <k.lewandowsk@samsung.com> | 2016-12-20 08:23:33 -0800 |
---|---|---|
committer | Gerrit Code Review <gerrit@review.vlan103.tizen.org> | 2016-12-20 08:23:33 -0800 |
commit | e4769d50f923dfc702c8396b63346d8b273ccc08 (patch) | |
tree | d138b23f31ffcad97ab847f7645c25f7f9ee6978 | |
parent | 0cc4ad5390a4fe07765e5b8ede4e632626d1ee1b (diff) | |
parent | 37b99923a1301b3c1a82e1b5616814a3c108fd2f (diff) | |
download | crash-worker-e4769d50f923dfc702c8396b63346d8b273ccc08.tar.gz crash-worker-e4769d50f923dfc702c8396b63346d8b273ccc08.tar.bz2 crash-worker-e4769d50f923dfc702c8396b63346d8b273ccc08.zip |
Merge "crash-stack: fixed attaching to thread" into tizen_3.0
-rw-r--r-- | src/crash-stack/crash-stack.c | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/src/crash-stack/crash-stack.c b/src/crash-stack/crash-stack.c index ea4dbc5..71d2f15 100644 --- a/src/crash-stack/crash-stack.c +++ b/src/crash-stack/crash-stack.c @@ -284,14 +284,14 @@ void __find_symbol_in_elf(ProcInfo *proc_info, Dwarf_Addr mapping_start) close(fd); } -static int __attachable(pid_t pid) +static int __attachable(pid_t pid, pid_t tid) { /* read /proc/<pid>/stat */ - char buf[20]; + char buf[40]; FILE *f; char status; - snprintf(buf, sizeof(buf), "/proc/%d/stat", pid); + snprintf(buf, sizeof(buf), "/proc/%d/task/%d/stat", pid, tid); f = fopen(buf, "r"); if (NULL == f) @@ -306,13 +306,13 @@ static int __attachable(pid_t pid) return status != 'D'; } -static void __print_proc_file(pid_t pid, const char *name) +static void __print_proc_file(pid_t pid, pid_t tid, const char *name) { char buf[1024]; FILE *f; int r; - snprintf(buf, sizeof(buf), "/proc/%d/%s", pid, name); + snprintf(buf, sizeof(buf), "/proc/%d/task/%d/%s", pid, tid, name); fprintf(outputfile, "%s:\n", buf); @@ -333,14 +333,14 @@ static void __print_proc_file(pid_t pid, const char *name) fprintf(outputfile, "\n"); } -static void __print_not_attachable_process_info(pid_t pid) +static void __print_not_attachable_process_info(pid_t pid, pid_t tid) { - fprintf(outputfile, "ERROR: can't attach to process %d - process is in uninterruptible sleep state\n", pid); + fprintf(outputfile, "ERROR: can't attach to process %d, thread %d - thread is in uninterruptible sleep state\n", pid, tid); fprintf(outputfile, "Giving some /proc info instead:\n\n"); - __print_proc_file(pid, "wchan"); + __print_proc_file(pid, tid, "wchan"); fprintf(outputfile, "\n"); - __print_proc_file(pid, "syscall"); - __print_proc_file(pid, "stack"); + __print_proc_file(pid, tid, "syscall"); + __print_proc_file(pid, tid, "stack"); } /** @@ -354,16 +354,16 @@ static Dwfl *__open_dwfl_with_pid(pid_t pid, pid_t tid) int status; pid_t stopped_pid; - status = __attachable(pid); + status = __attachable(pid, tid); if (-1 == status) { - fprintf(errfile, "failed to read /proc/%d/stat: %m\n", pid); + fprintf(errfile, "failed to read /proc/%d/task/%d/stat: %m\n", pid, tid); return NULL; } if (!status) { - __print_not_attachable_process_info(pid); + __print_not_attachable_process_info(pid, tid); return NULL; } @@ -372,23 +372,18 @@ static Dwfl *__open_dwfl_with_pid(pid_t pid, pid_t tid) return NULL; } - if (pid != tid) - if (ptrace(PTRACE_SEIZE, pid, NULL, PTRACE_O_TRACEEXIT) != 0) { - fprintf(errfile, "PTRACE_SEIZE failed on PID %d: %m\n", pid); - return NULL; - } - ptrace(PTRACE_INTERRUPT, tid, 0, 0); - ptrace(PTRACE_INTERRUPT, pid, 0, 0); - stopped_pid = waitpid(pid, &status, 0); - if (stopped_pid == -1 || stopped_pid != pid || !WIFSTOPPED(status)) { + stopped_pid = waitpid(tid, &status, __WALL); + if (stopped_pid == -1 || stopped_pid != tid || !WIFSTOPPED(status)) { fprintf(errfile, "waitpid failed: %m, stopped_pid=%d, status=%d\n", stopped_pid, status); return NULL; } - if (ptrace(PTRACE_GETSIGINFO, pid, NULL, &__siginfo) != 0) + if (ptrace(PTRACE_GETSIGINFO, tid, NULL, &__siginfo) != 0) { + fprintf(errfile, "ptrace GETSIGINFO failed: %m, pid=%d, tid=%d\n", pid, tid); return NULL; + } static const Dwfl_Callbacks proc_callbacks = { .find_elf = dwfl_linux_proc_find_elf, @@ -399,19 +394,19 @@ static Dwfl *__open_dwfl_with_pid(pid_t pid, pid_t tid) Dwfl *dwfl = dwfl_begin(&proc_callbacks); if (dwfl == NULL) { - fprintf(errfile, "process %d : Can't start dwfl (%s)\n", pid, dwfl_errmsg(-1)); + fprintf(errfile, "process %d : Can't start dwfl (%s)\n", tid, dwfl_errmsg(-1)); return NULL; } - if (dwfl_linux_proc_report(dwfl, pid) < 0) { - fprintf(errfile, "process %d : dwfl report failed (%s)\n", pid, dwfl_errmsg(-1)); + if (dwfl_linux_proc_report(dwfl, tid) < 0) { + fprintf(errfile, "process %d : dwfl report failed (%s)\n", tid, dwfl_errmsg(-1)); dwfl_end(dwfl); return NULL; } #if _ELFUTILS_PREREQ(0,158) - if (dwfl_linux_proc_attach(dwfl, pid, true) < 0) { - fprintf(errfile, "process %d : dwfl attach failed (%s)\n", pid, dwfl_errmsg(-1)); + if (dwfl_linux_proc_attach(dwfl, tid, true) < 0) { + fprintf(errfile, "process %d : dwfl attach failed (%s)\n", tid, dwfl_errmsg(-1)); dwfl_end(dwfl); return NULL; } |