summaryrefslogtreecommitdiff
path: root/libc/malloc_debug/malloc_debug.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2018-04-05 11:12:38 -0700
committerChristopher Ferris <cferris@google.com>2018-05-24 08:44:53 -0700
commit93bdd6ae3ad8322b7be2be0201c8db7227631d14 (patch)
tree42ee959b96c2c2db42f0569554680dbe22ce39ef /libc/malloc_debug/malloc_debug.cpp
parent4c5c45346fcc6f066a89bfc455f287fe2f4e3e41 (diff)
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
Diffstat (limited to 'libc/malloc_debug/malloc_debug.cpp')
-rw-r--r--libc/malloc_debug/malloc_debug.cpp33
1 files changed, 24 insertions, 9 deletions
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<uintptr_t> frames;
+ std::vector<unwindstack::LocalFrameData> frames_info;
+ if (!Unwind(&frames, &frames_info, 256)) {
+ error_log(" Backtrace failed to get any frames.");
+ } else {
+ UnwindLog(frames_info);
+ }
+ } else {
+ std::vector<uintptr_t> 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<uintptr_t> 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);