diff options
author | Christopher Ferris <cferris@google.com> | 2018-03-07 13:38:48 -0800 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2018-04-02 18:59:23 -0700 |
commit | 4da2503d70dc4bc1444454876e3794b69227d90d (patch) | |
tree | d904c750ebac96aee76df44baad1320c0db211a3 /libc/malloc_debug/DebugData.cpp | |
parent | a3f6f6c1b9135c90e410f5382b153db9a43a4db0 (diff) |
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
Diffstat (limited to 'libc/malloc_debug/DebugData.cpp')
-rw-r--r-- | libc/malloc_debug/DebugData.cpp | 47 |
1 files changed, 13 insertions, 34 deletions
diff --git a/libc/malloc_debug/DebugData.cpp b/libc/malloc_debug/DebugData.cpp index 76f8fbb1e..44c4a10d9 100644 --- a/libc/malloc_debug/DebugData.cpp +++ b/libc/malloc_debug/DebugData.cpp @@ -28,14 +28,12 @@ #include <stdint.h> -#include "BacktraceData.h" #include "Config.h" #include "DebugData.h" -#include "debug_disable.h" -#include "FreeTrackData.h" #include "GuardData.h" +#include "PointerData.h" +#include "debug_disable.h" #include "malloc_debug.h" -#include "TrackData.h" bool DebugData::Initialize(const char* options) { if (!config_.Init(options)) { @@ -44,18 +42,9 @@ bool DebugData::Initialize(const char* options) { // Check to see if the options that require a header are enabled. if (config_.options() & HEADER_OPTIONS) { - need_header_ = true; - // Initialize all of the static header offsets. pointer_offset_ = __BIONIC_ALIGN(sizeof(Header), MINIMUM_ALIGNMENT_BYTES); - if (config_.options() & BACKTRACE) { - backtrace.reset(new BacktraceData(this, config_, &pointer_offset_)); - if (!backtrace->Initialize(config_)) { - return false; - } - } - if (config_.options() & FRONT_GUARD) { front_guard.reset(new FrontGuardData(this, config_, &pointer_offset_)); } @@ -67,13 +56,12 @@ bool DebugData::Initialize(const char* options) { rear_guard.reset(new RearGuardData(this, config_)); extra_bytes_ += config_.rear_guard_bytes(); } + } - if (config_.options() & FREE_TRACK) { - free_track.reset(new FreeTrackData(this, config_)); - } - - if (config_.options() & TRACK_ALLOCS) { - track.reset(new TrackData(this)); + if (TrackPointers()) { + pointer.reset(new PointerData(this)); + if (!pointer->Initialize(config_)) { + return false; } } @@ -91,28 +79,19 @@ bool DebugData::Initialize(const char* options) { } void DebugData::PrepareFork() { - if (track != nullptr) { - track->PrepareFork(); - } - if (free_track != nullptr) { - free_track->PrepareFork(); + if (pointer != nullptr) { + pointer->PrepareFork(); } } void DebugData::PostForkParent() { - if (track != nullptr) { - track->PostForkParent(); - } - if (free_track != nullptr) { - free_track->PostForkParent(); + if (pointer != nullptr) { + pointer->PostForkParent(); } } void DebugData::PostForkChild() { - if (track != nullptr) { - track->PostForkChild(); - } - if (free_track != nullptr) { - free_track->PostForkChild(); + if (pointer != nullptr) { + pointer->PostForkChild(); } } |