From 93bdd6ae3ad8322b7be2be0201c8db7227631d14 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Thu, 5 Apr 2018 11:12:38 -0700 Subject: Add support for using the new unwinder. This adds a new option backtrace_full, when it is set, then it will use libunwindstack. Modify the dump to file data to dump the extra information from libunwindstack. Along with the new dump file format, change the version to v1.1. Updated document for new format of file data. Add unit tests for the new functionality. Bug: 74361929 Test: Ran unit tests. Change-Id: I40fff795f5346bba7b9d7fde2e04f269ff4eb7f1 --- libc/malloc_debug/malloc_debug.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'libc/malloc_debug/malloc_debug.cpp') diff --git a/libc/malloc_debug/malloc_debug.cpp b/libc/malloc_debug/malloc_debug.cpp index 6f841cab5..836c33b86 100644 --- a/libc/malloc_debug/malloc_debug.cpp +++ b/libc/malloc_debug/malloc_debug.cpp @@ -47,6 +47,7 @@ #include "debug_disable.h" #include "debug_log.h" #include "malloc_debug.h" +#include "UnwindBacktrace.h" // ------------------------------------------------------------------------ // Global Data @@ -118,6 +119,26 @@ static void InitAtfork() { }); } +void BacktraceAndLog() { + if (g_debug->config().options() & BACKTRACE_FULL) { + std::vector frames; + std::vector frames_info; + if (!Unwind(&frames, &frames_info, 256)) { + error_log(" Backtrace failed to get any frames."); + } else { + UnwindLog(frames_info); + } + } else { + std::vector frames(256); + size_t num_frames = backtrace_get(frames.data(), frames.size()); + if (num_frames == 0) { + error_log(" Backtrace failed to get any frames."); + } else { + backtrace_log(frames.data(), num_frames); + } + } +} + static void LogError(const void* pointer, const char* error_str) { error_log(LOG_DIVIDER); error_log("+++ ALLOCATION %p %s", pointer, error_str); @@ -128,14 +149,8 @@ static void LogError(const void* pointer, const char* error_str) { PointerData::LogFreeBacktrace(pointer); } - std::vector frames(128); - size_t num_frames = backtrace_get(frames.data(), frames.size()); - if (num_frames == 0) { - error_log("Backtrace failed to get any frames."); - } else { - error_log("Backtrace at time of failure:"); - backtrace_log(frames.data(), num_frames); - } + error_log("Backtrace at time of failure:"); + BacktraceAndLog(); error_log(LOG_DIVIDER); } @@ -819,7 +834,7 @@ bool debug_dump_heap(const char* file_name) { return false; } - fprintf(fp, "Android Native Heap Dump v1.0\n\n"); + fprintf(fp, "Android Native Heap Dump v1.1\n\n"); PointerData::DumpLiveToFile(fp); -- cgit v1.2.3