From 9fb5bf8bb77c26c5333ee86e9a2a108222336650 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Tue, 4 Nov 2025 09:25:28 +0000 Subject: [PATCH 1/2] [lldb][Runtime] Move VerboseTrapFrameRecognizer into CPPLanguageRuntime (#166157) https://github.com/llvm/llvm-project/pull/165996 is adding a Clang dependency to Target because we're moving some of the functionality of the VerboseTrapFrameRecognizer into libClang. To avoid adding this dependency this patch moves VerboseTrapFrameRecognizer into the CPPLanguageRuntime. Most of the frame recognizers already live in the various runtime plugins. An alternative discussed was to create a common `CLanguageRuntime` whose currently sole responsibility was to register the `VerboseTrapFrameRecognizer` and `AssertStackFrameRecognizer`. The main issue I ran into here was frame recognizers aren't uniqued in the target. Currently this only manifests when re-running a target, which re-triggers all the recognizer registration (added a test with a FIXME for this). If we had a common `CLanguageRuntime` that `CPPLanguageRuntime` and `ObjCLanguageRuntime` inherited from, I didn't find a great way to avoid registering the recognizer multiple times. We can't just call_once on it because we do want the recognisers to be re-registered for new targets in the same debugger session. If the recognisers were stored in something like a UniqueVector in the Target, then we wouldn't have that issue. But currently that's not the case, and it would take a bit of refactoring to de-dupe the recognisers. There may very well be solutions I haven't considered, but all the things I've tried so far I wasn't very happy with. So in the end I just moved this to the C++ runtime for now in order to unblock https://github.com/llvm/llvm-project/pull/165996. The C++ language runtime is always available (even for C targets) if the C++ language plugin is available. Which it should also be unless someone is using an LLDB with the C++ plugin compiled out. But at that point numerous things wouldn't work when even debugging just C. (cherry picked from commit bb4ed55acdbc7f48bc978147189e8106e3ea42f8) --- .../LanguageRuntime/CPlusPlus/CMakeLists.txt | 1 + .../CPlusPlus/CPPLanguageRuntime.cpp | 6 ++- .../CPlusPlus}/VerboseTrapFrameRecognizer.cpp | 2 +- .../CPlusPlus}/VerboseTrapFrameRecognizer.h | 14 +++-- lldb/source/Target/CMakeLists.txt | 1 - lldb/source/Target/Process.cpp | 2 - .../Shell/Recognizer/Inputs/verbose_trap.m | 4 ++ .../Shell/Recognizer/registration-unique.test | 54 +++++++++++++++++++ .../Shell/Recognizer/verbose_trap-objc.test | 12 +++++ 9 files changed, 88 insertions(+), 8 deletions(-) rename lldb/source/{Target => Plugins/LanguageRuntime/CPlusPlus}/VerboseTrapFrameRecognizer.cpp (99%) rename lldb/{include/lldb/Target => source/Plugins/LanguageRuntime/CPlusPlus}/VerboseTrapFrameRecognizer.h (63%) create mode 100644 lldb/test/Shell/Recognizer/Inputs/verbose_trap.m create mode 100644 lldb/test/Shell/Recognizer/registration-unique.test create mode 100644 lldb/test/Shell/Recognizer/verbose_trap-objc.test diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CMakeLists.txt b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CMakeLists.txt index 1717b0a896669..a27bceffe2e3a 100644 --- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CMakeLists.txt +++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CMakeLists.txt @@ -1,5 +1,6 @@ add_lldb_library(lldbPluginCPPRuntime CPPLanguageRuntime.cpp + VerboseTrapFrameRecognizer.cpp LINK_LIBS lldbCore diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp index 21a5ebe53073a..913678b629f2f 100644 --- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp @@ -12,6 +12,7 @@ #include #include "CPPLanguageRuntime.h" +#include "VerboseTrapFrameRecognizer.h" #include "llvm/ADT/StringRef.h" @@ -107,12 +108,15 @@ class LibCXXFrameRecognizer : public StackFrameRecognizer { CPPLanguageRuntime::CPPLanguageRuntime(Process *process) : LanguageRuntime(process) { - if (process) + if (process) { process->GetTarget().GetFrameRecognizerManager().AddRecognizer( StackFrameRecognizerSP(new LibCXXFrameRecognizer()), {}, std::make_shared("^std::__[^:]*::"), /*mangling_preference=*/Mangled::ePreferDemangledWithoutArguments, /*first_instruction_only=*/false); + + RegisterVerboseTrapFrameRecognizer(*process); + } } bool CPPLanguageRuntime::IsAllowedRuntimeValue(ConstString name) { diff --git a/lldb/source/Target/VerboseTrapFrameRecognizer.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/VerboseTrapFrameRecognizer.cpp similarity index 99% rename from lldb/source/Target/VerboseTrapFrameRecognizer.cpp rename to lldb/source/Plugins/LanguageRuntime/CPlusPlus/VerboseTrapFrameRecognizer.cpp index 34ce557533972..41bf10bbf42d7 100644 --- a/lldb/source/Target/VerboseTrapFrameRecognizer.cpp +++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/VerboseTrapFrameRecognizer.cpp @@ -1,4 +1,4 @@ -#include "lldb/Target/VerboseTrapFrameRecognizer.h" +#include "VerboseTrapFrameRecognizer.h" #include "lldb/Core/Module.h" #include "lldb/Symbol/Function.h" diff --git a/lldb/include/lldb/Target/VerboseTrapFrameRecognizer.h b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/VerboseTrapFrameRecognizer.h similarity index 63% rename from lldb/include/lldb/Target/VerboseTrapFrameRecognizer.h rename to lldb/source/Plugins/LanguageRuntime/CPlusPlus/VerboseTrapFrameRecognizer.h index 7e045760a28be..7d7020f63c8d2 100644 --- a/lldb/include/lldb/Target/VerboseTrapFrameRecognizer.h +++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/VerboseTrapFrameRecognizer.h @@ -1,5 +1,13 @@ -#ifndef LLDB_TARGET_VERBOSETRAPFRAMERECOGNIZER_H -#define LLDB_TARGET_VERBOSETRAPFRAMERECOGNIZER_H +//===-- VerboseTrapFrameRecognizer.h --------------------------------------===// +// +// 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_LANGUAGERUNTIME_C_PLUS_PLUS_VERBOSETRAPFRAMERECOGNIZER_H +#define LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_C_PLUS_PLUS_VERBOSETRAPFRAMERECOGNIZER_H #include "lldb/Target/StackFrameRecognizer.h" @@ -36,4 +44,4 @@ class VerboseTrapFrameRecognizer : public StackFrameRecognizer { } // namespace lldb_private -#endif // LLDB_TARGET_VERBOSETRAPFRAMERECOGNIZER_H +#endif // LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_C_PLUS_PLUS_VERBOSETRAPFRAMERECOGNIZER_H diff --git a/lldb/source/Target/CMakeLists.txt b/lldb/source/Target/CMakeLists.txt index 1afa43567d750..942a7839d4b46 100644 --- a/lldb/source/Target/CMakeLists.txt +++ b/lldb/source/Target/CMakeLists.txt @@ -81,7 +81,6 @@ add_lldb_library(lldbTarget UnixSignals.cpp UnwindAssembly.cpp UnwindLLDB.cpp - VerboseTrapFrameRecognizer.cpp ADDITIONAL_HEADER_DIRS ${LLDB_INCLUDE_DIR}/lldb/Target diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 5e2fc7e4a8ef9..598bcb0048e43 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -66,7 +66,6 @@ #include "lldb/Target/ThreadPlanCallFunction.h" #include "lldb/Target/ThreadPlanStack.h" #include "lldb/Target/UnixSignals.h" -#include "lldb/Target/VerboseTrapFrameRecognizer.h" #include "lldb/Utility/AddressableBits.h" #include "lldb/Utility/Event.h" #include "lldb/Utility/LLDBLog.h" @@ -527,7 +526,6 @@ Process::Process(lldb::TargetSP target_sp, ListenerSP listener_sp, // We should have a plugin do the registration instead, for example, a // common C LanguageRuntime plugin. RegisterAssertFrameRecognizer(this); - RegisterVerboseTrapFrameRecognizer(*this); } Process::~Process() { diff --git a/lldb/test/Shell/Recognizer/Inputs/verbose_trap.m b/lldb/test/Shell/Recognizer/Inputs/verbose_trap.m new file mode 100644 index 0000000000000..83a829a8c2fdd --- /dev/null +++ b/lldb/test/Shell/Recognizer/Inputs/verbose_trap.m @@ -0,0 +1,4 @@ +int main() { + __builtin_verbose_trap("Foo", "Bar"); + return 0; +} diff --git a/lldb/test/Shell/Recognizer/registration-unique.test b/lldb/test/Shell/Recognizer/registration-unique.test new file mode 100644 index 0000000000000..f6052bb57c940 --- /dev/null +++ b/lldb/test/Shell/Recognizer/registration-unique.test @@ -0,0 +1,54 @@ +# Checks that the recognizers that should work across language runtimes +# are only registered once with the target. + +# RUN: split-file %s %t + +# RUN: %clang_host %t/main.cpp -g -o %t/cpp.out +# RUN: %lldb -b -s %t/commands.input %t/cpp.out | FileCheck %s + +# RUN: %clang_host -x objective-c++ %t/main.mm -g -o %t/objcxx.out +# RUN: %lldb -b -s %t/commands.input %t/objcxx.out | FileCheck %s + +# RUN: %clang_host %t/main.c -g -o %t/c.out +# RUN: %lldb -b -s %t/commands.input %t/c.out | FileCheck %s + +# RUN: %clang_host -x objective-c %t/main.m -g -o %t/objc.out +# RUN: %lldb -b -s %t/commands.input %t/objc.out | FileCheck %s + +#--- main.m +int main() {} + +#--- main.c +int main() {} + +#--- main.mm +int main() {} + +#--- main.cpp +int main() {} + +#--- commands.input + +b main +frame recognizer list +run +frame recognizer list +continue +run +frame recognizer list + +# CHECK: frame recognizer list +# CHECK-NEXT: no matching results found. + +# CHECK: frame recognizer list +# CHECK: Verbose Trap StackFrame Recognizer +# CHECK: Assert StackFrame Recognizer +# CHECK-NOT: Verbose Trap StackFrame Recognizer +# CHECK-NOT: Assert StackFrame Recognizer + +# FIXME: avoid duplicate frame recognizers in the target: https://github.com/llvm/llvm-project/issues/166341 +# CHECK: frame recognizer list +# CHECK: Verbose Trap StackFrame Recognizer +# CHECK: Assert StackFrame Recognizer +# CHECK: Verbose Trap StackFrame Recognizer +# CHECK: Assert StackFrame Recognizer diff --git a/lldb/test/Shell/Recognizer/verbose_trap-objc.test b/lldb/test/Shell/Recognizer/verbose_trap-objc.test new file mode 100644 index 0000000000000..789e79c9542c5 --- /dev/null +++ b/lldb/test/Shell/Recognizer/verbose_trap-objc.test @@ -0,0 +1,12 @@ +# REQUIRES: system-darwin +# +# RUN: %clangxx_host -x objective-c -g %S/Inputs/verbose_trap.m -o %t.out +# RUN: %lldb -b -s %s %t.out | FileCheck %s + +run +# CHECK: thread #{{.*}}stop reason = Foo: Bar +frame info +# CHECK: frame #{{.*}}`main at verbose_trap.m +frame recognizer info 0 +# CHECK: frame 0 is recognized by Verbose Trap StackFrame Recognizer +q From c254ab83967abc719ca81cb39bdb98c7bb14cf23 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Tue, 4 Nov 2025 12:01:15 +0000 Subject: [PATCH 2/2] [lldb][test] Skip registration-unique.test on Windows Fails with: ``` RUN: at line 4 split-file C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Recognizer\registration-unique.test C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Recognizer\Output\registration-unique.test.tmp executed command: split-file 'C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Recognizer\registration-unique.test' 'C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Recognizer\Output\registration-unique.test.tmp' note: command had no output on stdout or stderr RUN: at line 6 c:\users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe --target=specify-a-target-or-use-a-_host-substitution --target=aarch64-pc-windows-msvc -fmodules-cache-path=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/module-cache-clang\lldb-shell C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Recognizer\Output\registration-unique.test.tmp/main.cpp -g -o C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Recognizer\Output\registration-unique.test.tmp/cpp.out executed command: 'c:\users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe' --target=specify-a-target-or-use-a-_host-substitution --target=aarch64-pc-windows-msvc '-fmodules-cache-path=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/module-cache-clang\lldb-shell' 'C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Recognizer\Output\registration-unique.test.tmp/main.cpp' -g -o 'C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Recognizer\Output\registration-unique.test.tmp/cpp.out' .---command stderr------------ | clang: warning: argument unused during compilation: '-fmodules-cache-path=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/module-cache-clang\lldb-shell' [-Wunused-command-line-argument] `----------------------------- RUN: at line 7 c:\users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\lldb.exe --no-lldbinit -S C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/tools/lldb\test\Shell\lit-lldb-init-quiet -b -s C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Recognizer\Output\registration-unique.test.tmp/commands.input C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Recognizer\Output\registration-unique.test.tmp/cpp.out | c:\users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\filecheck.exe C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Recognizer\registration-unique.test executed command: 'c:\users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\lldb.exe' --no-lldbinit -S 'C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/tools/lldb\test\Shell\lit-lldb-init-quiet' -b -s 'C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Recognizer\Output\registration-unique.test.tmp/commands.input' 'C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Recognizer\Output\registration-unique.test.tmp/cpp.out' note: command had no output on stdout or stderr executed command: 'c:\users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\filecheck.exe' 'C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Recognizer\registration-unique.test' .---command stderr------------ | C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Recognizer\registration-unique.test:45:10: error: CHECK: expected string not found in input | # CHECK: Assert StackFrame Recognizer | ^ | :20:38: note: scanning from here | 1: Verbose Trap StackFrame Recognizer, demangled symbol regex ^__clang_trap_msg | ^ | :34:10: note: possible intended match here | 3: Verbose Trap StackFrame Recognizer, demangled symbol regex ^__clang_trap_msg | ^ | | Input file: | Check file: C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Recognizer\registration-unique.test | | -dump-input=help explains the following input dump. ``` (cherry picked from commit 8636c40f4e5451fd9a6b64c22abe0e8d561f7c89) --- lldb/test/Shell/Recognizer/registration-unique.test | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lldb/test/Shell/Recognizer/registration-unique.test b/lldb/test/Shell/Recognizer/registration-unique.test index f6052bb57c940..b40c1ce12f940 100644 --- a/lldb/test/Shell/Recognizer/registration-unique.test +++ b/lldb/test/Shell/Recognizer/registration-unique.test @@ -1,3 +1,5 @@ +# UNSUPPORTED: system-windows + # Checks that the recognizers that should work across language runtimes # are only registered once with the target.