Skip to content

Commit ebeae64

Browse files
committed
Reland "[lldb][Format] Make function name frame-format variables work without debug-info" (#137757)
This reverts commit da70992. Same as the original PR. The failing test-case was resolved in #137763
1 parent 50d3feb commit ebeae64

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
@@ -1812,11 +1812,12 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
18121812
case Entry::Type::FunctionReturnLeft:
18131813
case Entry::Type::FunctionSuffix:
18141814
case Entry::Type::FunctionQualifiers: {
1815-
if (!sc->function)
1816-
return false;
1815+
Language *language_plugin = nullptr;
1816+
if (sc->function)
1817+
language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1818+
else if (sc->symbol)
1819+
language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
18171820

1818-
Language *language_plugin =
1819-
Language::FindPlugin(sc->function->GetLanguage());
18201821
if (!language_plugin)
18211822
return false;
18221823

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,34 @@ GetDemangledFunctionSuffix(const SymbolContext &sc) {
405405
llvm::StringRef::npos);
406406
}
407407

408+
static bool PrintDemangledArgumentList(Stream &s, const SymbolContext &sc) {
409+
assert(sc.symbol);
410+
411+
Mangled mangled = sc.GetPossiblyInlinedFunctionName();
412+
if (!mangled)
413+
return false;
414+
415+
auto demangled_name = mangled.GetDemangledName().GetStringRef();
416+
if (demangled_name.empty())
417+
return false;
418+
419+
const std::optional<DemangledNameInfo> &info = mangled.GetDemangledInfo();
420+
if (!info)
421+
return false;
422+
423+
// Function without a basename is nonsense.
424+
if (!info->hasBasename())
425+
return false;
426+
427+
if (info->ArgumentsRange.second < info->ArgumentsRange.first)
428+
return false;
429+
430+
s << demangled_name.slice(info->ArgumentsRange.first,
431+
info->ArgumentsRange.second);
432+
433+
return true;
434+
}
435+
408436
bool CPlusPlusLanguage::CxxMethodName::TrySimplifiedParse() {
409437
// This method tries to parse simple method definitions which are presumably
410438
// most comman in user programs. Definitions that can be parsed by this
@@ -1914,8 +1942,6 @@ bool CPlusPlusLanguage::GetFunctionDisplayName(
19141942
bool CPlusPlusLanguage::HandleFrameFormatVariable(
19151943
const SymbolContext &sc, const ExecutionContext *exe_ctx,
19161944
FormatEntity::Entry::Type type, Stream &s) {
1917-
assert(sc.function);
1918-
19191945
switch (type) {
19201946
case FormatEntity::Entry::Type::FunctionScope: {
19211947
std::optional<llvm::StringRef> scope = GetDemangledScope(sc);
@@ -1949,6 +1975,14 @@ bool CPlusPlusLanguage::HandleFrameFormatVariable(
19491975
}
19501976

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