Skip to content

Commit bb4ed55

Browse files
authored
[lldb][Runtime] Move VerboseTrapFrameRecognizer into CPPLanguageRuntime (#166157)
#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 #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.
1 parent c02bdd4 commit bb4ed55

File tree

9 files changed

+88
-8
lines changed

9 files changed

+88
-8
lines changed

lldb/source/Plugins/LanguageRuntime/CPlusPlus/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
add_lldb_library(lldbPluginCPPRuntime
22
CPPLanguageRuntime.cpp
3+
VerboseTrapFrameRecognizer.cpp
34

45
LINK_LIBS
56
lldbCore

lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <memory>
1313

1414
#include "CPPLanguageRuntime.h"
15+
#include "VerboseTrapFrameRecognizer.h"
1516

1617
#include "llvm/ADT/StringRef.h"
1718

@@ -107,12 +108,15 @@ class LibCXXFrameRecognizer : public StackFrameRecognizer {
107108

108109
CPPLanguageRuntime::CPPLanguageRuntime(Process *process)
109110
: LanguageRuntime(process) {
110-
if (process)
111+
if (process) {
111112
process->GetTarget().GetFrameRecognizerManager().AddRecognizer(
112113
StackFrameRecognizerSP(new LibCXXFrameRecognizer()), {},
113114
std::make_shared<RegularExpression>("^std::__[^:]*::"),
114115
/*mangling_preference=*/Mangled::ePreferDemangledWithoutArguments,
115116
/*first_instruction_only=*/false);
117+
118+
RegisterVerboseTrapFrameRecognizer(*process);
119+
}
116120
}
117121

118122
bool CPPLanguageRuntime::IsAllowedRuntimeValue(ConstString name) {

lldb/source/Target/VerboseTrapFrameRecognizer.cpp renamed to lldb/source/Plugins/LanguageRuntime/CPlusPlus/VerboseTrapFrameRecognizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "lldb/Target/VerboseTrapFrameRecognizer.h"
1+
#include "VerboseTrapFrameRecognizer.h"
22

33
#include "lldb/Core/Module.h"
44
#include "lldb/Symbol/Function.h"

lldb/include/lldb/Target/VerboseTrapFrameRecognizer.h renamed to lldb/source/Plugins/LanguageRuntime/CPlusPlus/VerboseTrapFrameRecognizer.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
#ifndef LLDB_TARGET_VERBOSETRAPFRAMERECOGNIZER_H
2-
#define LLDB_TARGET_VERBOSETRAPFRAMERECOGNIZER_H
1+
//===-- VerboseTrapFrameRecognizer.h --------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_C_PLUS_PLUS_VERBOSETRAPFRAMERECOGNIZER_H
10+
#define LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_C_PLUS_PLUS_VERBOSETRAPFRAMERECOGNIZER_H
311

412
#include "lldb/Target/StackFrameRecognizer.h"
513

@@ -36,4 +44,4 @@ class VerboseTrapFrameRecognizer : public StackFrameRecognizer {
3644

3745
} // namespace lldb_private
3846

39-
#endif // LLDB_TARGET_VERBOSETRAPFRAMERECOGNIZER_H
47+
#endif // LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_C_PLUS_PLUS_VERBOSETRAPFRAMERECOGNIZER_H

lldb/source/Target/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ add_lldb_library(lldbTarget
8080
UnixSignals.cpp
8181
UnwindAssembly.cpp
8282
UnwindLLDB.cpp
83-
VerboseTrapFrameRecognizer.cpp
8483

8584
ADDITIONAL_HEADER_DIRS
8685
${LLDB_INCLUDE_DIR}/lldb/Target

lldb/source/Target/Process.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
#include "lldb/Target/ThreadPlanCallFunction.h"
6666
#include "lldb/Target/ThreadPlanStack.h"
6767
#include "lldb/Target/UnixSignals.h"
68-
#include "lldb/Target/VerboseTrapFrameRecognizer.h"
6968
#include "lldb/Utility/AddressableBits.h"
7069
#include "lldb/Utility/Event.h"
7170
#include "lldb/Utility/LLDBLog.h"
@@ -513,7 +512,6 @@ Process::Process(lldb::TargetSP target_sp, ListenerSP listener_sp,
513512
// We should have a plugin do the registration instead, for example, a
514513
// common C LanguageRuntime plugin.
515514
RegisterAssertFrameRecognizer(this);
516-
RegisterVerboseTrapFrameRecognizer(*this);
517515
}
518516

519517
Process::~Process() {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int main() {
2+
__builtin_verbose_trap("Foo", "Bar");
3+
return 0;
4+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Checks that the recognizers that should work across language runtimes
2+
# are only registered once with the target.
3+
4+
# RUN: split-file %s %t
5+
6+
# RUN: %clang_host %t/main.cpp -g -o %t/cpp.out
7+
# RUN: %lldb -b -s %t/commands.input %t/cpp.out | FileCheck %s
8+
9+
# RUN: %clang_host -x objective-c++ %t/main.mm -g -o %t/objcxx.out
10+
# RUN: %lldb -b -s %t/commands.input %t/objcxx.out | FileCheck %s
11+
12+
# RUN: %clang_host %t/main.c -g -o %t/c.out
13+
# RUN: %lldb -b -s %t/commands.input %t/c.out | FileCheck %s
14+
15+
# RUN: %clang_host -x objective-c %t/main.m -g -o %t/objc.out
16+
# RUN: %lldb -b -s %t/commands.input %t/objc.out | FileCheck %s
17+
18+
#--- main.m
19+
int main() {}
20+
21+
#--- main.c
22+
int main() {}
23+
24+
#--- main.mm
25+
int main() {}
26+
27+
#--- main.cpp
28+
int main() {}
29+
30+
#--- commands.input
31+
32+
b main
33+
frame recognizer list
34+
run
35+
frame recognizer list
36+
continue
37+
run
38+
frame recognizer list
39+
40+
# CHECK: frame recognizer list
41+
# CHECK-NEXT: no matching results found.
42+
43+
# CHECK: frame recognizer list
44+
# CHECK: Verbose Trap StackFrame Recognizer
45+
# CHECK: Assert StackFrame Recognizer
46+
# CHECK-NOT: Verbose Trap StackFrame Recognizer
47+
# CHECK-NOT: Assert StackFrame Recognizer
48+
49+
# FIXME: avoid duplicate frame recognizers in the target: https://github.com/llvm/llvm-project/issues/166341
50+
# CHECK: frame recognizer list
51+
# CHECK: Verbose Trap StackFrame Recognizer
52+
# CHECK: Assert StackFrame Recognizer
53+
# CHECK: Verbose Trap StackFrame Recognizer
54+
# CHECK: Assert StackFrame Recognizer
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# REQUIRES: system-darwin
2+
#
3+
# RUN: %clangxx_host -x objective-c -g %S/Inputs/verbose_trap.m -o %t.out
4+
# RUN: %lldb -b -s %s %t.out | FileCheck %s
5+
6+
run
7+
# CHECK: thread #{{.*}}stop reason = Foo: Bar
8+
frame info
9+
# CHECK: frame #{{.*}}`main at verbose_trap.m
10+
frame recognizer info 0
11+
# CHECK: frame 0 is recognized by Verbose Trap StackFrame Recognizer
12+
q

0 commit comments

Comments
 (0)