Skip to content

Commit a824d52

Browse files
committed
[lldb][Runtime] Move VerboseTrapFrameRecognizer into CPPLanguageRuntime
llvm#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 currentl sole responsibility was to register the `VerboseTrapFrameRecognizer` and `AssertStackFrameRecognizer`. However, making this plugin a fully-fledged runtime felt wrong because all the `LanguageRuntime` functionality would live in the derived C++/ObjC runtime plugins. We also have this awkward problem that 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. In order to unblock llvm#165996 simply move the `VerboseTrapFrameRecognizer` for now
1 parent f3b407f commit a824d52

File tree

9 files changed

+87
-8
lines changed

9 files changed

+87
-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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
run
37+
frame recognizer list
38+
39+
# CHECK: frame recognizer list
40+
# CHECK-NEXT: no matching results found.
41+
42+
# CHECK: frame recognizer list
43+
# CHECK: Verbose Trap StackFrame Recognizer
44+
# CHECK: Assert StackFrame Recognizer
45+
# CHECK-NOT: Verbose Trap StackFrame Recognizer
46+
# CHECK-NOT: Assert StackFrame Recognizer
47+
48+
# FIXME: avoid duplicate frame recognizers in the target.
49+
# CHECK: frame recognizer list
50+
# CHECK: Verbose Trap StackFrame Recognizer
51+
# CHECK: Assert StackFrame Recognizer
52+
# CHECK: Verbose Trap StackFrame Recognizer
53+
# 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)