Refactor Config from a struct to a class.
This should make it easier to add new options, and to add options that
are complex. For example, I want to modify the behavior of
record_allocs_file so that it also enables record_allocs to a default
state.
Test: All unit tests pass.
Test: Enable the backtrace option and restart.
Change-Id: Idf5cdeed06ade3bc2c8ae39d228734bf65209b4f
diff --git a/libc/malloc_debug/DebugData.cpp b/libc/malloc_debug/DebugData.cpp
index 339efdf..e9974d7 100644
--- a/libc/malloc_debug/DebugData.cpp
+++ b/libc/malloc_debug/DebugData.cpp
@@ -38,54 +38,54 @@
#include "TrackData.h"
bool DebugData::Initialize(const char* options) {
- if (!config_.Set(options)) {
+ if (!config_.Init(options)) {
return false;
}
// Check to see if the options that require a header are enabled.
- if (config_.options & HEADER_OPTIONS) {
+ 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) {
+ if (config_.options() & BACKTRACE) {
backtrace.reset(new BacktraceData(this, config_, &pointer_offset_));
if (!backtrace->Initialize(config_)) {
return false;
}
}
- if (config_.options & FRONT_GUARD) {
+ if (config_.options() & FRONT_GUARD) {
front_guard.reset(new FrontGuardData(this, config_, &pointer_offset_));
}
extra_bytes_ = pointer_offset_;
// Initialize all of the non-header data.
- if (config_.options & REAR_GUARD) {
+ if (config_.options() & REAR_GUARD) {
rear_guard.reset(new RearGuardData(this, config_));
- extra_bytes_ += config_.rear_guard_bytes;
+ extra_bytes_ += config_.rear_guard_bytes();
}
- if (config_.options & FREE_TRACK) {
+ if (config_.options() & FREE_TRACK) {
free_track.reset(new FreeTrackData(this, config_));
}
- if (config_.options & TRACK_ALLOCS) {
+ if (config_.options() & TRACK_ALLOCS) {
track.reset(new TrackData(this));
}
}
- if (config_.options & RECORD_ALLOCS) {
+ if (config_.options() & RECORD_ALLOCS) {
record.reset(new RecordData());
if (!record->Initialize(config_)) {
return false;
}
}
- if (config_.options & EXPAND_ALLOC) {
- extra_bytes_ += config_.expand_alloc_bytes;
+ if (config_.options() & EXPAND_ALLOC) {
+ extra_bytes_ += config_.expand_alloc_bytes();
}
return true;
}