Skip to content

Commit 63a74fe

Browse files
committed
[lldb][CPlusPLus] Make C++ frame-format work without debug-info
1 parent b571aa4 commit 63a74fe

8 files changed

+78
-15
lines changed

lldb/source/Core/FormatEntity.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,11 +1809,12 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
18091809
case Entry::Type::FunctionReturnRight:
18101810
case Entry::Type::FunctionReturnLeft:
18111811
case Entry::Type::FunctionQualifiers: {
1812-
if (!sc->function)
1813-
return false;
1812+
Language *language_plugin = nullptr;
1813+
if (sc->function)
1814+
language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1815+
else if (sc->symbol)
1816+
language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
18141817

1815-
Language *language_plugin =
1816-
Language::FindPlugin(sc->function->GetLanguage());
18171818
if (!language_plugin)
18181819
return false;
18191820

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

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

384+
static bool PrintDemangledArgumentList(Stream &s, const SymbolContext &sc) {
385+
assert(sc.symbol);
386+
387+
Mangled mangled = sc.GetPossiblyInlinedFunctionName();
388+
if (!mangled)
389+
return false;
390+
391+
auto demangled_name = mangled.GetDemangledName().GetStringRef();
392+
if (demangled_name.empty())
393+
return false;
394+
395+
const std::optional<DemangledNameInfo> &info = mangled.GetDemangledInfo();
396+
if (!info)
397+
return false;
398+
399+
// Function without a basename is nonsense.
400+
if (!info->hasBasename())
401+
return false;
402+
403+
if (info->ArgumentsRange.second < info->ArgumentsRange.first)
404+
return false;
405+
406+
s << demangled_name.slice(info->ArgumentsRange.first,
407+
info->ArgumentsRange.second);
408+
409+
return true;
410+
}
411+
384412
bool CPlusPlusLanguage::CxxMethodName::TrySimplifiedParse() {
385413
// This method tries to parse simple method definitions which are presumably
386414
// most comman in user programs. Definitions that can be parsed by this
@@ -1890,8 +1918,6 @@ bool CPlusPlusLanguage::GetFunctionDisplayName(
18901918
bool CPlusPlusLanguage::HandleFrameFormatVariable(
18911919
const SymbolContext &sc, const ExecutionContext *exe_ctx,
18921920
FormatEntity::Entry::Type type, Stream &s) {
1893-
assert(sc.function);
1894-
18951921
switch (type) {
18961922
case FormatEntity::Entry::Type::FunctionScope: {
18971923
std::optional<llvm::StringRef> scope = GetDemangledScope(sc);
@@ -1925,6 +1951,14 @@ bool CPlusPlusLanguage::HandleFrameFormatVariable(
19251951
}
19261952

19271953
case FormatEntity::Entry::Type::FunctionFormattedArguments: {
1954+
// This ensures we print the arguments even when no debug-info is available.
1955+
//
1956+
// FIXME: we should have a Entry::Type::FunctionArguments and
1957+
// use it in the plugin.cplusplus.display.function-name-format
1958+
// once we have a "fallback operator" in the frame-format language.
1959+
if (!sc.function && sc.symbol)
1960+
return PrintDemangledArgumentList(s, sc);
1961+
19281962
VariableList args;
19291963
if (auto variable_list_sp = GetFunctionVariableList(sc))
19301964
variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument,

lldb/test/Shell/Settings/TestFrameFormatFunctionBasename.test

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Test the ${function.basename} frame-format variable.
22

33
# RUN: split-file %s %t
4-
# RUN: %build %t/main.cpp -o %t.out
4+
# RUN: %clang_host -g %t/main.cpp -o %t.out
55
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
66
# RUN: | FileCheck %s
77
#
8+
# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
9+
# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
10+
# RUN: | FileCheck %s
11+
812
#--- main.cpp
913
namespace ns {
1014
template<typename T>

lldb/test/Shell/Settings/TestFrameFormatFunctionFormattedArguments.test

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# Test the ${function.formatted-arguments} frame-format variable.
22

33
# RUN: split-file %s %t
4-
# RUN: %build %t/main.cpp -o %t.out
4+
# RUN: %clang_host -g %t/main.cpp -o %t.out
55
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
66
# RUN: | FileCheck %s
7+
#
8+
# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
9+
# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
10+
# RUN: | FileCheck %s --check-prefix=CHECK-NODEBUG
711

812
#--- main.cpp
913
struct Foo {
@@ -40,3 +44,8 @@ bt
4044
# CHECK: custom-frame '((null)=5, x=10)'
4145
# CHECK: custom-frame '(str="hello", fptr=({{.*}}.out`foo(int, int) at main.cpp:{{[0-9]+}}))'
4246
# CHECK: custom-frame '(argc=1, argv={{.*}})'
47+
48+
# CHECK-NODEBUG: custom-frame '()'
49+
# CHECK-NODEBUG: custom-frame '()'
50+
# CHECK-NODEBUG: custom-frame '(int, int)'
51+
# CHECK-NODEBUG: custom-frame '(char const*, void (*)(int, int))'

lldb/test/Shell/Settings/TestFrameFormatFunctionQualifiers.test

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# Test the ${function.qualifiers} frame-format variable.
22

33
# RUN: split-file %s %t
4-
# RUN: %build %t/main.cpp -o %t.out
4+
# RUN: %clang_host -g %t/main.cpp -o %t.out
55
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
66
# RUN: | FileCheck %s
7+
#
8+
# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
9+
# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
10+
# RUN: | FileCheck %s
711

812
#--- main.cpp
913
struct Foo {

lldb/test/Shell/Settings/TestFrameFormatFunctionReturn.test

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
# frame-format variables.
33

44
# RUN: split-file %s %t
5-
# RUN: %build %t/main.cpp -o %t.out
5+
# RUN: %clang_host -g %t/main.cpp -o %t.out
66
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
77
# RUN: | FileCheck %s
8+
#
9+
# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
10+
# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
11+
# RUN: | FileCheck %s
812

913
#--- main.cpp
1014
namespace ns::ns2 {

lldb/test/Shell/Settings/TestFrameFormatFunctionScope.test

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# Test the ${function.scope} frame-format variable.
22

33
# RUN: split-file %s %t
4-
# RUN: %build %t/main.cpp -o %t.out
5-
# RUN: %lldb -o "settings set interpreter.stop-command-source-on-error false" \
6-
# RUN: -x -b -s %t/commands.input %t.out -o exit 2>&1 \
4+
# RUN: %clang_host -g %t/main.cpp -o %t.out
5+
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
6+
# RUN: | FileCheck %s
7+
#
8+
# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
9+
# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
710
# RUN: | FileCheck %s
811

912
#--- main.cpp

lldb/test/Shell/Settings/TestFrameFormatFunctionTemplateArguments.test

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

33
# RUN: split-file %s %t
4-
# RUN: %build %t/main.cpp -o %t.cxx.out
5-
# RUN: %lldb -x -b -s %t/commands.input %t.cxx.out -o exit 2>&1 \
4+
# RUN: %clang_host -g %t/main.cpp -o %t.out
5+
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
6+
# RUN: | FileCheck %s
7+
#
8+
# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
9+
# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
610
# RUN: | FileCheck %s
711

812
#--- main.cpp

0 commit comments

Comments
 (0)