diff --git a/lldb/source/API/SystemInitializerFull.cpp b/lldb/source/API/SystemInitializerFull.cpp index 799f894375ab..720f1aad744b 100644 --- a/lldb/source/API/SystemInitializerFull.cpp +++ b/lldb/source/API/SystemInitializerFull.cpp @@ -55,7 +55,7 @@ #include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h" #include "Plugins/Instruction/PPC64/EmulateInstructionPPC64.h" #include "Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.h" -#include "Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.h" +#include "Plugins/InstrumentationRuntime/MainThreadChecker/InstrumentationRuntimeMainThreadChecker.h" #include "Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.h" #include "Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.h" #include "Plugins/JITLoader/GDB/JITLoaderGDB.h" @@ -225,7 +225,7 @@ llvm::Error SystemInitializerFull::Initialize() { InstrumentationRuntimeASan::Initialize(); InstrumentationRuntimeTSan::Initialize(); InstrumentationRuntimeUBSan::Initialize(); - MainThreadCheckerRuntime::Initialize(); + InstrumentationRuntimeMainThreadChecker::Initialize(); SymbolVendorELF::Initialize(); breakpad::SymbolFileBreakpad::Initialize(); @@ -319,7 +319,8 @@ void SystemInitializerFull::Terminate() { InstrumentationRuntimeASan::Terminate(); InstrumentationRuntimeTSan::Terminate(); InstrumentationRuntimeUBSan::Terminate(); - MainThreadCheckerRuntime::Terminate(); + InstrumentationRuntimeMainThreadChecker::Terminate(); + wasm::SymbolVendorWasm::Terminate(); SymbolVendorELF::Terminate(); breakpad::SymbolFileBreakpad::Terminate(); diff --git a/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/CMakeLists.txt b/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/CMakeLists.txt index 440b176b2709..8095658452d1 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/CMakeLists.txt +++ b/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/CMakeLists.txt @@ -1,5 +1,5 @@ add_lldb_library(lldbPluginInstrumentationRuntimeMainThreadChecker PLUGIN - MainThreadCheckerRuntime.cpp + InstrumentationRuntimeMainThreadChecker.cpp LINK_LIBS lldbBreakpoint diff --git a/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.cpp b/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/InstrumentationRuntimeMainThreadChecker.cpp similarity index 80% rename from lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.cpp rename to lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/InstrumentationRuntimeMainThreadChecker.cpp index b73b6c095368..6f4663b5df0b 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 -------------*- 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,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,52 @@ #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Utility/RegularExpression.h" -#include "Plugins/Process/Utility/HistoryThread.h" #include using namespace lldb; using namespace lldb_private; -MainThreadCheckerRuntime::~MainThreadCheckerRuntime() { +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 +77,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 +155,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(baton); + InstrumentationRuntimeMainThreadChecker *const instance = + static_cast(baton); ProcessSP process_sp = instance->GetProcessSP(); ThreadSP thread_sp = context->exe_ctx_ref.GetThreadSP(); @@ -172,9 +179,9 @@ bool MainThreadCheckerRuntime::NotifyBreakpointHit( if (report) { std::string description = report->GetAsDictionary() - ->GetValueForKey("description") - ->GetAsString() - ->GetValue(); + ->GetValueForKey("description") + ->GetAsString() + ->GetValue(); thread_sp->SetStopInfo( InstrumentationRuntimeStopInfo::CreateStopReasonWithInstrumentationData( *thread_sp, description, report)); @@ -184,7 +191,7 @@ bool MainThreadCheckerRuntime::NotifyBreakpointHit( return false; } -void MainThreadCheckerRuntime::Activate() { +void InstrumentationRuntimeMainThreadChecker::Activate() { if (IsActive()) return; @@ -215,15 +222,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 +244,7 @@ void MainThreadCheckerRuntime::Deactivate() { } lldb::ThreadCollectionSP -MainThreadCheckerRuntime::GetBacktracesFromExtendedStopInfo( +InstrumentationRuntimeMainThreadChecker::GetBacktracesFromExtendedStopInfo( StructuredData::ObjectSP info) { ThreadCollectionSP threads; threads = std::make_shared(); @@ -245,7 +252,7 @@ MainThreadCheckerRuntime::GetBacktracesFromExtendedStopInfo( ProcessSP process_sp = GetProcessSP(); if (info->GetObjectForDotSeparatedPath("instrumentation_class") - ->GetStringValue() != "MainThreadChecker") + ->GetStringValue() != "MainThreadChecker") return threads; std::vector 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..290e3a80d849 --- /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 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 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 // liblldb_MainThreadCheckerRuntime_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/tools/lldb-test/SystemInitializerTest.cpp b/lldb/tools/lldb-test/SystemInitializerTest.cpp index 280a118e9105..b6cd146f4d88 100644 --- a/lldb/tools/lldb-test/SystemInitializerTest.cpp +++ b/lldb/tools/lldb-test/SystemInitializerTest.cpp @@ -45,7 +45,7 @@ #include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h" #include "Plugins/Instruction/PPC64/EmulateInstructionPPC64.h" #include "Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.h" -#include "Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.h" +#include "Plugins/InstrumentationRuntime/MainThreadChecker/InstrumentationRuntimeMainThreadChecker.h" #include "Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.h" #include "Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.h" #include "Plugins/JITLoader/GDB/JITLoaderGDB.h" @@ -196,7 +196,7 @@ llvm::Error SystemInitializerTest::Initialize() { InstrumentationRuntimeASan::Initialize(); InstrumentationRuntimeTSan::Initialize(); InstrumentationRuntimeUBSan::Initialize(); - MainThreadCheckerRuntime::Initialize(); + InstrumentationRuntimeMainThreadChecker::Initialize(); SymbolVendorELF::Initialize(); breakpad::SymbolFileBreakpad::Initialize(); @@ -289,7 +289,8 @@ void SystemInitializerTest::Terminate() { InstrumentationRuntimeASan::Terminate(); InstrumentationRuntimeTSan::Terminate(); InstrumentationRuntimeUBSan::Terminate(); - MainThreadCheckerRuntime::Terminate(); + InstrumentationRuntimeMainThreadChecker::Terminate(); + wasm::SymbolVendorWasm::Terminate(); SymbolVendorELF::Terminate(); breakpad::SymbolFileBreakpad::Terminate();