diff options
Diffstat (limited to 'lldb/source/Plugins/InstrumentationRuntime')
9 files changed, 237 insertions, 226 deletions
diff --git a/lldb/source/Plugins/InstrumentationRuntime/ASan/ASanRuntime.cpp b/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp index 2e5dd5989e77..e78ea3a68483 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/ASan/ASanRuntime.cpp +++ b/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp @@ -1,4 +1,4 @@ -//===-- ASanRuntime.cpp -----------------------------------------*- C++ -*-===// +//===-- InstrumentationRuntimeASan.cpp ------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "ASanRuntime.h" +#include "InstrumentationRuntimeASan.h" #include "lldb/Breakpoint/StoppointCallbackContext.h" #include "lldb/Core/Debugger.h" @@ -30,40 +30,42 @@ using namespace lldb; using namespace lldb_private; +LLDB_PLUGIN_DEFINE(InstrumentationRuntimeASan) + lldb::InstrumentationRuntimeSP -AddressSanitizerRuntime::CreateInstance(const lldb::ProcessSP &process_sp) { - return InstrumentationRuntimeSP(new AddressSanitizerRuntime(process_sp)); +InstrumentationRuntimeASan::CreateInstance(const lldb::ProcessSP &process_sp) { + return InstrumentationRuntimeSP(new InstrumentationRuntimeASan(process_sp)); } -void AddressSanitizerRuntime::Initialize() { +void InstrumentationRuntimeASan::Initialize() { PluginManager::RegisterPlugin( GetPluginNameStatic(), "AddressSanitizer instrumentation runtime plugin.", CreateInstance, GetTypeStatic); } -void AddressSanitizerRuntime::Terminate() { +void InstrumentationRuntimeASan::Terminate() { PluginManager::UnregisterPlugin(CreateInstance); } -lldb_private::ConstString AddressSanitizerRuntime::GetPluginNameStatic() { +lldb_private::ConstString InstrumentationRuntimeASan::GetPluginNameStatic() { return ConstString("AddressSanitizer"); } -lldb::InstrumentationRuntimeType AddressSanitizerRuntime::GetTypeStatic() { +lldb::InstrumentationRuntimeType InstrumentationRuntimeASan::GetTypeStatic() { return eInstrumentationRuntimeTypeAddressSanitizer; } -AddressSanitizerRuntime::~AddressSanitizerRuntime() { Deactivate(); } +InstrumentationRuntimeASan::~InstrumentationRuntimeASan() { Deactivate(); } const RegularExpression & -AddressSanitizerRuntime::GetPatternForRuntimeLibrary() { +InstrumentationRuntimeASan::GetPatternForRuntimeLibrary() { // FIXME: This shouldn't include the "dylib" suffix. static RegularExpression regex( llvm::StringRef("libclang_rt.asan_(.*)_dynamic\\.dylib")); return regex; } -bool AddressSanitizerRuntime::CheckIfRuntimeIsValid( +bool InstrumentationRuntimeASan::CheckIfRuntimeIsValid( const lldb::ModuleSP module_sp) { const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType( ConstString("__asan_get_alloc_stack"), lldb::eSymbolTypeAny); @@ -108,7 +110,7 @@ t.description = __asan_get_report_description(); t )"; -StructuredData::ObjectSP AddressSanitizerRuntime::RetrieveReportData() { +StructuredData::ObjectSP InstrumentationRuntimeASan::RetrieveReportData() { ProcessSP process_sp = GetProcessSP(); if (!process_sp) return StructuredData::ObjectSP(); @@ -189,11 +191,11 @@ StructuredData::ObjectSP AddressSanitizerRuntime::RetrieveReportData() { } std::string -AddressSanitizerRuntime::FormatDescription(StructuredData::ObjectSP report) { - std::string description = report->GetAsDictionary() - ->GetValueForKey("description") - ->GetAsString() - ->GetValue(); +InstrumentationRuntimeASan::FormatDescription(StructuredData::ObjectSP report) { + std::string description = std::string(report->GetAsDictionary() + ->GetValueForKey("description") + ->GetAsString() + ->GetValue()); return llvm::StringSwitch<std::string>(description) .Case("heap-use-after-free", "Use of deallocated memory") .Case("heap-buffer-overflow", "Heap buffer overflow") @@ -235,15 +237,15 @@ AddressSanitizerRuntime::FormatDescription(StructuredData::ObjectSP report) { .Default("AddressSanitizer detected: " + description); } -bool AddressSanitizerRuntime::NotifyBreakpointHit( +bool InstrumentationRuntimeASan::NotifyBreakpointHit( void *baton, StoppointCallbackContext *context, user_id_t break_id, user_id_t break_loc_id) { assert(baton && "null baton"); if (!baton) return false; - AddressSanitizerRuntime *const instance = - static_cast<AddressSanitizerRuntime *>(baton); + InstrumentationRuntimeASan *const instance = + static_cast<InstrumentationRuntimeASan *>(baton); ProcessSP process_sp = instance->GetProcessSP(); @@ -275,7 +277,7 @@ bool AddressSanitizerRuntime::NotifyBreakpointHit( return false; // Let target run } -void AddressSanitizerRuntime::Activate() { +void InstrumentationRuntimeASan::Activate() { if (IsActive()) return; @@ -305,7 +307,7 @@ void AddressSanitizerRuntime::Activate() { process_sp->GetTarget() .CreateBreakpoint(symbol_address, internal, hardware) .get(); - breakpoint->SetCallback(AddressSanitizerRuntime::NotifyBreakpointHit, this, + breakpoint->SetCallback(InstrumentationRuntimeASan::NotifyBreakpointHit, this, true); breakpoint->SetBreakpointKind("address-sanitizer-report"); SetBreakpointID(breakpoint->GetID()); @@ -313,7 +315,7 @@ void AddressSanitizerRuntime::Activate() { SetActive(true); } -void AddressSanitizerRuntime::Deactivate() { +void InstrumentationRuntimeASan::Deactivate() { if (GetBreakpointID() != LLDB_INVALID_BREAK_ID) { ProcessSP process_sp = GetProcessSP(); if (process_sp) { diff --git a/lldb/source/Plugins/InstrumentationRuntime/ASan/ASanRuntime.h b/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.h index 0771e624ff6b..cde0a9613350 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/ASan/ASanRuntime.h +++ b/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.h @@ -1,4 +1,4 @@ -//===-- ASanRuntime.h -------------------------------------------*- C++ -*-===// +//===-- InstrumentationRuntimeASan.h ----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef liblldb_AddressSanitizerRuntime_h_ -#define liblldb_AddressSanitizerRuntime_h_ +#ifndef LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_ASAN_INSTRUMENTATIONRUNTIMEASAN_H +#define LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_ASAN_INSTRUMENTATIONRUNTIMEASAN_H #include "lldb/Target/InstrumentationRuntime.h" #include "lldb/Target/Process.h" @@ -16,9 +16,9 @@ namespace lldb_private { -class AddressSanitizerRuntime : public lldb_private::InstrumentationRuntime { +class InstrumentationRuntimeASan : public lldb_private::InstrumentationRuntime { public: - ~AddressSanitizerRuntime() override; + ~InstrumentationRuntimeASan() override; static lldb::InstrumentationRuntimeSP CreateInstance(const lldb::ProcessSP &process_sp); @@ -40,7 +40,7 @@ public: uint32_t GetPluginVersion() override { return 1; } private: - AddressSanitizerRuntime(const lldb::ProcessSP &process_sp) + InstrumentationRuntimeASan(const lldb::ProcessSP &process_sp) : lldb_private::InstrumentationRuntime(process_sp) {} const RegularExpression &GetPatternForRuntimeLibrary() override; @@ -63,4 +63,4 @@ private: } // namespace lldb_private -#endif // liblldb_AddressSanitizerRuntime_h_ +#endif // LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_ASAN_INSTRUMENTATIONRUNTIMEASAN_H diff --git a/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.cpp b/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/InstrumentationRuntimeMainThreadChecker.cpp index b73b6c095368..72d28c347457 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.cpp +++ b/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/InstrumentationRuntimeMainThreadChecker.cpp @@ -1,4 +1,4 @@ -//===-- MainThreadCheckerRuntime.cpp ----------------------------*- C++ -*-===// +//===-- InstrumentationRuntimeMainThreadChecker.cpp -----------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "MainThreadCheckerRuntime.h" +#include "InstrumentationRuntimeMainThreadChecker.h" +#include "Plugins/Process/Utility/HistoryThread.h" #include "lldb/Breakpoint/StoppointCallbackContext.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" @@ -22,47 +23,54 @@ #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Utility/RegularExpression.h" -#include "Plugins/Process/Utility/HistoryThread.h" #include <memory> using namespace lldb; using namespace lldb_private; -MainThreadCheckerRuntime::~MainThreadCheckerRuntime() { +LLDB_PLUGIN_DEFINE(InstrumentationRuntimeMainThreadChecker) + +InstrumentationRuntimeMainThreadChecker:: + ~InstrumentationRuntimeMainThreadChecker() { Deactivate(); } lldb::InstrumentationRuntimeSP -MainThreadCheckerRuntime::CreateInstance(const lldb::ProcessSP &process_sp) { - return InstrumentationRuntimeSP(new MainThreadCheckerRuntime(process_sp)); +InstrumentationRuntimeMainThreadChecker::CreateInstance( + const lldb::ProcessSP &process_sp) { + return InstrumentationRuntimeSP( + new InstrumentationRuntimeMainThreadChecker(process_sp)); } -void MainThreadCheckerRuntime::Initialize() { +void InstrumentationRuntimeMainThreadChecker::Initialize() { PluginManager::RegisterPlugin( - GetPluginNameStatic(), "MainThreadChecker instrumentation runtime plugin.", - CreateInstance, GetTypeStatic); + GetPluginNameStatic(), + "MainThreadChecker instrumentation runtime plugin.", CreateInstance, + GetTypeStatic); } -void MainThreadCheckerRuntime::Terminate() { +void InstrumentationRuntimeMainThreadChecker::Terminate() { PluginManager::UnregisterPlugin(CreateInstance); } -lldb_private::ConstString MainThreadCheckerRuntime::GetPluginNameStatic() { +lldb_private::ConstString +InstrumentationRuntimeMainThreadChecker::GetPluginNameStatic() { return ConstString("MainThreadChecker"); } -lldb::InstrumentationRuntimeType MainThreadCheckerRuntime::GetTypeStatic() { +lldb::InstrumentationRuntimeType +InstrumentationRuntimeMainThreadChecker::GetTypeStatic() { return eInstrumentationRuntimeTypeMainThreadChecker; } const RegularExpression & -MainThreadCheckerRuntime::GetPatternForRuntimeLibrary() { +InstrumentationRuntimeMainThreadChecker::GetPatternForRuntimeLibrary() { static RegularExpression regex(llvm::StringRef("libMainThreadChecker.dylib")); return regex; } -bool MainThreadCheckerRuntime::CheckIfRuntimeIsValid( +bool InstrumentationRuntimeMainThreadChecker::CheckIfRuntimeIsValid( const lldb::ModuleSP module_sp) { static ConstString test_sym("__main_thread_checker_on_report"); const Symbol *symbol = @@ -71,7 +79,8 @@ bool MainThreadCheckerRuntime::CheckIfRuntimeIsValid( } StructuredData::ObjectSP -MainThreadCheckerRuntime::RetrieveReportData(ExecutionContextRef exe_ctx_ref) { +InstrumentationRuntimeMainThreadChecker::RetrieveReportData( + ExecutionContextRef exe_ctx_ref) { ProcessSP process_sp = GetProcessSP(); if (!process_sp) return StructuredData::ObjectSP(); @@ -148,15 +157,15 @@ MainThreadCheckerRuntime::RetrieveReportData(ExecutionContextRef exe_ctx_ref) { return dict_sp; } -bool MainThreadCheckerRuntime::NotifyBreakpointHit( +bool InstrumentationRuntimeMainThreadChecker::NotifyBreakpointHit( void *baton, StoppointCallbackContext *context, user_id_t break_id, user_id_t break_loc_id) { assert(baton && "null baton"); if (!baton) return false; ///< false => resume execution. - MainThreadCheckerRuntime *const instance = - static_cast<MainThreadCheckerRuntime *>(baton); + InstrumentationRuntimeMainThreadChecker *const instance = + static_cast<InstrumentationRuntimeMainThreadChecker *>(baton); ProcessSP process_sp = instance->GetProcessSP(); ThreadSP thread_sp = context->exe_ctx_ref.GetThreadSP(); @@ -171,10 +180,10 @@ bool MainThreadCheckerRuntime::NotifyBreakpointHit( instance->RetrieveReportData(context->exe_ctx_ref); if (report) { - std::string description = report->GetAsDictionary() - ->GetValueForKey("description") - ->GetAsString() - ->GetValue(); + std::string description = std::string(report->GetAsDictionary() + ->GetValueForKey("description") + ->GetAsString() + ->GetValue()); thread_sp->SetStopInfo( InstrumentationRuntimeStopInfo::CreateStopReasonWithInstrumentationData( *thread_sp, description, report)); @@ -184,7 +193,7 @@ bool MainThreadCheckerRuntime::NotifyBreakpointHit( return false; } -void MainThreadCheckerRuntime::Activate() { +void InstrumentationRuntimeMainThreadChecker::Activate() { if (IsActive()) return; @@ -215,15 +224,15 @@ void MainThreadCheckerRuntime::Activate() { .CreateBreakpoint(symbol_address, /*internal=*/true, /*hardware=*/false) .get(); - breakpoint->SetCallback(MainThreadCheckerRuntime::NotifyBreakpointHit, this, - true); + breakpoint->SetCallback( + InstrumentationRuntimeMainThreadChecker::NotifyBreakpointHit, this, true); breakpoint->SetBreakpointKind("main-thread-checker-report"); SetBreakpointID(breakpoint->GetID()); SetActive(true); } -void MainThreadCheckerRuntime::Deactivate() { +void InstrumentationRuntimeMainThreadChecker::Deactivate() { SetActive(false); auto BID = GetBreakpointID(); @@ -237,7 +246,7 @@ void MainThreadCheckerRuntime::Deactivate() { } lldb::ThreadCollectionSP -MainThreadCheckerRuntime::GetBacktracesFromExtendedStopInfo( +InstrumentationRuntimeMainThreadChecker::GetBacktracesFromExtendedStopInfo( StructuredData::ObjectSP info) { ThreadCollectionSP threads; threads = std::make_shared<ThreadCollection>(); @@ -245,7 +254,7 @@ MainThreadCheckerRuntime::GetBacktracesFromExtendedStopInfo( ProcessSP process_sp = GetProcessSP(); if (info->GetObjectForDotSeparatedPath("instrumentation_class") - ->GetStringValue() != "MainThreadChecker") + ->GetStringValue() != "MainThreadChecker") return threads; std::vector<lldb::addr_t> PCs; diff --git a/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/InstrumentationRuntimeMainThreadChecker.h b/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/InstrumentationRuntimeMainThreadChecker.h new file mode 100644 index 000000000000..1435ae8d367f --- /dev/null +++ b/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/InstrumentationRuntimeMainThreadChecker.h @@ -0,0 +1,68 @@ +//===-- InstrumentationRuntimeMainThreadChecker.h----------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_MAINTHREADCHECKER_INSTRUMENTATIONRUNTIMEMAINTHREADCHECKER_H +#define LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_MAINTHREADCHECKER_INSTRUMENTATIONRUNTIMEMAINTHREADCHECKER_H + +#include "lldb/Target/ABI.h" +#include "lldb/Target/InstrumentationRuntime.h" +#include "lldb/Utility/StructuredData.h" +#include "lldb/lldb-private.h" + +namespace lldb_private { + +class InstrumentationRuntimeMainThreadChecker + : public lldb_private::InstrumentationRuntime { +public: + ~InstrumentationRuntimeMainThreadChecker() override; + + static lldb::InstrumentationRuntimeSP + CreateInstance(const lldb::ProcessSP &process_sp); + + static void Initialize(); + + static void Terminate(); + + static lldb_private::ConstString GetPluginNameStatic(); + + static lldb::InstrumentationRuntimeType GetTypeStatic(); + + lldb_private::ConstString GetPluginName() override { + return GetPluginNameStatic(); + } + + virtual lldb::InstrumentationRuntimeType GetType() { return GetTypeStatic(); } + + uint32_t GetPluginVersion() override { return 1; } + + lldb::ThreadCollectionSP + GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info) override; + +private: + InstrumentationRuntimeMainThreadChecker(const lldb::ProcessSP &process_sp) + : lldb_private::InstrumentationRuntime(process_sp) {} + + const RegularExpression &GetPatternForRuntimeLibrary() override; + + bool CheckIfRuntimeIsValid(const lldb::ModuleSP module_sp) override; + + void Activate() override; + + void Deactivate(); + + static bool NotifyBreakpointHit(void *baton, + StoppointCallbackContext *context, + lldb::user_id_t break_id, + lldb::user_id_t break_loc_id); + + StructuredData::ObjectSP RetrieveReportData(ExecutionContextRef exe_ctx_ref); +}; + +} // namespace lldb_private + +#endif // LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_MAINTHREADCHECKER_INSTRUMENTATIONRUNTIMEMAINTHREADCHECKER_H diff --git a/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.h b/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.h deleted file mode 100644 index 1dcbc0f6bc89..000000000000 --- a/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.h +++ /dev/null @@ -1,67 +0,0 @@ -//===-- MainThreadCheckerRuntime.h ------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef liblldb_MainThreadCheckerRuntime_h_ -#define liblldb_MainThreadCheckerRuntime_h_ - -#include "lldb/Target/ABI.h" -#include "lldb/Target/InstrumentationRuntime.h" -#include "lldb/Utility/StructuredData.h" -#include "lldb/lldb-private.h" - -namespace lldb_private { - - class MainThreadCheckerRuntime : public lldb_private::InstrumentationRuntime { - public: - ~MainThreadCheckerRuntime() override; - - static lldb::InstrumentationRuntimeSP - CreateInstance(const lldb::ProcessSP &process_sp); - - static void Initialize(); - - static void Terminate(); - - static lldb_private::ConstString GetPluginNameStatic(); - - static lldb::InstrumentationRuntimeType GetTypeStatic(); - - lldb_private::ConstString GetPluginName() override { - return GetPluginNameStatic(); - } - - virtual lldb::InstrumentationRuntimeType GetType() { return GetTypeStatic(); } - - uint32_t GetPluginVersion() override { return 1; } - - lldb::ThreadCollectionSP - GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info) override; - - private: - MainThreadCheckerRuntime(const lldb::ProcessSP &process_sp) - : lldb_private::InstrumentationRuntime(process_sp) {} - - const RegularExpression &GetPatternForRuntimeLibrary() override; - - bool CheckIfRuntimeIsValid(const lldb::ModuleSP module_sp) override; - - void Activate() override; - - void Deactivate(); - - static bool NotifyBreakpointHit(void *baton, - StoppointCallbackContext *context, - lldb::user_id_t break_id, - lldb::user_id_t break_loc_id); - - StructuredData::ObjectSP RetrieveReportData(ExecutionContextRef exe_ctx_ref); - }; - -} // namespace lldb_private - -#endif // liblldb_MainThreadCheckerRuntime_h_ diff --git a/lldb/source/Plugins/InstrumentationRuntime/TSan/TSanRuntime.cpp b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp index 45a3aeeb204e..50f0faefa0f4 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/TSan/TSanRuntime.cpp +++ b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp @@ -1,4 +1,4 @@ -//===-- TSanRuntime.cpp -----------------------------------------*- C++ -*-===// +//===-- InstrumentationRuntimeTSan.cpp ------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "TSanRuntime.h" +#include "InstrumentationRuntimeTSan.h" #include "Plugins/Process/Utility/HistoryThread.h" #include "lldb/Breakpoint/StoppointCallbackContext.h" @@ -35,30 +35,32 @@ using namespace lldb; using namespace lldb_private; +LLDB_PLUGIN_DEFINE(InstrumentationRuntimeTSan) + lldb::InstrumentationRuntimeSP -ThreadSanitizerRuntime::CreateInstance(const lldb::ProcessSP &process_sp) { - return InstrumentationRuntimeSP(new ThreadSanitizerRuntime(process_sp)); +InstrumentationRuntimeTSan::CreateInstance(const lldb::ProcessSP &process_sp) { + return InstrumentationRuntimeSP(new InstrumentationRuntimeTSan(process_sp)); } -void ThreadSanitizerRuntime::Initialize() { +void InstrumentationRuntimeTSan::Initialize() { PluginManager::RegisterPlugin( GetPluginNameStatic(), "ThreadSanitizer instrumentation runtime plugin.", CreateInstance, GetTypeStatic); } -void ThreadSanitizerRuntime::Terminate() { +void InstrumentationRuntimeTSan::Terminate() { PluginManager::UnregisterPlugin(CreateInstance); } -lldb_private::ConstString ThreadSanitizerRuntime::GetPluginNameStatic() { +lldb_private::ConstString InstrumentationRuntimeTSan::GetPluginNameStatic() { return ConstString("ThreadSanitizer"); } -lldb::InstrumentationRuntimeType ThreadSanitizerRuntime::GetTypeStatic() { +lldb::InstrumentationRuntimeType InstrumentationRuntimeTSan::GetTypeStatic() { return eInstrumentationRuntimeTypeThreadSanitizer; } -ThreadSanitizerRuntime::~ThreadSanitizerRuntime() { Deactivate(); } +InstrumentationRuntimeTSan::~InstrumentationRuntimeTSan() { Deactivate(); } const char *thread_sanitizer_retrieve_report_data_prefix = R"( extern "C" @@ -84,7 +86,7 @@ extern "C" int *running, const char **name, int *parent_tid, void **trace, unsigned long trace_size); int __tsan_get_report_unique_tid(void *report, unsigned long idx, int *tid); - + // TODO: dlsym won't work on Windows. void *dlsym(void* handle, const char* symbol); int (*ptr__tsan_get_report_loc_object_type)(void *report, unsigned long idx, const char **object_type); @@ -97,15 +99,15 @@ struct data { void *report; const char *description; int report_count; - + void *sleep_trace[REPORT_TRACE_SIZE]; - + int stack_count; struct { int idx; void *trace[REPORT_TRACE_SIZE]; } stacks[REPORT_ARRAY_SIZE]; - + int mop_count; struct { int idx; @@ -116,7 +118,7 @@ struct data { void *addr; void *trace[REPORT_TRACE_SIZE]; } mops[REPORT_ARRAY_SIZE]; - + int loc_count; struct { int idx; @@ -130,7 +132,7 @@ struct data { void *trace[REPORT_TRACE_SIZE]; const char *object_type; } locs[REPORT_ARRAY_SIZE]; - + int mutex_count; struct { int idx; @@ -139,7 +141,7 @@ struct data { int destroyed; void *trace[REPORT_TRACE_SIZE]; } mutexes[REPORT_ARRAY_SIZE]; - + int thread_count; struct { int idx; @@ -150,7 +152,7 @@ struct data { int parent_tid; void *trace[REPORT_TRACE_SIZE]; } threads[REPORT_ARRAY_SIZE]; - + int unique_tid_count; struct { int idx; @@ -299,8 +301,8 @@ static user_id_t Renumber(uint64_t id, return IT->second; } -StructuredData::ObjectSP -ThreadSanitizerRuntime::RetrieveReportData(ExecutionContextRef exe_ctx_ref) { +StructuredData::ObjectSP InstrumentationRuntimeTSan::RetrieveReportData( + ExecutionContextRef exe_ctx_ref) { ProcessSP process_sp = GetProcessSP(); if (!process_sp) return StructuredData::ObjectSP(); @@ -486,11 +488,11 @@ ThreadSanitizerRuntime::RetrieveReportData(ExecutionContextRef exe_ctx_ref) { } std::string -ThreadSanitizerRuntime::FormatDescription(StructuredData::ObjectSP report) { - std::string description = report->GetAsDictionary() - ->GetValueForKey("issue_type") - ->GetAsString() - ->GetValue(); +InstrumentationRuntimeTSan::FormatDescription(StructuredData::ObjectSP report) { + std::string description = std::string(report->GetAsDictionary() + ->GetValueForKey("issue_type") + ->GetAsString() + ->GetValue()); if (description == "data-race") { return "Data race"; @@ -536,7 +538,7 @@ static std::string Sprintf(const char *format, ...) { va_start(args, format); s.PrintfVarArg(format, args); va_end(args); - return s.GetString(); + return std::string(s.GetString()); } static std::string GetSymbolNameFromAddress(ProcessSP process_sp, addr_t addr) { @@ -564,15 +566,14 @@ static void GetSymbolDeclarationFromAddress(ProcessSP process_sp, addr_t addr, if (!symbol) return; - ConstString sym_name = symbol->GetMangled().GetName( - lldb::eLanguageTypeUnknown, Mangled::ePreferMangled); + ConstString sym_name = symbol->GetMangled().GetName(Mangled::ePreferMangled); ModuleSP module = symbol->CalculateSymbolContextModule(); if (!module) return; VariableList var_list; - module->FindGlobalVariables(sym_name, nullptr, 1U, var_list); + module->FindGlobalVariables(sym_name, CompilerDeclContext(), 1U, var_list); if (var_list.GetSize() < 1) return; @@ -580,7 +581,7 @@ static void GetSymbolDeclarationFromAddress(ProcessSP process_sp, addr_t addr, decl = var->GetDeclaration(); } -addr_t ThreadSanitizerRuntime::GetFirstNonInternalFramePc( +addr_t InstrumentationRuntimeTSan::GetFirstNonInternalFramePc( StructuredData::ObjectSP trace, bool skip_one_frame) { ProcessSP process_sp = GetProcessSP(); ModuleSP runtime_module_sp = GetRuntimeModuleSP(); @@ -609,13 +610,13 @@ addr_t ThreadSanitizerRuntime::GetFirstNonInternalFramePc( } std::string -ThreadSanitizerRuntime::GenerateSummary(StructuredData::ObjectSP report) { +InstrumentationRuntimeTSan::GenerateSummary(StructuredData::ObjectSP report) { ProcessSP process_sp = GetProcessSP(); - std::string summary = report->GetAsDictionary() - ->GetValueForKey("description") - ->GetAsString() - ->GetValue(); + std::string summary = std::string(report->GetAsDictionary() + ->GetValueForKey("description") + ->GetAsString() + ->GetValue()); bool skip_one_frame = report->GetObjectForDotSeparatedPath("issue_type")->GetStringValue() == "external-race"; @@ -657,10 +658,10 @@ ThreadSanitizerRuntime::GenerateSummary(StructuredData::ObjectSP report) { ->GetValueForKey("locs") ->GetAsArray() ->GetItemAtIndex(0); - std::string object_type = loc->GetAsDictionary() - ->GetValueForKey("object_type") - ->GetAsString() - ->GetValue(); + std::string object_type = std::string(loc->GetAsDictionary() + ->GetValueForKey("object_type") + ->GetAsString() + ->GetValue()); if (!object_type.empty()) { summary = "Race on " + object_type + " object"; } @@ -695,8 +696,8 @@ ThreadSanitizerRuntime::GenerateSummary(StructuredData::ObjectSP report) { return summary; } -addr_t -ThreadSanitizerRuntime::GetMainRacyAddress(StructuredData::ObjectSP report) { +addr_t InstrumentationRuntimeTSan::GetMainRacyAddress( + StructuredData::ObjectSP report) { addr_t result = (addr_t)-1; report->GetObjectForDotSeparatedPath("mops")->GetAsArray()->ForEach( @@ -711,7 +712,7 @@ ThreadSanitizerRuntime::GetMainRacyAddress(StructuredData::ObjectSP report) { return (result == (addr_t)-1) ? 0 : result; } -std::string ThreadSanitizerRuntime::GetLocationDescription( +std::string InstrumentationRuntimeTSan::GetLocationDescription( StructuredData::ObjectSP report, addr_t &global_addr, std::string &global_name, std::string &filename, uint32_t &line) { std::string result = ""; @@ -726,8 +727,8 @@ std::string ThreadSanitizerRuntime::GetLocationDescription( ->GetValueForKey("locs") ->GetAsArray() ->GetItemAtIndex(0); - std::string type = - loc->GetAsDictionary()->GetValueForKey("type")->GetStringValue(); + std::string type = std::string( + loc->GetAsDictionary()->GetValueForKey("type")->GetStringValue()); if (type == "global") { global_addr = loc->GetAsDictionary() ->GetValueForKey("address") @@ -756,10 +757,10 @@ std::string ThreadSanitizerRuntime::GetLocationDescription( ->GetValueForKey("size") ->GetAsInteger() ->GetValue(); - std::string object_type = loc->GetAsDictionary() - ->GetValueForKey("object_type") - ->GetAsString() - ->GetValue(); + std::string object_type = std::string(loc->GetAsDictionary() + ->GetValueForKey("object_type") + ->GetAsString() + ->GetValue()); if (!object_type.empty()) { result = Sprintf("Location is a %ld-byte %s object at 0x%llx", size, object_type.c_str(), addr); @@ -791,15 +792,15 @@ std::string ThreadSanitizerRuntime::GetLocationDescription( return result; } -bool ThreadSanitizerRuntime::NotifyBreakpointHit( +bool InstrumentationRuntimeTSan::NotifyBreakpointHit( void *baton, StoppointCallbackContext *context, user_id_t break_id, user_id_t break_loc_id) { assert(baton && "null baton"); if (!baton) return false; - ThreadSanitizerRuntime *const instance = - static_cast<ThreadSanitizerRuntime *>(baton); + InstrumentationRuntimeTSan *const instance = + static_cast<InstrumentationRuntimeTSan *>(baton); ProcessSP process_sp = instance->GetProcessSP(); @@ -873,12 +874,13 @@ bool ThreadSanitizerRuntime::NotifyBreakpointHit( return false; // Let target run } -const RegularExpression &ThreadSanitizerRuntime::GetPatternForRuntimeLibrary() { +const RegularExpression & +InstrumentationRuntimeTSan::GetPatternForRuntimeLibrary() { static RegularExpression regex(llvm::StringRef("libclang_rt.tsan_")); return regex; } -bool ThreadSanitizerRuntime::CheckIfRuntimeIsValid( +bool InstrumentationRuntimeTSan::CheckIfRuntimeIsValid( const lldb::ModuleSP module_sp) { static ConstString g_tsan_get_current_report("__tsan_get_current_report"); const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType( @@ -886,7 +888,7 @@ bool ThreadSanitizerRuntime::CheckIfRuntimeIsValid( return symbol != nullptr; } -void ThreadSanitizerRuntime::Activate() { +void InstrumentationRuntimeTSan::Activate() { if (IsActive()) return; @@ -916,7 +918,7 @@ void ThreadSanitizerRuntime::Activate() { process_sp->GetTarget() .CreateBreakpoint(symbol_address, internal, hardware) .get(); - breakpoint->SetCallback(ThreadSanitizerRuntime::NotifyBreakpointHit, this, + breakpoint->SetCallback(InstrumentationRuntimeTSan::NotifyBreakpointHit, this, true); breakpoint->SetBreakpointKind("thread-sanitizer-report"); SetBreakpointID(breakpoint->GetID()); @@ -924,7 +926,7 @@ void ThreadSanitizerRuntime::Activate() { SetActive(true); } -void ThreadSanitizerRuntime::Deactivate() { +void InstrumentationRuntimeTSan::Deactivate() { if (GetBreakpointID() != LLDB_INVALID_BREAK_ID) { ProcessSP process_sp = GetProcessSP(); if (process_sp) { @@ -977,8 +979,8 @@ static std::string GenerateThreadName(const std::string &path, } if (path == "locs") { - std::string type = - o->GetAsDictionary()->GetValueForKey("type")->GetStringValue(); + std::string type = std::string( + o->GetAsDictionary()->GetValueForKey("type")->GetStringValue()); int thread_id = o->GetObjectForDotSeparatedPath("thread_id")->GetIntegerValue(); int fd = @@ -1043,7 +1045,7 @@ static void AddThreadsForPath(const std::string &path, } lldb::ThreadCollectionSP -ThreadSanitizerRuntime::GetBacktracesFromExtendedStopInfo( +InstrumentationRuntimeTSan::GetBacktracesFromExtendedStopInfo( StructuredData::ObjectSP info) { ThreadCollectionSP threads; threads = std::make_shared<ThreadCollection>(); diff --git a/lldb/source/Plugins/InstrumentationRuntime/TSan/TSanRuntime.h b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.h index db8bb1db7996..35a878d90aff 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/TSan/TSanRuntime.h +++ b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.h @@ -1,4 +1,4 @@ -//===-- TSanRuntime.h -------------------------------------------*- C++ -*-===// +//===-- InstrumentationRuntimeTSan.h ----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef liblldb_ThreadSanitizerRuntime_h_ -#define liblldb_ThreadSanitizerRuntime_h_ +#ifndef LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_TSAN_INSTRUMENTATIONRUNTIMETSAN_H +#define LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_TSAN_INSTRUMENTATIONRUNTIMETSAN_H #include "lldb/Target/ABI.h" #include "lldb/Target/InstrumentationRuntime.h" @@ -16,9 +16,9 @@ namespace lldb_private { -class ThreadSanitizerRuntime : public lldb_private::InstrumentationRuntime { +class InstrumentationRuntimeTSan : public lldb_private::InstrumentationRuntime { public: - ~ThreadSanitizerRuntime() override; + ~InstrumentationRuntimeTSan() override; static lldb::InstrumentationRuntimeSP CreateInstance(const lldb::ProcessSP &process_sp); @@ -43,7 +43,7 @@ public: GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info) override; private: - ThreadSanitizerRuntime(const lldb::ProcessSP &process_sp) + InstrumentationRuntimeTSan(const lldb::ProcessSP &process_sp) : lldb_private::InstrumentationRuntime(process_sp) {} const RegularExpression &GetPatternForRuntimeLibrary() override; @@ -78,4 +78,4 @@ private: } // namespace lldb_private -#endif // liblldb_ThreadSanitizerRuntime_h_ +#endif // LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_TSAN_INSTRUMENTATIONRUNTIMETSAN_H diff --git a/lldb/source/Plugins/InstrumentationRuntime/UBSan/UBSanRuntime.cpp b/lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp index 137ecab224bc..b60eb53f3d4a 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/UBSan/UBSanRuntime.cpp +++ b/lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp @@ -1,4 +1,4 @@ -//===-- UBSanRuntime.cpp ----------------------------------------*- C++ -*-===// +//===-- InstrumentationRuntimeUBSan.cpp -----------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "UBSanRuntime.h" +#include "InstrumentationRuntimeUBSan.h" #include "Plugins/Process/Utility/HistoryThread.h" #include "lldb/Breakpoint/StoppointCallbackContext.h" @@ -36,35 +36,31 @@ using namespace lldb; using namespace lldb_private; -UndefinedBehaviorSanitizerRuntime::~UndefinedBehaviorSanitizerRuntime() { - Deactivate(); -} +LLDB_PLUGIN_DEFINE(InstrumentationRuntimeUBSan) + +InstrumentationRuntimeUBSan::~InstrumentationRuntimeUBSan() { Deactivate(); } lldb::InstrumentationRuntimeSP -UndefinedBehaviorSanitizerRuntime::CreateInstance( - const lldb::ProcessSP &process_sp) { - return InstrumentationRuntimeSP( - new UndefinedBehaviorSanitizerRuntime(process_sp)); +InstrumentationRuntimeUBSan::CreateInstance(const lldb::ProcessSP &process_sp) { + return InstrumentationRuntimeSP(new InstrumentationRuntimeUBSan(process_sp)); } -void UndefinedBehaviorSanitizerRuntime::Initialize() { +void InstrumentationRuntimeUBSan::Initialize() { PluginManager::RegisterPlugin( GetPluginNameStatic(), "UndefinedBehaviorSanitizer instrumentation runtime plugin.", CreateInstance, GetTypeStatic); } -void UndefinedBehaviorSanitizerRuntime::Terminate() { +void InstrumentationRuntimeUBSan::Terminate() { PluginManager::UnregisterPlugin(CreateInstance); } -lldb_private::ConstString -UndefinedBehaviorSanitizerRuntime::GetPluginNameStatic() { +lldb_private::ConstString InstrumentationRuntimeUBSan::GetPluginNameStatic() { return ConstString("UndefinedBehaviorSanitizer"); } -lldb::InstrumentationRuntimeType -UndefinedBehaviorSanitizerRuntime::GetTypeStatic() { +lldb::InstrumentationRuntimeType InstrumentationRuntimeUBSan::GetTypeStatic() { return eInstrumentationRuntimeTypeUndefinedBehaviorSanitizer; } @@ -110,7 +106,7 @@ static std::string RetrieveString(ValueObjectSP return_value_sp, return str; } -StructuredData::ObjectSP UndefinedBehaviorSanitizerRuntime::RetrieveReportData( +StructuredData::ObjectSP InstrumentationRuntimeUBSan::RetrieveReportData( ExecutionContextRef exe_ctx_ref) { ProcessSP process_sp = GetProcessSP(); if (!process_sp) @@ -187,9 +183,10 @@ StructuredData::ObjectSP UndefinedBehaviorSanitizerRuntime::RetrieveReportData( static std::string GetStopReasonDescription(StructuredData::ObjectSP report) { llvm::StringRef stop_reason_description_ref; - report->GetAsDictionary()->GetValueForKeyAsString("description", - stop_reason_description_ref); - std::string stop_reason_description = stop_reason_description_ref; + report->GetAsDictionary()->GetValueForKeyAsString( + "description", stop_reason_description_ref); + std::string stop_reason_description = + std::string(stop_reason_description_ref); if (!stop_reason_description.size()) { stop_reason_description = "Undefined behavior detected"; @@ -202,15 +199,15 @@ static std::string GetStopReasonDescription(StructuredData::ObjectSP report) { return stop_reason_description; } -bool UndefinedBehaviorSanitizerRuntime::NotifyBreakpointHit( +bool InstrumentationRuntimeUBSan::NotifyBreakpointHit( void *baton, StoppointCallbackContext *context, user_id_t break_id, user_id_t break_loc_id) { assert(baton && "null baton"); if (!baton) return false; ///< false => resume execution. - UndefinedBehaviorSanitizerRuntime *const instance = - static_cast<UndefinedBehaviorSanitizerRuntime *>(baton); + InstrumentationRuntimeUBSan *const instance = + static_cast<InstrumentationRuntimeUBSan *>(baton); ProcessSP process_sp = instance->GetProcessSP(); ThreadSP thread_sp = context->exe_ctx_ref.GetThreadSP(); @@ -235,12 +232,12 @@ bool UndefinedBehaviorSanitizerRuntime::NotifyBreakpointHit( } const RegularExpression & -UndefinedBehaviorSanitizerRuntime::GetPatternForRuntimeLibrary() { +InstrumentationRuntimeUBSan::GetPatternForRuntimeLibrary() { static RegularExpression regex(llvm::StringRef("libclang_rt\\.(a|t|ub)san_")); return regex; } -bool UndefinedBehaviorSanitizerRuntime::CheckIfRuntimeIsValid( +bool InstrumentationRuntimeUBSan::CheckIfRuntimeIsValid( const lldb::ModuleSP module_sp) { static ConstString ubsan_test_sym("__ubsan_on_report"); const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType( @@ -249,7 +246,7 @@ bool UndefinedBehaviorSanitizerRuntime::CheckIfRuntimeIsValid( } // FIXME: Factor out all the logic we have in common with the {a,t}san plugins. -void UndefinedBehaviorSanitizerRuntime::Activate() { +void InstrumentationRuntimeUBSan::Activate() { if (IsActive()) return; @@ -280,15 +277,15 @@ void UndefinedBehaviorSanitizerRuntime::Activate() { .CreateBreakpoint(symbol_address, /*internal=*/true, /*hardware=*/false) .get(); - breakpoint->SetCallback( - UndefinedBehaviorSanitizerRuntime::NotifyBreakpointHit, this, true); + breakpoint->SetCallback(InstrumentationRuntimeUBSan::NotifyBreakpointHit, + this, true); breakpoint->SetBreakpointKind("undefined-behavior-sanitizer-report"); SetBreakpointID(breakpoint->GetID()); SetActive(true); } -void UndefinedBehaviorSanitizerRuntime::Deactivate() { +void InstrumentationRuntimeUBSan::Deactivate() { SetActive(false); auto BID = GetBreakpointID(); @@ -302,7 +299,7 @@ void UndefinedBehaviorSanitizerRuntime::Deactivate() { } lldb::ThreadCollectionSP -UndefinedBehaviorSanitizerRuntime::GetBacktracesFromExtendedStopInfo( +InstrumentationRuntimeUBSan::GetBacktracesFromExtendedStopInfo( StructuredData::ObjectSP info) { ThreadCollectionSP threads; threads = std::make_shared<ThreadCollection>(); diff --git a/lldb/source/Plugins/InstrumentationRuntime/UBSan/UBSanRuntime.h b/lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.h index 1d854b7bf06f..813c30069600 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/UBSan/UBSanRuntime.h +++ b/lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.h @@ -1,4 +1,4 @@ -//===-- UBSanRuntime.h ------------------------------------------*- C++ -*-===// +//===-- InstrumentationRuntimeUBSan.h ---------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef liblldb_UndefinedBehaviorSanitizerRuntime_h_ -#define liblldb_UndefinedBehaviorSanitizerRuntime_h_ +#ifndef LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_UBSAN_INSTRUMENTATIONRUNTIMEUBSAN_H +#define LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_UBSAN_INSTRUMENTATIONRUNTIMEUBSAN_H #include "lldb/Target/ABI.h" #include "lldb/Target/InstrumentationRuntime.h" @@ -16,10 +16,10 @@ namespace lldb_private { -class UndefinedBehaviorSanitizerRuntime +class InstrumentationRuntimeUBSan : public lldb_private::InstrumentationRuntime { public: - ~UndefinedBehaviorSanitizerRuntime() override; + ~InstrumentationRuntimeUBSan() override; static lldb::InstrumentationRuntimeSP CreateInstance(const lldb::ProcessSP &process_sp); @@ -44,7 +44,7 @@ public: GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info) override; private: - UndefinedBehaviorSanitizerRuntime(const lldb::ProcessSP &process_sp) + InstrumentationRuntimeUBSan(const lldb::ProcessSP &process_sp) : lldb_private::InstrumentationRuntime(process_sp) {} const RegularExpression &GetPatternForRuntimeLibrary() override; @@ -65,4 +65,4 @@ private: } // namespace lldb_private -#endif // liblldb_UndefinedBehaviorSanitizerRuntime_h_ +#endif // LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_UBSAN_INSTRUMENTATIONRUNTIMEUBSAN_H |