vsk created this revision. vsk added reviewers: kubabrecka, k8stone. vsk added subscribers: lldb-commits, friss.
Adapters for instrumentation runtimes have to do two basic things: 1) Load a runtime library. 2) Install breakpoints in that library. This logic is duplicated in the adapters for asan and tsan. Factor it out and document bits of it to make it easier to add new adapters. I tested this with check-lldb, and double-checked testcases/functionalities/{a,t}san. https://reviews.llvm.org/D23043 Files: include/lldb/Target/InstrumentationRuntime.h source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.h source/Target/InstrumentationRuntime.cpp
Index: source/Target/InstrumentationRuntime.cpp =================================================================== --- source/Target/InstrumentationRuntime.cpp +++ source/Target/InstrumentationRuntime.cpp @@ -40,17 +40,6 @@ } } -void -InstrumentationRuntime::ModulesDidLoad(lldb_private::ModuleList &module_list) -{ -} - -bool -InstrumentationRuntime::IsActive() -{ - return false; -} - lldb::ThreadCollectionSP InstrumentationRuntime::GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info) { Index: source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.h =================================================================== --- source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.h +++ source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.h @@ -17,7 +17,6 @@ #include "lldb/lldb-private.h" #include "lldb/Target/ABI.h" #include "lldb/Target/InstrumentationRuntime.h" -#include "lldb/Target/Process.h" #include "lldb/Core/StructuredData.h" namespace lldb_private { @@ -60,26 +59,11 @@ void ModulesDidLoad(lldb_private::ModuleList &module_list) override; - bool - IsActive() override; - lldb::ThreadCollectionSP GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info) override; private: - ThreadSanitizerRuntime(const lldb::ProcessSP &process_sp); - - lldb::ProcessSP - GetProcessSP () - { - return m_process_wp.lock(); - } - - lldb::ModuleSP - GetRuntimeModuleSP () - { - return m_runtime_module_wp.lock(); - } + ThreadSanitizerRuntime(const lldb::ProcessSP &process_sp) : lldb_private::InstrumentationRuntime(process_sp) {} void Activate(); @@ -107,11 +91,6 @@ lldb::addr_t GetFirstNonInternalFramePc(StructuredData::ObjectSP trace); - - bool m_is_active; - lldb::ModuleWP m_runtime_module_wp; - lldb::ProcessWP m_process_wp; - lldb::user_id_t m_breakpoint_id; }; } // namespace lldb_private Index: source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp =================================================================== --- source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp +++ source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp @@ -68,16 +68,6 @@ return eInstrumentationRuntimeTypeThreadSanitizer; } -ThreadSanitizerRuntime::ThreadSanitizerRuntime(const ProcessSP &process_sp) : -m_is_active(false), -m_runtime_module_wp(), -m_process_wp(), -m_breakpoint_id(0) -{ - if (process_sp) - m_process_wp = process_sp; -} - ThreadSanitizerRuntime::~ThreadSanitizerRuntime() { Deactivate(); @@ -113,7 +103,7 @@ { if (ModuleContainsTSanRuntime(module_sp)) { - m_runtime_module_wp = module_sp; + SetRuntimeModuleSP(module_sp); Activate(); return false; // Stop iterating } @@ -123,12 +113,6 @@ }); } -bool -ThreadSanitizerRuntime::IsActive() -{ - return m_is_active; -} - #define RETRIEVE_REPORT_DATA_FUNCTION_TIMEOUT_USEC 2*1000*1000 const char * @@ -732,7 +716,7 @@ void ThreadSanitizerRuntime::Activate() { - if (m_is_active) + if (IsActive()) return; ProcessSP process_sp = GetProcessSP(); @@ -759,30 +743,30 @@ Breakpoint *breakpoint = process_sp->GetTarget().CreateBreakpoint(symbol_address, internal, hardware).get(); breakpoint->SetCallback (ThreadSanitizerRuntime::NotifyBreakpointHit, this, true); breakpoint->SetBreakpointKind ("thread-sanitizer-report"); - m_breakpoint_id = breakpoint->GetID(); + SetBreakpointID(breakpoint->GetID()); StreamFileSP stream_sp (process_sp->GetTarget().GetDebugger().GetOutputFile()); if (stream_sp) { stream_sp->Printf ("ThreadSanitizer debugger support is active.\n"); } - m_is_active = true; + SetActive(true); } void ThreadSanitizerRuntime::Deactivate() { - if (m_breakpoint_id != LLDB_INVALID_BREAK_ID) + if (GetBreakpointID() != LLDB_INVALID_BREAK_ID) { ProcessSP process_sp = GetProcessSP(); if (process_sp) { - process_sp->GetTarget().RemoveBreakpointByID(m_breakpoint_id); - m_breakpoint_id = LLDB_INVALID_BREAK_ID; + process_sp->GetTarget().RemoveBreakpointByID(GetBreakpointID()); + SetBreakpointID(LLDB_INVALID_BREAK_ID); } } - m_is_active = false; + SetActive(false); } static std::string Index: source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h =================================================================== --- source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h +++ source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h @@ -59,17 +59,8 @@ void ModulesDidLoad(lldb_private::ModuleList &module_list) override; - bool - IsActive() override; - private: - AddressSanitizerRuntime(const lldb::ProcessSP &process_sp); - - lldb::ProcessSP - GetProcessSP () - { - return m_process_wp.lock(); - } + AddressSanitizerRuntime(const lldb::ProcessSP &process_sp) : lldb_private::InstrumentationRuntime(process_sp) {} void Activate(); @@ -85,11 +76,6 @@ std::string FormatDescription(StructuredData::ObjectSP report); - - bool m_is_active; - lldb::ModuleSP m_runtime_module; - lldb::ProcessWP m_process_wp; - lldb::user_id_t m_breakpoint_id; }; } // namespace lldb_private Index: source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp =================================================================== --- source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp +++ source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp @@ -64,16 +64,6 @@ return eInstrumentationRuntimeTypeAddressSanitizer; } -AddressSanitizerRuntime::AddressSanitizerRuntime(const ProcessSP &process_sp) : - m_is_active(false), - m_runtime_module(), - m_process_wp(), - m_breakpoint_id(0) -{ - if (process_sp) - m_process_wp = process_sp; -} - AddressSanitizerRuntime::~AddressSanitizerRuntime() { Deactivate(); @@ -94,7 +84,7 @@ if (IsActive()) return; - if (m_runtime_module) { + if (GetRuntimeModuleSP()) { Activate(); return; } @@ -113,20 +103,14 @@ { if (ModuleContainsASanRuntime(module_pointer)) { - m_runtime_module = module_pointer->shared_from_this(); + SetRuntimeModuleSP(module_pointer->shared_from_this()); Activate(); return; } } } } -bool -AddressSanitizerRuntime::IsActive() -{ - return m_is_active; -} - #define RETRIEVE_REPORT_DATA_FUNCTION_TIMEOUT_USEC 2*1000*1000 const char * address_sanitizer_retrieve_report_data_prefix = R"( @@ -306,15 +290,15 @@ void AddressSanitizerRuntime::Activate() { - if (m_is_active) + if (IsActive()) return; ProcessSP process_sp = GetProcessSP(); if (!process_sp) return; ConstString symbol_name ("__asan::AsanDie()"); - const Symbol *symbol = m_runtime_module->FindFirstSymbolWithNameAndType (symbol_name, eSymbolTypeCode); + const Symbol *symbol = GetRuntimeModuleSP()->FindFirstSymbolWithNameAndType (symbol_name, eSymbolTypeCode); if (symbol == NULL) return; @@ -333,28 +317,28 @@ Breakpoint *breakpoint = process_sp->GetTarget().CreateBreakpoint(symbol_address, internal, hardware).get(); breakpoint->SetCallback (AddressSanitizerRuntime::NotifyBreakpointHit, this, true); breakpoint->SetBreakpointKind ("address-sanitizer-report"); - m_breakpoint_id = breakpoint->GetID(); + SetBreakpointID(breakpoint->GetID()); StreamFileSP stream_sp (process_sp->GetTarget().GetDebugger().GetOutputFile()); if (stream_sp) { stream_sp->Printf ("AddressSanitizer debugger support is active. Memory error breakpoint has been installed and you can now use the 'memory history' command.\n"); } - m_is_active = true; + SetActive(true); } void AddressSanitizerRuntime::Deactivate() { - if (m_breakpoint_id != LLDB_INVALID_BREAK_ID) + if (GetBreakpointID() != LLDB_INVALID_BREAK_ID) { ProcessSP process_sp = GetProcessSP(); if (process_sp) { - process_sp->GetTarget().RemoveBreakpointByID(m_breakpoint_id); - m_breakpoint_id = LLDB_INVALID_BREAK_ID; + process_sp->GetTarget().RemoveBreakpointByID(GetBreakpointID()); + SetBreakpointID(LLDB_INVALID_BREAK_ID); } } - m_is_active = false; + SetActive(false); } Index: include/lldb/Target/InstrumentationRuntime.h =================================================================== --- include/lldb/Target/InstrumentationRuntime.h +++ include/lldb/Target/InstrumentationRuntime.h @@ -17,6 +17,7 @@ // Other libraries and framework includes // Project includes +#include "lldb/lldb-forward.h" #include "lldb/lldb-private.h" #include "lldb/lldb-types.h" #include "lldb/Core/PluginInterface.h" @@ -30,16 +31,77 @@ public std::enable_shared_from_this<InstrumentationRuntime>, public PluginInterface { + /// The instrumented process. + lldb::ProcessWP m_process_wp; + + /// The module containing the instrumentation runtime. + lldb::ModuleSP m_runtime_module; + + /// The breakpoint in the instrumentation runtime. + lldb::user_id_t m_breakpoint_id; + + /// Indicates whether or not breakpoints have been registered in the instrumentation runtime. + bool m_is_active; + +protected: + InstrumentationRuntime(const lldb::ProcessSP &process_sp) + : m_process_wp(), m_runtime_module(), m_breakpoint_id(0), m_is_active(false) + { + if (process_sp) + m_process_wp = process_sp; + } + + lldb::ProcessSP + GetProcessSP() + { + return m_process_wp.lock(); + } + + lldb::ModuleSP + GetRuntimeModuleSP() + { + return m_runtime_module; + } + + void + SetRuntimeModuleSP(lldb::ModuleSP module_sp) + { + m_runtime_module = module_sp; + } + + lldb::user_id_t + GetBreakpointID() const + { + return m_breakpoint_id; + } + + void + SetBreakpointID(lldb::user_id_t ID) + { + m_breakpoint_id = ID; + } + + void + SetActive(bool IsActive) + { + m_is_active = IsActive; + } + public: static void ModulesDidLoad(lldb_private::ModuleList &module_list, Process *process, InstrumentationRuntimeCollection &runtimes); - + + /// Look for the instrumentation runtime in \p module_list. Register and activate the runtime if this hasn't already + /// been done. virtual void - ModulesDidLoad(lldb_private::ModuleList &module_list); - - virtual bool - IsActive(); + ModulesDidLoad(lldb_private::ModuleList &module_list) = 0; + + bool + IsActive() const + { + return m_is_active; + } virtual lldb::ThreadCollectionSP GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info);
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits