summaryrefslogtreecommitdiff
path: root/libc/malloc_debug
diff options
context:
space:
mode:
Diffstat (limited to 'libc/malloc_debug')
-rw-r--r--libc/malloc_debug/DebugData.h6
-rw-r--r--libc/malloc_debug/PointerData.cpp5
-rw-r--r--libc/malloc_debug/malloc_debug.cpp23
3 files changed, 33 insertions, 1 deletions
diff --git a/libc/malloc_debug/DebugData.h b/libc/malloc_debug/DebugData.h
index 3a3629981..1ad2f6812 100644
--- a/libc/malloc_debug/DebugData.h
+++ b/libc/malloc_debug/DebugData.h
@@ -98,3 +98,9 @@ class DebugData {
};
extern DebugData* g_debug;
+
+// The minimum and maximum allocation sizes
+// for which backtrace will be recorded.
+// They default to 0 and SIZE_MAX respectively
+extern size_t g_min_alloc_to_record;
+extern size_t g_max_alloc_to_record;
diff --git a/libc/malloc_debug/PointerData.cpp b/libc/malloc_debug/PointerData.cpp
index ec7e42dda..b5219a172 100644
--- a/libc/malloc_debug/PointerData.cpp
+++ b/libc/malloc_debug/PointerData.cpp
@@ -197,7 +197,10 @@ void PointerData::Add(const void* ptr, size_t pointer_size) {
uintptr_t pointer = reinterpret_cast<uintptr_t>(ptr);
size_t hash_index = 0;
if (backtrace_enabled_) {
- hash_index = AddBacktrace(g_debug->config().backtrace_frames());
+ if ((pointer_size >= g_min_alloc_to_record) &&
+ (pointer_size <= g_max_alloc_to_record)) {
+ hash_index = AddBacktrace(g_debug->config().backtrace_frames());
+ }
}
std::lock_guard<std::mutex> pointer_guard(pointer_mutex_);
diff --git a/libc/malloc_debug/malloc_debug.cpp b/libc/malloc_debug/malloc_debug.cpp
index c030d5429..d2679ca4c 100644
--- a/libc/malloc_debug/malloc_debug.cpp
+++ b/libc/malloc_debug/malloc_debug.cpp
@@ -37,6 +37,8 @@
#include <sys/param.h>
#include <unistd.h>
+#include <sys/system_properties.h>
+
#include <mutex>
#include <vector>
@@ -62,6 +64,10 @@ DebugData* g_debug;
bool* g_zygote_child;
const MallocDispatch* g_dispatch;
+
+size_t g_min_alloc_to_record = 0;
+size_t g_max_alloc_to_record = SIZE_MAX;
+
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
@@ -287,6 +293,23 @@ bool debug_initialize(const MallocDispatch* malloc_dispatch, bool* zygote_child,
// of different error cases.
backtrace_startup();
+ char min_alloc_to_record[10];
+ if (__system_property_get("libc.debug.malloc.minalloctorecord", min_alloc_to_record)) {
+ g_min_alloc_to_record = atoi(min_alloc_to_record);
+ }
+
+ char max_alloc_to_record[10];
+ if (__system_property_get("libc.debug.malloc.maxalloctorecord", max_alloc_to_record)) {
+ g_max_alloc_to_record = atoi(max_alloc_to_record);
+ }
+
+ if (g_min_alloc_to_record > g_max_alloc_to_record) {
+ error_log("%s: min_alloc_to_record > max_alloc_to_record!,"
+ "reverting back to default limits", getprogname());
+ g_min_alloc_to_record = 0;
+ g_max_alloc_to_record = SIZE_MAX;
+ }
+
if (g_debug->config().options() & VERBOSE) {
info_log("%s: malloc debug enabled", getprogname());
}