Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_lldb_library(lldbPluginCPPRuntime
CPPLanguageRuntime.cpp
VerboseTrapFrameRecognizer.cpp

LINK_LIBS
lldbCore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <memory>

#include "CPPLanguageRuntime.h"
#include "VerboseTrapFrameRecognizer.h"

#include "llvm/ADT/StringRef.h"

Expand Down Expand Up @@ -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<RegularExpression>("^std::__[^:]*::"),
/*mangling_preference=*/Mangled::ePreferDemangledWithoutArguments,
/*first_instruction_only=*/false);

RegisterVerboseTrapFrameRecognizer(*process);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is CPPLanguageRuntime guaranteed to be loaded even if the process being debugged was built with C only?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so yes. I don't know of a case where the C++ language plugin registration wouldn't trigger. IIUC, this would only happen if someone chose to compile the plugin out of LLDB when building it. I don't think we have a mechanism in CMake to do that yet? @jimingham @JDevlieghere Is my understanding correct here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can compile out plugins but it's not guaranteed to be safe. There are many "plugins" that LLDB can't work without (or plugins that depend on other plugins) so although it's possible, it's not encouraged or easy to do. I don't think we should account for that in our design.

}
}

bool CPPLanguageRuntime::IsAllowedRuntimeValue(ConstString name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "lldb/Target/VerboseTrapFrameRecognizer.h"
#include "VerboseTrapFrameRecognizer.h"

#include "lldb/Core/Module.h"
#include "lldb/Symbol/Function.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion lldb/source/Target/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ add_lldb_library(lldbTarget
UnixSignals.cpp
UnwindAssembly.cpp
UnwindLLDB.cpp
VerboseTrapFrameRecognizer.cpp

ADDITIONAL_HEADER_DIRS
${LLDB_INCLUDE_DIR}/lldb/Target
Expand Down
2 changes: 0 additions & 2 deletions lldb/source/Target/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,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"
Expand Down Expand Up @@ -513,7 +512,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() {
Expand Down
4 changes: 4 additions & 0 deletions lldb/test/Shell/Recognizer/Inputs/verbose_trap.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int main() {
__builtin_verbose_trap("Foo", "Bar");
return 0;
}
54 changes: 54 additions & 0 deletions lldb/test/Shell/Recognizer/registration-unique.test
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions lldb/test/Shell/Recognizer/verbose_trap-objc.test
Original file line number Diff line number Diff line change
@@ -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
Loading