diff options
Diffstat (limited to 'lldb/source/Plugins/InstrumentationRuntime/TSan')
-rw-r--r-- | lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp (renamed from lldb/source/Plugins/InstrumentationRuntime/TSan/TSanRuntime.cpp) | 118 | ||||
-rw-r--r-- | lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.h (renamed from lldb/source/Plugins/InstrumentationRuntime/TSan/TSanRuntime.h) | 14 |
2 files changed, 67 insertions, 65 deletions
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 |