From 053b865412d1982ad1dc0e840898d82527deeb99 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Wed, 6 Jun 2012 16:25:03 -0700 Subject: Enhance native stack dumps. Provides a new mechanism for dumpstate (while running as root) to request that debuggerd dump the stacks of native processes that we care about in bug reports. In this mode, the backtrace is formatted to look similar to a Dalvik backtrace. Moved the tombstone generating code into a separate file to make it easier to maintain. Fixed a bug where sometimes the stack traces would be incomplete because we were not waiting for each thread to stop after issuing PTRACE_ATTACH, only the main thread. So sometimes we were missing traces for some threads. Refactored the logging code to prevent accidentally writing data to logcat when explicitly dumping a tombstone or backtrace from the console. Only root or system server can request to dump backtraces but only root can dump tombstones. Bug: 6615693 Change-Id: Ib3edcc16f9f3a687e414e3f2d250d9500566123b --- debuggerd/x86/machine.c | 49 +++++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) (limited to 'debuggerd/x86/machine.c') diff --git a/debuggerd/x86/machine.c b/debuggerd/x86/machine.c index 2729c7e..01da5fe 100644 --- a/debuggerd/x86/machine.c +++ b/debuggerd/x86/machine.c @@ -15,59 +15,44 @@ ** limitations under the License. */ +#include +#include +#include +#include #include #include -#include -#include -#include #include -#include - #include -#include -#include -#include - -#include -#include -#include #include -#include +#include -#include "../machine.h" #include "../utility.h" +#include "../machine.h" + +void dump_memory_and_code(const ptrace_context_t* context __attribute((unused)), + log_t* log, pid_t tid, bool at_fault) { +} -static void dump_registers(const ptrace_context_t* context __attribute((unused)), - int tfd, pid_t tid, bool at_fault) { +void dump_registers(const ptrace_context_t* context __attribute((unused)), + log_t* log, pid_t tid, bool at_fault) { struct pt_regs_x86 r; bool only_in_tombstone = !at_fault; if(ptrace(PTRACE_GETREGS, tid, 0, &r)) { - _LOG(tfd, only_in_tombstone, "cannot get registers: %s\n", strerror(errno)); + _LOG(log, only_in_tombstone, "cannot get registers: %s\n", strerror(errno)); return; } //if there is no stack, no print just like arm if(!r.ebp) return; - _LOG(tfd, only_in_tombstone, " eax %08x ebx %08x ecx %08x edx %08x\n", + _LOG(log, only_in_tombstone, " eax %08x ebx %08x ecx %08x edx %08x\n", r.eax, r.ebx, r.ecx, r.edx); - _LOG(tfd, only_in_tombstone, " esi %08x edi %08x\n", + _LOG(log, only_in_tombstone, " esi %08x edi %08x\n", r.esi, r.edi); - _LOG(tfd, only_in_tombstone, " xcs %08x xds %08x xes %08x xfs %08x xss %08x\n", + _LOG(log, only_in_tombstone, " xcs %08x xds %08x xes %08x xfs %08x xss %08x\n", r.xcs, r.xds, r.xes, r.xfs, r.xss); - _LOG(tfd, only_in_tombstone, " eip %08x ebp %08x esp %08x flags %08x\n", + _LOG(log, only_in_tombstone, " eip %08x ebp %08x esp %08x flags %08x\n", r.eip, r.ebp, r.esp, r.eflags); } - -void dump_thread(const ptrace_context_t* context, int tfd, pid_t tid, bool at_fault) { - dump_registers(context, tfd, tid, at_fault); - - dump_backtrace_and_stack(context, tfd, tid, at_fault); - - if (at_fault) { - dump_nearby_maps(context, tfd, tid); - } -} - -- cgit v1.1