https://github.com/charles-zablit created https://github.com/llvm/llvm-project/pull/201097
This patch moves `MSVCRTCFrameRecognizer` to `Plugins/DynamicLoader/Windows-DYLD` and register it from `DynamicLoaderWindowsDYLD::DidLaunch / DidAttach`. The Windows DYLD plugin runs for every Windows target regardless of process plugin. This patch enables it to work with `lldb-server.exe`. This fixes `TestMSVCRTCException` with `LLDB_USE_LLDB_SERVER=1`. This patch also removes the exception-code gate (`exc_code != EXCEPTION_BREAKPOINT`) from `RecognizeFrame`. It did not translate to `ProcessGDBRemote`. >From abd9eb6926f3c50d7bbbabfd61e6c3933d7cc3a5 Mon Sep 17 00:00:00 2001 From: Charles Zablit <[email protected]> Date: Tue, 2 Jun 2026 12:24:10 +0100 Subject: [PATCH] [lldb][Windows] Register MSVCRTCFrameRecognizer from DynamicLoaderWindowsDYLD --- .../Plugins/DynamicLoader/Windows-DYLD/CMakeLists.txt | 3 +++ .../Windows-DYLD/DynamicLoaderWindowsDYLD.cpp | 5 +++++ .../Windows-DYLD}/MSVCRTCFrameRecognizer.cpp | 11 ++--------- .../Windows-DYLD}/MSVCRTCFrameRecognizer.h | 11 ++++++----- .../Plugins/Process/Windows/Common/CMakeLists.txt | 1 - .../Plugins/Process/Windows/Common/ProcessWindows.cpp | 3 --- 6 files changed, 16 insertions(+), 18 deletions(-) rename lldb/source/Plugins/{Process/Windows/Common => DynamicLoader/Windows-DYLD}/MSVCRTCFrameRecognizer.cpp (81%) rename lldb/source/Plugins/{Process/Windows/Common => DynamicLoader/Windows-DYLD}/MSVCRTCFrameRecognizer.h (82%) diff --git a/lldb/source/Plugins/DynamicLoader/Windows-DYLD/CMakeLists.txt b/lldb/source/Plugins/DynamicLoader/Windows-DYLD/CMakeLists.txt index 4c2145714081c..9f000d4ea654a 100644 --- a/lldb/source/Plugins/DynamicLoader/Windows-DYLD/CMakeLists.txt +++ b/lldb/source/Plugins/DynamicLoader/Windows-DYLD/CMakeLists.txt @@ -1,10 +1,13 @@ add_lldb_library(lldbPluginDynamicLoaderWindowsDYLD PLUGIN DynamicLoaderWindowsDYLD.cpp + MSVCRTCFrameRecognizer.cpp LINK_COMPONENTS Support TargetParser LINK_LIBS lldbCore + lldbSymbol lldbTarget + lldbValueObject ) diff --git a/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp b/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp index b0ea55c96f48f..2d6e97b067c30 100644 --- a/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp @@ -8,6 +8,7 @@ #include "DynamicLoaderWindowsDYLD.h" +#include "MSVCRTCFrameRecognizer.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Target/ExecutionContext.h" @@ -137,6 +138,8 @@ void DynamicLoaderWindowsDYLD::DidAttach() { Log *log = GetLog(LLDBLog::DynamicLoader); LLDB_LOGF(log, "DynamicLoaderWindowsDYLD::%s()", __FUNCTION__); + RegisterMSVCRTCFrameRecognizer(m_process->GetTarget()); + ModuleSP executable = GetTargetExecutable(); if (!executable) @@ -167,6 +170,8 @@ void DynamicLoaderWindowsDYLD::DidLaunch() { Log *log = GetLog(LLDBLog::DynamicLoader); LLDB_LOGF(log, "DynamicLoaderWindowsDYLD::%s()", __FUNCTION__); + RegisterMSVCRTCFrameRecognizer(m_process->GetTarget()); + ModuleSP executable = GetTargetExecutable(); if (!executable) return; diff --git a/lldb/source/Plugins/Process/Windows/Common/MSVCRTCFrameRecognizer.cpp b/lldb/source/Plugins/DynamicLoader/Windows-DYLD/MSVCRTCFrameRecognizer.cpp similarity index 81% rename from lldb/source/Plugins/Process/Windows/Common/MSVCRTCFrameRecognizer.cpp rename to lldb/source/Plugins/DynamicLoader/Windows-DYLD/MSVCRTCFrameRecognizer.cpp index da05cd79fbe62..c1438ae7e76bb 100644 --- a/lldb/source/Plugins/Process/Windows/Common/MSVCRTCFrameRecognizer.cpp +++ b/lldb/source/Plugins/DynamicLoader/Windows-DYLD/MSVCRTCFrameRecognizer.cpp @@ -21,8 +21,8 @@ using namespace lldb_private; namespace lldb_private { -void RegisterMSVCRTCFrameRecognizer(ProcessWindows &process) { - process.GetTarget().GetFrameRecognizerManager().AddRecognizer( +void RegisterMSVCRTCFrameRecognizer(Target &target) { + target.GetFrameRecognizerManager().AddRecognizer( std::make_shared<MSVCRTCFrameRecognizer>(), ConstString(""), {ConstString("failwithmessage")}, Mangled::ePreferDemangled, /*first_instruction_only=*/false); @@ -33,13 +33,6 @@ MSVCRTCFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame_sp) { // failwithmessage calls __debugbreak() which lands at frame 0. if (frame_sp->GetFrameIndex() != 0) return RecognizedStackFrameSP(); - // Only fire on EXCEPTION_BREAKPOINT (0x80000003), not on other exceptions - // that might incidentally have failwithmessage somewhere in the call stack. - auto *pw = - static_cast<ProcessWindows *>(frame_sp->GetThread()->GetProcess().get()); - auto exc_code = pw->GetActiveExceptionCode(); - if (!exc_code || *exc_code != EXCEPTION_BREAKPOINT) - return RecognizedStackFrameSP(); const char *fn_name = frame_sp->GetFunctionName(); if (!fn_name) diff --git a/lldb/source/Plugins/Process/Windows/Common/MSVCRTCFrameRecognizer.h b/lldb/source/Plugins/DynamicLoader/Windows-DYLD/MSVCRTCFrameRecognizer.h similarity index 82% rename from lldb/source/Plugins/Process/Windows/Common/MSVCRTCFrameRecognizer.h rename to lldb/source/Plugins/DynamicLoader/Windows-DYLD/MSVCRTCFrameRecognizer.h index 51a451cb94f90..79dcad049b11a 100644 --- a/lldb/source/Plugins/Process/Windows/Common/MSVCRTCFrameRecognizer.h +++ b/lldb/source/Plugins/DynamicLoader/Windows-DYLD/MSVCRTCFrameRecognizer.h @@ -6,16 +6,17 @@ // //===----------------------------------------------------------------------===// -#ifndef LLDB_PLUGINS_PROCESS_WINDOWS_MSVCRTCFRAMERECOGNIZER_H -#define LLDB_PLUGINS_PROCESS_WINDOWS_MSVCRTCFRAMERECOGNIZER_H +#ifndef LLDB_PLUGINS_DYNAMICLOADER_WINDOWS_MSVCRTCFRAMERECOGNIZER_H +#define LLDB_PLUGINS_DYNAMICLOADER_WINDOWS_MSVCRTCFRAMERECOGNIZER_H -#include "ProcessWindows.h" #include "lldb/Target/StackFrameRecognizer.h" namespace lldb_private { +class Target; + /// Registers the MSVC run-time check failure frame recognizer with the target. -void RegisterMSVCRTCFrameRecognizer(ProcessWindows &process); +void RegisterMSVCRTCFrameRecognizer(Target &target); /// Recognized stack frame for an MSVC _RTC failure. Carries the human-readable /// stop description extracted from failwithmessage's \c msg parameter. @@ -38,4 +39,4 @@ class MSVCRTCFrameRecognizer : public StackFrameRecognizer { } // namespace lldb_private -#endif // LLDB_PLUGINS_PROCESS_WINDOWS_MSVCRTCFRAMERECOGNIZER_H +#endif // LLDB_PLUGINS_DYNAMICLOADER_WINDOWS_MSVCRTCFRAMERECOGNIZER_H diff --git a/lldb/source/Plugins/Process/Windows/Common/CMakeLists.txt b/lldb/source/Plugins/Process/Windows/Common/CMakeLists.txt index edb0532ea01c7..9854b79fbb8d6 100644 --- a/lldb/source/Plugins/Process/Windows/Common/CMakeLists.txt +++ b/lldb/source/Plugins/Process/Windows/Common/CMakeLists.txt @@ -2,7 +2,6 @@ add_lldb_library(lldbPluginProcessWindowsCommon PLUGIN DebuggerThread.cpp LocalDebugDelegate.cpp - MSVCRTCFrameRecognizer.cpp NativeProcessWindows.cpp NativeRegisterContextWindows.cpp NativeRegisterContextWindows_arm.cpp diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp index beea043ccb2e7..84fee7df8cf5a 100644 --- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp +++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp @@ -44,7 +44,6 @@ #include "ExceptionRecord.h" #include "ForwardDecl.h" #include "LocalDebugDelegate.h" -#include "MSVCRTCFrameRecognizer.h" #include "ProcessWindowsLog.h" #include "TargetThreadWindows.h" @@ -304,8 +303,6 @@ void ProcessWindows::DidLaunch() { void ProcessWindows::DidAttach(ArchSpec &arch_spec) { llvm::sys::ScopedLock lock(m_mutex); - RegisterMSVCRTCFrameRecognizer(*this); - // The initial stop won't broadcast the state change event, so account for // that here. if (m_session_data && GetPrivateState() == eStateStopped && _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
