diff options
author | Adrian Szyndela <adrian.s@samsung.com> | 2016-12-14 14:52:37 +0100 |
---|---|---|
committer | Karol Lewandowski <k.lewandowsk@samsung.com> | 2016-12-14 16:56:32 +0100 |
commit | 78b75f2ef9fece4a3cc2bf8251c7a9ed20c61de5 (patch) | |
tree | 9799c9b9591584ce59cec79a5ec075fa80537e32 | |
parent | 1c23e085a8377ee92f2200af9b98a0841edf3e87 (diff) | |
download | crash-worker-78b75f2ef9fece4a3cc2bf8251c7a9ed20c61de5.tar.gz crash-worker-78b75f2ef9fece4a3cc2bf8251c7a9ed20c61de5.tar.bz2 crash-worker-78b75f2ef9fece4a3cc2bf8251c7a9ed20c61de5.zip |
crash-stack: support for resolving stack from threads
Change-Id: Ic80b6b83acb80b3c332b6b6674fbf662b1003586
-rw-r--r-- | src/crash-stack/crash-stack.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/crash-stack/crash-stack.c b/src/crash-stack/crash-stack.c index d839a4f..a377306 100644 --- a/src/crash-stack/crash-stack.c +++ b/src/crash-stack/crash-stack.c @@ -269,17 +269,24 @@ void __find_symbol_in_elf(ProcInfo *proc_info, Dwarf_Addr mapping_start) * @param pid pid of the process to attach to * @return Dwfl handle */ -static Dwfl *__open_dwfl_with_pid(pid_t pid) +static Dwfl *__open_dwfl_with_pid(pid_t pid, pid_t tid) { int status; pid_t stopped_pid; - if (ptrace(PTRACE_SEIZE, pid, NULL, PTRACE_O_TRACEEXIT) != 0) { - fprintf(errfile, "PTRACE_SEIZE failed on PID %d: %m\n", pid); + if (ptrace(PTRACE_SEIZE, tid, NULL, PTRACE_O_TRACEEXIT) != 0) { + fprintf(errfile, "PTRACE_SEIZE failed on TID %d: %m\n", 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, pid, 0, 0); + ptrace(PTRACE_INTERRUPT, tid, 0, 0); stopped_pid = waitpid(pid, &status, 0); if (stopped_pid == -1 || stopped_pid != pid || !WIFSTOPPED(status)) { @@ -874,6 +881,8 @@ int main(int argc, char **argv) if (NULL == errfile) errfile = stderr; if (NULL == outputfile) outputfile = stdout; + if (tid == 0) tid = pid; + core_file_name = argv[optind]; argc -= optind; @@ -885,11 +894,11 @@ int main(int argc, char **argv) Dwfl *dwfl = NULL; if (pid > 1) - dwfl = __open_dwfl_with_pid(pid); + dwfl = __open_dwfl_with_pid(pid, tid); else { if (argc != 1) { fprintf(errfile, - "Usage: %s [--output file] [--erroutput file] [--pid <pid> | <core-file>]\n", + "Usage: %s [--output file] [--erroutput file] [--pid <pid> [--tid <tid>] | <core-file>]\n", argv[0]); return 1; } @@ -934,7 +943,7 @@ int main(int argc, char **argv) Callstack callstack; callstack_constructor(&callstack); - _create_crash_stack(dwfl, core, pid, &mappings, &callstack); + _create_crash_stack(dwfl, core, tid, &mappings, &callstack); size_t it; for (it = 0; it != callstack.elems; ++it) __resolve_symbols(&callstack.proc[it], dwfl, core, notes); @@ -946,7 +955,7 @@ int main(int argc, char **argv) __crash_stack_print_threads(outputfile, pid, tid); /* Print the results */ - __print_callstack(&callstack, pid); + __print_callstack(&callstack, tid); /* Clean up */ callstack_destructor(&callstack); |