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/BacktraceData.cpp b/libc/malloc_debug/BacktraceData.cpp
index 3d46bf0..752d507 100644
--- a/libc/malloc_debug/BacktraceData.cpp
+++ b/libc/malloc_debug/BacktraceData.cpp
@@ -51,26 +51,26 @@
BacktraceData::BacktraceData(DebugData* debug_data, const Config& config, size_t* offset)
: OptionData(debug_data) {
- size_t hdr_len = sizeof(BacktraceHeader) + sizeof(uintptr_t) * config.backtrace_frames;
+ size_t hdr_len = sizeof(BacktraceHeader) + sizeof(uintptr_t) * config.backtrace_frames();
alloc_offset_ = *offset;
*offset += BIONIC_ALIGN(hdr_len, MINIMUM_ALIGNMENT_BYTES);
}
bool BacktraceData::Initialize(const Config& config) {
- enabled_ = config.backtrace_enabled;
- if (config.backtrace_enable_on_signal) {
+ enabled_ = config.backtrace_enabled();
+ if (config.backtrace_enable_on_signal()) {
struct sigaction enable_act;
memset(&enable_act, 0, sizeof(enable_act));
enable_act.sa_sigaction = EnableToggle;
enable_act.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK;
sigemptyset(&enable_act.sa_mask);
- if (sigaction(config.backtrace_signal, &enable_act, nullptr) != 0) {
+ if (sigaction(config.backtrace_signal(), &enable_act, nullptr) != 0) {
error_log("Unable to set up backtrace signal enable function: %s", strerror(errno));
return false;
}
info_log("%s: Run: 'kill -%d %d' to enable backtracing.", getprogname(),
- config.backtrace_signal, getpid());
+ config.backtrace_signal(), getpid());
}
return true;
}