summaryrefslogtreecommitdiff
path: root/libc/malloc_debug/Config.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2016-01-28 18:35:05 -0800
committerChristopher Ferris <cferris@google.com>2016-01-29 15:19:22 -0800
commit7993b80f894db20af4d1d154221c42fea6171a3d (patch)
treefc99d36000a8f0853224d75296d96509a730ee05 /libc/malloc_debug/Config.cpp
parent50647711ebaf2360aca05cc94a2fdf431c1a153e (diff)
Add better free tracking.
Included in this change: - Change the tag when a pointer is freed so it's easy to detect if an already freed pointer is being used. - Move the free backtrace out of the header. This backtrace is only used under only some circumstances, so no need to allocate space in all headers for it. - Add new option free_track_backtrace_num_frames to specify how many frames to record when the free occurs. This removes the dependency on the backtrace option to get backtraces. Bug: 26739265 Change-Id: I76f5209507dcf46af67ada162a7cb2bf282116f2
Diffstat (limited to 'libc/malloc_debug/Config.cpp')
-rw-r--r--libc/malloc_debug/Config.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/libc/malloc_debug/Config.cpp b/libc/malloc_debug/Config.cpp
index 224bb08ed..032c1fc93 100644
--- a/libc/malloc_debug/Config.cpp
+++ b/libc/malloc_debug/Config.cpp
@@ -195,9 +195,17 @@ void PropertyParser::LogUsage() {
error_log(" Instead, keep XX of these allocations around and then verify");
error_log(" that they have not been modified when the total number of freed");
error_log(" allocations exceeds the XX amount. When the program terminates,");
- error_log(" the rest of these allocations are verified.");
+ error_log(" the rest of these allocations are verified. When this option is");
+ error_log(" enabled, it automatically records the backtrace at the time of the free.");
error_log(" The default is to record 100 allocations.");
error_log("");
+ error_log(" free_track_backtrace_num_frames[=XX]");
+ error_log(" This option only has meaning if free_track is set. This indicates");
+ error_log(" how many backtrace frames to capture when an allocation is freed.");
+ error_log(" If XX is set, that is the number of frames to capture. If XX");
+ error_log(" is set to zero, then no backtrace will be captured.");
+ error_log(" The default is to record 16 frames.");
+ error_log("");
error_log(" leak_track");
error_log(" Enable the leak tracking of memory allocations.");
}
@@ -245,6 +253,7 @@ bool Config::SetFromProperties() {
front_guard_value = PropertyParser::DEFAULT_FRONT_GUARD_VALUE;
rear_guard_value = PropertyParser::DEFAULT_REAR_GUARD_VALUE;
backtrace_signal = SIGRTMIN + 10;
+ free_track_backtrace_num_frames = 16;
// Parse the options are of the format:
// option_name or option_name=XX
@@ -286,6 +295,10 @@ bool Config::SetFromProperties() {
// fill on free.
Feature("free_track", 100, 1, 16384, FREE_TRACK | FILL_ON_FREE, &this->free_track_allocations,
nullptr, false),
+ // Number of backtrace frames to keep when free_track is enabled. If this
+ // value is set to zero, no backtrace will be kept.
+ Feature("free_track_backtrace_num_frames", 16, 0, 256, 0,
+ &this->free_track_backtrace_num_frames, nullptr, false),
// Enable printing leaked allocations.
Feature("leak_track", 0, 0, 0, LEAK_TRACK | TRACK_ALLOCS, nullptr, nullptr, false),