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
diff --git a/libc/malloc_debug/malloc_debug.cpp b/libc/malloc_debug/malloc_debug.cpp
index 6f841ca..836c33b 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 @@
});
}
+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 @@
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 @@
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);