From ab9e7dcef62ae05b3c74215325a2bd2b554d383a Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Mon, 9 Feb 2015 17:06:27 -0800 Subject: [PATCH] Do not dump maps/memory/code of sibling threads. Modifies the code so that if the unwind fails, the code still prints as much data as possible. Also, for sibling threads, skip printing the maps and memory/code since it's not likely to be very relevant. Fix a few cases where extra space is at the end of lines. Fix an inverted if statement that was checking the wrong condition. Bug: 18816322 Change-Id: Ic659e0c34489bf2c65c5a23e2b83e31653b927e4 --- debuggerd/tombstone.cpp | 82 ++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/debuggerd/tombstone.cpp b/debuggerd/tombstone.cpp index 11a15d6f5..4233d4674 100644 --- a/debuggerd/tombstone.cpp +++ b/debuggerd/tombstone.cpp @@ -242,39 +242,37 @@ static void dump_stack_segment( backtrace_map_t map; backtrace->FillInMap(stack_content, &map); - const char* map_name; - if (BacktraceMap::IsValid(map)) { - map_name = ""; - } else { - map_name = map.name.c_str(); + std::string map_name; + if (BacktraceMap::IsValid(map) && map.name.length() > 0) { + map_name = " " + map.name; } uintptr_t offset = 0; std::string func_name(backtrace->GetFunctionName(stack_content, &offset)); if (!func_name.empty()) { if (!i && label >= 0) { if (offset) { - _LOG(log, logtype::STACK, " #%02d %" PRIPTR " %" PRIPTR " %s (%s+%" PRIuPTR ")\n", - label, *sp, stack_content, map_name, func_name.c_str(), offset); + _LOG(log, logtype::STACK, " #%02d %" PRIPTR " %" PRIPTR "%s (%s+%" PRIuPTR ")\n", + label, *sp, stack_content, map_name.c_str(), func_name.c_str(), offset); } else { - _LOG(log, logtype::STACK, " #%02d %" PRIPTR " %" PRIPTR " %s (%s)\n", - label, *sp, stack_content, map_name, func_name.c_str()); + _LOG(log, logtype::STACK, " #%02d %" PRIPTR " %" PRIPTR "%s (%s)\n", + label, *sp, stack_content, map_name.c_str(), func_name.c_str()); } } else { if (offset) { - _LOG(log, logtype::STACK, " %" PRIPTR " %" PRIPTR " %s (%s+%" PRIuPTR ")\n", - *sp, stack_content, map_name, func_name.c_str(), offset); + _LOG(log, logtype::STACK, " %" PRIPTR " %" PRIPTR "%s (%s+%" PRIuPTR ")\n", + *sp, stack_content, map_name.c_str(), func_name.c_str(), offset); } else { - _LOG(log, logtype::STACK, " %" PRIPTR " %" PRIPTR " %s (%s)\n", - *sp, stack_content, map_name, func_name.c_str()); + _LOG(log, logtype::STACK, " %" PRIPTR " %" PRIPTR "%s (%s)\n", + *sp, stack_content, map_name.c_str(), func_name.c_str()); } } } else { if (!i && label >= 0) { - _LOG(log, logtype::STACK, " #%02d %" PRIPTR " %" PRIPTR " %s\n", - label, *sp, stack_content, map_name); + _LOG(log, logtype::STACK, " #%02d %" PRIPTR " %" PRIPTR "%s\n", + label, *sp, stack_content, map_name.c_str()); } else { - _LOG(log, logtype::STACK, " %" PRIPTR " %" PRIPTR " %s\n", - *sp, stack_content, map_name); + _LOG(log, logtype::STACK, " %" PRIPTR " %" PRIPTR "%s\n", + *sp, stack_content, map_name.c_str()); } } @@ -327,36 +325,28 @@ static void dump_stack(Backtrace* backtrace, log_t* log) { } } -static void dump_backtrace_and_stack(Backtrace* backtrace, log_t* log) { - if (backtrace->NumFrames()) { - _LOG(log, logtype::BACKTRACE, "\nbacktrace:\n"); - dump_backtrace_to_log(backtrace, log, " "); - - _LOG(log, logtype::STACK, "\nstack:\n"); - dump_stack(backtrace, log); - } -} - static void dump_map(log_t* log, const backtrace_map_t* map, bool fault_addr) { - _LOG(log, logtype::MAPS, "%s%" PRIPTR "-%" PRIPTR " %c%c%c %7" PRIdPTR " %s\n", + _LOG(log, logtype::MAPS, "%s%" PRIPTR "-%" PRIPTR " %c%c%c %7" PRIdPTR "%s\n", (fault_addr? "--->" : " "), map->start, map->end - 1, (map->flags & PROT_READ) ? 'r' : '-', (map->flags & PROT_WRITE) ? 'w' : '-', (map->flags & PROT_EXEC) ? 'x' : '-', - (map->end - map->start), map->name.c_str()); + (map->end - map->start), + (map->name.length() > 0) ? (" " + map->name).c_str() : ""); } -static void dump_nearby_maps(BacktraceMap* map, log_t* log, pid_t tid) { +static void dump_all_maps(BacktraceMap* map, log_t* log, pid_t tid) { + bool has_fault_address = false; + uintptr_t addr = 0; siginfo_t si; memset(&si, 0, sizeof(si)); if (ptrace(PTRACE_GETSIGINFO, tid, 0, &si)) { _LOG(log, logtype::MAPS, "cannot get siginfo for %d: %s\n", tid, strerror(errno)); - return; + } else { + has_fault_address = signal_has_si_addr(si.si_signo); + addr = reinterpret_cast(si.si_addr); } - bool has_fault_address = signal_has_si_addr(si.si_signo); - uintptr_t addr = reinterpret_cast(si.si_addr); - - _LOG(log, logtype::MAPS, "\nmemory map: %s\n", has_fault_address ? "(fault address prefixed with --->)" : ""); + _LOG(log, logtype::MAPS, "\nmemory map:%s\n", has_fault_address ? " (fault address prefixed with --->)" : ""); if (has_fault_address && (addr < map->begin()->start)) { _LOG(log, logtype::MAPS, "--->Fault address falls at %" PRIPTR " before any mapped regions\n", addr); @@ -376,12 +366,14 @@ static void dump_nearby_maps(BacktraceMap* map, log_t* log, pid_t tid) { } } -static void dump_thread(Backtrace* backtrace, log_t* log) { - dump_registers(log, backtrace->Tid()); - dump_backtrace_and_stack(backtrace, log); +static void dump_backtrace_and_stack(Backtrace* backtrace, log_t* log) { + if (backtrace->NumFrames()) { + _LOG(log, logtype::BACKTRACE, "\nbacktrace:\n"); + dump_backtrace_to_log(backtrace, log, " "); - dump_memory_and_code(log, backtrace->Tid()); - dump_nearby_maps(backtrace->GetMap(), log, backtrace->Tid()); + _LOG(log, logtype::STACK, "\nstack:\n"); + dump_stack(backtrace, log); + } } // Return true if some thread is not detached cleanly @@ -427,9 +419,10 @@ static bool dump_sibling_thread_report( _LOG(log, logtype::THREAD, "--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n"); dump_thread_info(log, pid, new_tid); + dump_registers(log, new_tid); UniquePtr backtrace(Backtrace::Create(pid, new_tid, map)); if (backtrace->Unwind(0)) { - dump_thread(backtrace.get(), log); + dump_backtrace_and_stack(backtrace.get(), log); } log->current_tid = log->crashed_tid; @@ -628,10 +621,13 @@ static bool dump_crash(log_t* log, pid_t pid, pid_t tid, int signal, int si_code UniquePtr map(BacktraceMap::Create(pid)); UniquePtr backtrace(Backtrace::Create(pid, tid, map.get())); + dump_abort_message(backtrace.get(), log, abort_msg_address); + dump_registers(log, tid); if (backtrace->Unwind(0)) { - dump_abort_message(backtrace.get(), log, abort_msg_address); - dump_thread(backtrace.get(), log); + dump_backtrace_and_stack(backtrace.get(), log); } + dump_memory_and_code(log, tid); + dump_all_maps(map.get(), log, tid); if (want_logs) { dump_logs(log, pid, 5);