Skip to content

Commit 75433c6

Browse files
committed
[lldb][CPlusPLus] Make C++ frame-format work without debug-info
(cherry picked from commit db417e8)
1 parent 8deff41 commit 75433c6

8 files changed

+73
-10
lines changed

lldb/source/Core/FormatEntity.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,11 +1817,12 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
18171817
case Entry::Type::FunctionReturnRight:
18181818
case Entry::Type::FunctionReturnLeft:
18191819
case Entry::Type::FunctionQualifiers: {
1820-
if (!sc->function)
1821-
return false;
1820+
Language *language_plugin = nullptr;
1821+
if (sc->function)
1822+
language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1823+
else if (sc->symbol)
1824+
language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
18221825

1823-
Language *language_plugin =
1824-
Language::FindPlugin(sc->function->GetLanguage());
18251826
if (!language_plugin)
18261827
return false;
18271828

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,34 @@ GetDemangledScope(const SymbolContext &sc) {
354354
return demangled_name.slice(info->ScopeRange.first, info->ScopeRange.second);
355355
}
356356

357+
static bool PrintDemangledArgumentList(Stream &s, const SymbolContext &sc) {
358+
assert(sc.symbol);
359+
360+
Mangled mangled = sc.GetPossiblyInlinedFunctionName();
361+
if (!mangled)
362+
return false;
363+
364+
auto demangled_name = mangled.GetDemangledName().GetStringRef();
365+
if (demangled_name.empty())
366+
return false;
367+
368+
const std::optional<DemangledNameInfo> &info = mangled.GetDemangledInfo();
369+
if (!info)
370+
return false;
371+
372+
// Function without a basename is nonsense.
373+
if (!info->hasBasename())
374+
return false;
375+
376+
if (info->ArgumentsRange.second < info->ArgumentsRange.first)
377+
return false;
378+
379+
s << demangled_name.slice(info->ArgumentsRange.first,
380+
info->ArgumentsRange.second);
381+
382+
return true;
383+
}
384+
357385
bool CPlusPlusLanguage::MethodName::TrySimplifiedParse() {
358386
// This method tries to parse simple method definitions which are presumably
359387
// most comman in user programs. Definitions that can be parsed by this
@@ -1913,8 +1941,6 @@ bool CPlusPlusLanguage::GetFunctionDisplayName(
19131941
bool CPlusPlusLanguage::HandleFrameFormatVariable(
19141942
const SymbolContext &sc, const ExecutionContext *exe_ctx,
19151943
FormatEntity::Entry::Type type, Stream &s) {
1916-
assert(sc.function);
1917-
19181944
switch (type) {
19191945
case FormatEntity::Entry::Type::FunctionScope: {
19201946
std::optional<llvm::StringRef> scope = GetDemangledScope(sc);
@@ -1948,6 +1974,14 @@ bool CPlusPlusLanguage::HandleFrameFormatVariable(
19481974
}
19491975

19501976
case FormatEntity::Entry::Type::FunctionFormattedArguments: {
1977+
// This ensures we print the arguments even when no debug-info is available.
1978+
//
1979+
// FIXME: we should have a Entry::Type::FunctionArguments and
1980+
// use it in the plugin.cplusplus.display.function-name-format
1981+
// once we have a "fallback operator" in the frame-format language.
1982+
if (!sc.function && sc.symbol)
1983+
return PrintDemangledArgumentList(s, sc);
1984+
19511985
VariableList args;
19521986
if (auto variable_list_sp = GetFunctionVariableList(sc))
19531987
variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument,

lldb/test/Shell/Settings/TestFrameFormatFunctionBasename.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
88
# RUN: | FileCheck %s
99
#
10+
# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
11+
# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
12+
# RUN: | FileCheck %s
13+
1014
#--- main.cpp
1115
namespace ns {
1216
template<typename T>

lldb/test/Shell/Settings/TestFrameFormatFunctionFormattedArguments.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.out
77
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
88
# RUN: | FileCheck %s
9+
#
10+
# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
11+
# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
12+
# RUN: | FileCheck %s --check-prefix=CHECK-NODEBUG
913

1014
#--- main.cpp
1115
struct Foo {
@@ -42,3 +46,8 @@ bt
4246
# CHECK: custom-frame '({{.*}}=5, x=10)'
4347
# CHECK: custom-frame '(str="hello", fptr=({{.*}}.out`{{.*}}foo(int,{{.*}}int) at main.cpp:{{[0-9]+}}))'
4448
# CHECK: custom-frame '(argc=1, argv={{.*}})'
49+
50+
# CHECK-NODEBUG: custom-frame '()'
51+
# CHECK-NODEBUG: custom-frame '()'
52+
# CHECK-NODEBUG: custom-frame '(int, int)'
53+
# CHECK-NODEBUG: custom-frame '(char const*, void (*)(int, int))'

lldb/test/Shell/Settings/TestFrameFormatFunctionQualifiers.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.out
77
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
88
# RUN: | FileCheck %s
9+
#
10+
# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
11+
# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
12+
# RUN: | FileCheck %s
913

1014
#--- main.cpp
1115
struct Foo {

lldb/test/Shell/Settings/TestFrameFormatFunctionReturn.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.out
88
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
99
# RUN: | FileCheck %s
10+
#
11+
# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
12+
# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
13+
# RUN: | FileCheck %s
1014

1115
#--- main.cpp
1216
namespace ns::ns2 {

lldb/test/Shell/Settings/TestFrameFormatFunctionScope.test

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
# RUN: split-file %s %t
66
# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.out
7-
# RUN: %lldb -o "settings set interpreter.stop-command-source-on-error false" \
8-
# RUN: -x -b -s %t/commands.input %t.out -o exit 2>&1 \
7+
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
8+
# RUN: | FileCheck %s
9+
#
10+
# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
11+
# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
912
# RUN: | FileCheck %s
1013

1114
#--- main.cpp

lldb/test/Shell/Settings/TestFrameFormatFunctionTemplateArguments.test

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
# Test the ${function.template-arguments} frame-format variable.
44

55
# RUN: split-file %s %t
6-
# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.cxx.out
7-
# RUN: %lldb -x -b -s %t/commands.input %t.cxx.out -o exit 2>&1 \
6+
# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.out
7+
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
8+
# RUN: | FileCheck %s
9+
#
10+
# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
11+
# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
812
# RUN: | FileCheck %s
913

1014
#--- main.cpp

0 commit comments

Comments
 (0)