diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:55:28 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:55:28 +0000 |
commit | e81d9d49145e432d917eea3a70d2ae74dcad1d89 (patch) | |
tree | 9ed5e1a91f242e2cb5911577356e487a55c01b78 /source/Plugins/InstrumentationRuntime | |
parent | 85d8ef8f1f0e0e063a8571944302be2d2026f823 (diff) |
Notes
Diffstat (limited to 'source/Plugins/InstrumentationRuntime')
-rw-r--r-- | source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp | 74 | ||||
-rw-r--r-- | source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h | 48 |
2 files changed, 73 insertions, 49 deletions
diff --git a/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp b/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp index 9b72ceb71bd0..c2f1f2e95c83 100644 --- a/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp +++ b/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp @@ -66,9 +66,11 @@ AddressSanitizerRuntime::GetTypeStatic() AddressSanitizerRuntime::AddressSanitizerRuntime(const ProcessSP &process_sp) : m_is_active(false), m_runtime_module(), - m_process(process_sp), + m_process_wp(), m_breakpoint_id(0) { + if (process_sp) + m_process_wp = process_sp; } AddressSanitizerRuntime::~AddressSanitizerRuntime() @@ -78,14 +80,11 @@ AddressSanitizerRuntime::~AddressSanitizerRuntime() bool ModuleContainsASanRuntime(Module * module) { - SymbolContextList sc_list; - const bool include_symbols = true; - const bool append = true; - const bool include_inlines = true; - - size_t num_matches = module->FindFunctions(ConstString("__asan_get_alloc_stack"), NULL, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list); - - return num_matches > 0; + const Symbol* symbol = module->FindFirstSymbolWithNameAndType( + ConstString("__asan_get_alloc_stack"), + lldb::eSymbolTypeAny); + + return symbol != nullptr; } void @@ -164,7 +163,11 @@ t StructuredData::ObjectSP AddressSanitizerRuntime::RetrieveReportData() { - ThreadSP thread_sp = m_process->GetThreadList().GetSelectedThread(); + ProcessSP process_sp = GetProcessSP(); + if (!process_sp) + return StructuredData::ObjectSP(); + + ThreadSP thread_sp = process_sp->GetThreadList().GetSelectedThread(); StackFrameSP frame_sp = thread_sp->GetSelectedFrame(); if (!frame_sp) @@ -178,7 +181,7 @@ AddressSanitizerRuntime::RetrieveReportData() options.SetTimeoutUsec(RETRIEVE_REPORT_DATA_FUNCTION_TIMEOUT_USEC); ValueObjectSP return_value_sp; - if (m_process->GetTarget().EvaluateExpression(address_sanitizer_retrieve_report_data_command, frame_sp.get(), return_value_sp, options) != eExpressionCompleted) + if (process_sp->GetTarget().EvaluateExpression(address_sanitizer_retrieve_report_data_command, frame_sp.get(), return_value_sp, options) != eExpressionCompleted) return StructuredData::ObjectSP(); int present = return_value_sp->GetValueForExpressionPath(".present")->GetValueAsUnsigned(0); @@ -196,7 +199,7 @@ AddressSanitizerRuntime::RetrieveReportData() addr_t description_ptr = return_value_sp->GetValueForExpressionPath(".description")->GetValueAsUnsigned(0); std::string description; Error error; - m_process->ReadCStringFromMemory(description_ptr, description, error); + process_sp->ReadCStringFromMemory(description_ptr, description, error); StructuredData::Dictionary *dict = new StructuredData::Dictionary(); dict->AddStringItem("instrumentation_class", "AddressSanitizer"); @@ -252,27 +255,31 @@ AddressSanitizerRuntime::NotifyBreakpointHit(void *baton, StoppointCallbackConte assert (baton && "null baton"); if (!baton) return false; - + AddressSanitizerRuntime *const instance = static_cast<AddressSanitizerRuntime*>(baton); - + StructuredData::ObjectSP report = instance->RetrieveReportData(); std::string description; if (report) { description = instance->FormatDescription(report); } - ThreadSP thread = context->exe_ctx_ref.GetThreadSP(); - thread->SetStopInfo(InstrumentationRuntimeStopInfo::CreateStopReasonWithInstrumentationData(*thread, description.c_str(), report)); - - if (instance->m_process) + ProcessSP process_sp = instance->GetProcessSP(); + // Make sure this is the right process + if (process_sp && process_sp == context->exe_ctx_ref.GetProcessSP()) { - StreamFileSP stream_sp (instance->m_process->GetTarget().GetDebugger().GetOutputFile()); + ThreadSP thread_sp = context->exe_ctx_ref.GetThreadSP(); + if (thread_sp) + thread_sp->SetStopInfo(InstrumentationRuntimeStopInfo::CreateStopReasonWithInstrumentationData(*thread_sp, description.c_str(), report)); + + StreamFileSP stream_sp (process_sp->GetTarget().GetDebugger().GetOutputFile()); if (stream_sp) { stream_sp->Printf ("AddressSanitizer report breakpoint hit. Use 'thread info -s' to get extended information about the report.\n"); } + return true; // Return true to stop the target } - // Return true to stop the target, false to just let the target run. - return true; + else + return false; // Let target run } void @@ -281,6 +288,10 @@ AddressSanitizerRuntime::Activate() if (m_is_active) return; + ProcessSP process_sp = GetProcessSP(); + if (!process_sp) + return; + ConstString symbol_name ("__asan::AsanDie()"); const Symbol *symbol = m_runtime_module->FindFirstSymbolWithNameAndType (symbol_name, eSymbolTypeCode); @@ -290,7 +301,7 @@ AddressSanitizerRuntime::Activate() if (!symbol->ValueIsAddress() || !symbol->GetAddressRef().IsValid()) return; - Target &target = m_process->GetTarget(); + Target &target = process_sp->GetTarget(); addr_t symbol_address = symbol->GetAddressRef().GetOpcodeLoadAddress(&target); if (symbol_address == LLDB_INVALID_ADDRESS) @@ -298,18 +309,15 @@ AddressSanitizerRuntime::Activate() bool internal = true; bool hardware = false; - Breakpoint *breakpoint = m_process->GetTarget().CreateBreakpoint(symbol_address, internal, hardware).get(); + 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(); - if (m_process) + StreamFileSP stream_sp (process_sp->GetTarget().GetDebugger().GetOutputFile()); + if (stream_sp) { - StreamFileSP stream_sp (m_process->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"); - } + 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; @@ -320,8 +328,12 @@ AddressSanitizerRuntime::Deactivate() { if (m_breakpoint_id != LLDB_INVALID_BREAK_ID) { - m_process->GetTarget().RemoveBreakpointByID(m_breakpoint_id); - m_breakpoint_id = 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; + } } m_is_active = false; } diff --git a/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h b/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h index 69c134cbedaf..fe12ab847e76 100644 --- a/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h +++ b/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h @@ -10,6 +10,10 @@ #ifndef liblldb_AddressSanitizerRuntime_h_ #define liblldb_AddressSanitizerRuntime_h_ +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes #include "lldb/lldb-private.h" #include "lldb/Target/ABI.h" #include "lldb/Target/InstrumentationRuntime.h" @@ -21,7 +25,8 @@ namespace lldb_private { class AddressSanitizerRuntime : public lldb_private::InstrumentationRuntime { public: - + ~AddressSanitizerRuntime() override; + static lldb::InstrumentationRuntimeSP CreateInstance (const lldb::ProcessSP &process_sp); @@ -36,29 +41,37 @@ public: static lldb::InstrumentationRuntimeType GetTypeStatic(); - - virtual - ~AddressSanitizerRuntime(); - - virtual lldb_private::ConstString - GetPluginName() { return GetPluginNameStatic(); } + + lldb_private::ConstString + GetPluginName() override + { + return GetPluginNameStatic(); + } virtual lldb::InstrumentationRuntimeType GetType() { return GetTypeStatic(); } - virtual uint32_t - GetPluginVersion() { return 1; } + uint32_t + GetPluginVersion() override + { + return 1; + } - virtual void - ModulesDidLoad(lldb_private::ModuleList &module_list); + void + ModulesDidLoad(lldb_private::ModuleList &module_list) override; - virtual bool - IsActive(); + bool + IsActive() override; private: - AddressSanitizerRuntime(const lldb::ProcessSP &process_sp); - + + lldb::ProcessSP + GetProcessSP () + { + return m_process_wp.lock(); + } + void Activate(); @@ -76,11 +89,10 @@ private: bool m_is_active; lldb::ModuleSP m_runtime_module; - lldb::ProcessSP m_process; + lldb::ProcessWP m_process_wp; lldb::user_id_t m_breakpoint_id; - }; } // namespace lldb_private -#endif // liblldb_InstrumentationRuntime_h_ +#endif // liblldb_AddressSanitizerRuntime_h_ |