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/MapData.cpp b/libc/malloc_debug/MapData.cpp
index d57017e..060425e 100644
--- a/libc/malloc_debug/MapData.cpp
+++ b/libc/malloc_debug/MapData.cpp
@@ -31,8 +31,8 @@
#include <inttypes.h>
#include <link.h>
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
+#include <string.h>
#include <vector>
@@ -46,8 +46,8 @@
uintptr_t offset;
char permissions[5];
int name_pos;
- if (sscanf(line, "%" PRIxPTR "-%" PRIxPTR " %4s %" PRIxPTR " %*x:%*x %*d %n", &start,
- &end, permissions, &offset, &name_pos) < 2) {
+ if (sscanf(line, "%" PRIxPTR "-%" PRIxPTR " %4s %" PRIxPTR " %*x:%*x %*d %n", &start, &end,
+ permissions, &offset, &name_pos) < 2) {
return nullptr;
}
@@ -66,13 +66,13 @@
return entry;
}
-template<typename T>
+template <typename T>
static inline bool get_val(MapEntry* entry, uintptr_t addr, T* store) {
if (addr < entry->start || addr + sizeof(T) > entry->end) {
return false;
}
// Make sure the address is aligned properly.
- if (addr & (sizeof(T)-1)) {
+ if (addr & (sizeof(T) - 1)) {
return false;
}
*store = *reinterpret_cast<T*>(addr);
@@ -157,7 +157,7 @@
return nullptr;
}
- MapEntry *entry = *it;
+ MapEntry* entry = *it;
if (!entry->load_base_read) {
read_loadbase(entry);
}