Small refactor.
- Move all ScopedDisableDebugCalls into the debug_XXX calls. This avoids
any issues that might arise where every part of the code needs to properly
guard anything that might allocate. Instead everything is already guarded.
- Add a pointer to debug_data in all of the XXData classes. This avoids
calling individual functions passing in the debug_data pointer.
- Flip the NO_HEADER_OPTIONS to an explicit HEADER_OPTIONS list since fewer
options actually require a header.
- Move the extern of g_debug to the DebugData.h header.
Change-Id: Ia213a391b4a44d9ce122a709d09fe4f1b5426f36
diff --git a/libc/malloc_debug/GuardData.h b/libc/malloc_debug/GuardData.h
index 4de2702..bfb3949 100644
--- a/libc/malloc_debug/GuardData.h
+++ b/libc/malloc_debug/GuardData.h
@@ -36,14 +36,16 @@
#include <private/bionic_macros.h>
+#include "OptionData.h"
+
// Forward declarations.
class DebugData;
struct Header;
struct Config;
-class GuardData {
+class GuardData : public OptionData {
public:
- GuardData(int init_value, size_t num_bytes);
+ GuardData(DebugData* debug_data, int init_value, size_t num_bytes);
virtual ~GuardData() = default;
bool Valid(void* data) { return memcmp(data, cmp_mem_.data(), cmp_mem_.size()) == 0; }
@@ -60,12 +62,12 @@
class FrontGuardData : public GuardData {
public:
- FrontGuardData(const Config& config, size_t* offset);
+ FrontGuardData(DebugData* debug_data, const Config& config, size_t* offset);
virtual ~FrontGuardData() = default;
- bool Valid(DebugData& debug, const Header* header);
+ bool Valid(const Header* header);
- void LogFailure(DebugData& debug, const Header* header);
+ void LogFailure(const Header* header);
size_t offset() { return offset_; }
@@ -79,12 +81,12 @@
class RearGuardData : public GuardData {
public:
- RearGuardData(const Config& config);
+ RearGuardData(DebugData* debug_data, const Config& config);
virtual ~RearGuardData() = default;
- bool Valid(DebugData& debug, const Header* header);
+ bool Valid(const Header* header);
- void LogFailure(DebugData& debug, const Header* header);
+ void LogFailure(const Header* header);
private:
const char* GetTypeName() override { return "REAR"; }