Refactor malloc debug.
Changes
- Refactor the code so that only guards require creating a special header
for every pointer allocated.
- Store only a single copy of every backtrace. This saves memory so that
turning on the backtrace option doesn't result in 10X memory usage.
- Added new option track_allocs that only verifies pointers are valid for
free/malloc_usable_size/realloc.
- Remove suffix from test names.
- Add the TRACK_ALLOCS options to all guard options.
- Add new option verify_pointers that is a lightweight way to verify
pointers that are passed to allocation routines.
- Do auto-formatting of the code.
- Updated documentation for all of these changes.
Bug: 74361929
Test: Ran unit tests.
Test: Ran libmemunreachable unit tests.
Test: Ran an app with backtrace enabled.
Change-Id: I3246c48ae4f9811f64622d90d0a9b4d9d818702c
diff --git a/libc/malloc_debug/backtrace.cpp b/libc/malloc_debug/backtrace.cpp
index 2443ba1..cd8c334 100644
--- a/libc/malloc_debug/backtrace.cpp
+++ b/libc/malloc_debug/backtrace.cpp
@@ -38,9 +38,9 @@
#include <demangle.h>
+#include "MapData.h"
#include "backtrace.h"
#include "debug_log.h"
-#include "MapData.h"
#if defined(__LP64__)
#define PAD_PTR "016" PRIxPTR
@@ -69,8 +69,7 @@
_Unwind_Backtrace(find_current_map, nullptr);
}
-void backtrace_shutdown() {
-}
+void backtrace_shutdown() {}
struct stack_crawl_state_t {
uintptr_t* frames;
@@ -165,13 +164,13 @@
char buf[1024];
if (symbol != nullptr) {
- async_safe_format_buffer(
- buf, sizeof(buf), " #%02zd pc %" PAD_PTR " %s%s (%s+%" PRIuPTR ")\n", frame_num,
- rel_pc, soname, offset_buf, demangle(symbol).c_str(), frames[frame_num] - offset);
+ async_safe_format_buffer(buf, sizeof(buf),
+ " #%02zd pc %" PAD_PTR " %s%s (%s+%" PRIuPTR ")\n",
+ frame_num, rel_pc, soname, offset_buf, demangle(symbol).c_str(),
+ frames[frame_num] - offset);
} else {
- async_safe_format_buffer(
- buf, sizeof(buf), " #%02zd pc %" PAD_PTR " %s%s\n", frame_num, rel_pc, soname,
- offset_buf);
+ async_safe_format_buffer(buf, sizeof(buf), " #%02zd pc %" PAD_PTR " %s%s\n",
+ frame_num, rel_pc, soname, offset_buf);
}
str += buf;
}