[Lldb-commits] [lldb] [lldb][Format] Make function name frame-format variables work without debug-info (PR #137408)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Sun Apr 27 13:46:21 PDT 2025
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/137408
>From db417e84e944ee80f045414a4ce0f83a3e423e45 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Fri, 25 Apr 2025 22:49:36 +0100
Subject: [PATCH 1/2] [lldb][CPlusPLus] Make C++ frame-format work without
debug-info
---
lldb/source/Core/FormatEntity.cpp | 9 +++--
.../Language/CPlusPlus/CPlusPlusLanguage.cpp | 38 ++++++++++++++++++-
.../TestFrameFormatFunctionBasename.test | 4 ++
...FrameFormatFunctionFormattedArguments.test | 9 +++++
.../TestFrameFormatFunctionQualifiers.test | 4 ++
.../TestFrameFormatFunctionReturn.test | 4 ++
.../TestFrameFormatFunctionScope.test | 7 +++-
...tFrameFormatFunctionTemplateArguments.test | 8 +++-
8 files changed, 73 insertions(+), 10 deletions(-)
diff --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp
index e352d07fe487d..4ac50e2d30f3c 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -1809,11 +1809,12 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
case Entry::Type::FunctionReturnRight:
case Entry::Type::FunctionReturnLeft:
case Entry::Type::FunctionQualifiers: {
- if (!sc->function)
- return false;
+ Language *language_plugin = nullptr;
+ if (sc->function)
+ language_plugin = Language::FindPlugin(sc->function->GetLanguage());
+ else if (sc->symbol)
+ language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
- Language *language_plugin =
- Language::FindPlugin(sc->function->GetLanguage());
if (!language_plugin)
return false;
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 283e867d53bb7..ab8e9883868ce 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -381,6 +381,34 @@ GetDemangledScope(const SymbolContext &sc) {
return demangled_name.slice(info->ScopeRange.first, info->ScopeRange.second);
}
+static bool PrintDemangledArgumentList(Stream &s, const SymbolContext &sc) {
+ assert(sc.symbol);
+
+ Mangled mangled = sc.GetPossiblyInlinedFunctionName();
+ if (!mangled)
+ return false;
+
+ auto demangled_name = mangled.GetDemangledName().GetStringRef();
+ if (demangled_name.empty())
+ return false;
+
+ const std::optional<DemangledNameInfo> &info = mangled.GetDemangledInfo();
+ if (!info)
+ return false;
+
+ // Function without a basename is nonsense.
+ if (!info->hasBasename())
+ return false;
+
+ if (info->ArgumentsRange.second < info->ArgumentsRange.first)
+ return false;
+
+ s << demangled_name.slice(info->ArgumentsRange.first,
+ info->ArgumentsRange.second);
+
+ return true;
+}
+
bool CPlusPlusLanguage::CxxMethodName::TrySimplifiedParse() {
// This method tries to parse simple method definitions which are presumably
// most comman in user programs. Definitions that can be parsed by this
@@ -1890,8 +1918,6 @@ bool CPlusPlusLanguage::GetFunctionDisplayName(
bool CPlusPlusLanguage::HandleFrameFormatVariable(
const SymbolContext &sc, const ExecutionContext *exe_ctx,
FormatEntity::Entry::Type type, Stream &s) {
- assert(sc.function);
-
switch (type) {
case FormatEntity::Entry::Type::FunctionScope: {
std::optional<llvm::StringRef> scope = GetDemangledScope(sc);
@@ -1925,6 +1951,14 @@ bool CPlusPlusLanguage::HandleFrameFormatVariable(
}
case FormatEntity::Entry::Type::FunctionFormattedArguments: {
+ // This ensures we print the arguments even when no debug-info is available.
+ //
+ // FIXME: we should have a Entry::Type::FunctionArguments and
+ // use it in the plugin.cplusplus.display.function-name-format
+ // once we have a "fallback operator" in the frame-format language.
+ if (!sc.function && sc.symbol)
+ return PrintDemangledArgumentList(s, sc);
+
VariableList args;
if (auto variable_list_sp = GetFunctionVariableList(sc))
variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument,
diff --git a/lldb/test/Shell/Settings/TestFrameFormatFunctionBasename.test b/lldb/test/Shell/Settings/TestFrameFormatFunctionBasename.test
index a2cb1c6adf064..7e34fbd3855d0 100644
--- a/lldb/test/Shell/Settings/TestFrameFormatFunctionBasename.test
+++ b/lldb/test/Shell/Settings/TestFrameFormatFunctionBasename.test
@@ -7,6 +7,10 @@
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
# RUN: | FileCheck %s
#
+# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
+# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
+# RUN: | FileCheck %s
+
#--- main.cpp
namespace ns {
template<typename T>
diff --git a/lldb/test/Shell/Settings/TestFrameFormatFunctionFormattedArguments.test b/lldb/test/Shell/Settings/TestFrameFormatFunctionFormattedArguments.test
index c4c9062b640f1..04f51701a2a2d 100644
--- a/lldb/test/Shell/Settings/TestFrameFormatFunctionFormattedArguments.test
+++ b/lldb/test/Shell/Settings/TestFrameFormatFunctionFormattedArguments.test
@@ -6,6 +6,10 @@
# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.out
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
# RUN: | FileCheck %s
+#
+# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
+# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
+# RUN: | FileCheck %s --check-prefix=CHECK-NODEBUG
#--- main.cpp
struct Foo {
@@ -42,3 +46,8 @@ bt
# CHECK: custom-frame '({{.*}}=5, x=10)'
# CHECK: custom-frame '(str="hello", fptr=({{.*}}.out`{{.*}}foo(int,{{.*}}int) at main.cpp:{{[0-9]+}}))'
# CHECK: custom-frame '(argc=1, argv={{.*}})'
+
+# CHECK-NODEBUG: custom-frame '()'
+# CHECK-NODEBUG: custom-frame '()'
+# CHECK-NODEBUG: custom-frame '(int, int)'
+# CHECK-NODEBUG: custom-frame '(char const*, void (*)(int, int))'
diff --git a/lldb/test/Shell/Settings/TestFrameFormatFunctionQualifiers.test b/lldb/test/Shell/Settings/TestFrameFormatFunctionQualifiers.test
index c4b74b7d7defa..b1dfe834c1deb 100644
--- a/lldb/test/Shell/Settings/TestFrameFormatFunctionQualifiers.test
+++ b/lldb/test/Shell/Settings/TestFrameFormatFunctionQualifiers.test
@@ -6,6 +6,10 @@
# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.out
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
# RUN: | FileCheck %s
+#
+# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
+# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
+# RUN: | FileCheck %s
#--- main.cpp
struct Foo {
diff --git a/lldb/test/Shell/Settings/TestFrameFormatFunctionReturn.test b/lldb/test/Shell/Settings/TestFrameFormatFunctionReturn.test
index ce970d4d24d86..f913162a1aa66 100644
--- a/lldb/test/Shell/Settings/TestFrameFormatFunctionReturn.test
+++ b/lldb/test/Shell/Settings/TestFrameFormatFunctionReturn.test
@@ -7,6 +7,10 @@
# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.out
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
# RUN: | FileCheck %s
+#
+# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
+# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
+# RUN: | FileCheck %s
#--- main.cpp
namespace ns::ns2 {
diff --git a/lldb/test/Shell/Settings/TestFrameFormatFunctionScope.test b/lldb/test/Shell/Settings/TestFrameFormatFunctionScope.test
index d98893aa5e8b4..a28c16f95a9e2 100644
--- a/lldb/test/Shell/Settings/TestFrameFormatFunctionScope.test
+++ b/lldb/test/Shell/Settings/TestFrameFormatFunctionScope.test
@@ -4,8 +4,11 @@
# RUN: split-file %s %t
# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.out
-# RUN: %lldb -o "settings set interpreter.stop-command-source-on-error false" \
-# RUN: -x -b -s %t/commands.input %t.out -o exit 2>&1 \
+# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
+# RUN: | FileCheck %s
+#
+# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
+# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
# RUN: | FileCheck %s
#--- main.cpp
diff --git a/lldb/test/Shell/Settings/TestFrameFormatFunctionTemplateArguments.test b/lldb/test/Shell/Settings/TestFrameFormatFunctionTemplateArguments.test
index f0c29bcee2ce5..1421c8e918a03 100644
--- a/lldb/test/Shell/Settings/TestFrameFormatFunctionTemplateArguments.test
+++ b/lldb/test/Shell/Settings/TestFrameFormatFunctionTemplateArguments.test
@@ -3,8 +3,12 @@
# Test the ${function.template-arguments} frame-format variable.
# RUN: split-file %s %t
-# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.cxx.out
-# RUN: %lldb -x -b -s %t/commands.input %t.cxx.out -o exit 2>&1 \
+# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.out
+# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
+# RUN: | FileCheck %s
+#
+# RUN: %clang_host -O0 %t/main.cpp -o %t-nodebug.out
+# RUN: %lldb -x -b -s %t/commands.input %t-nodebug.out -o exit 2>&1 \
# RUN: | FileCheck %s
#--- main.cpp
>From 1af69b61f32147cf99b9192a7c14a849b7862f42 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Sun, 27 Apr 2025 16:13:08 +0100
Subject: [PATCH 2/2] fixup! set breakpoints by name
---
lldb/test/Shell/Settings/TestFrameFormatFunctionBasename.test | 2 +-
.../Settings/TestFrameFormatFunctionTemplateArguments.test | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lldb/test/Shell/Settings/TestFrameFormatFunctionBasename.test b/lldb/test/Shell/Settings/TestFrameFormatFunctionBasename.test
index 7d9963da352bc..c0008e50927b1 100644
--- a/lldb/test/Shell/Settings/TestFrameFormatFunctionBasename.test
+++ b/lldb/test/Shell/Settings/TestFrameFormatFunctionBasename.test
@@ -42,7 +42,7 @@ int main() {
#--- commands.input
settings set -f frame-format "custom-frame '${function.basename}'\n"
-break set -l 5 -f main.cpp
+break set -n bar
run
bt
diff --git a/lldb/test/Shell/Settings/TestFrameFormatFunctionTemplateArguments.test b/lldb/test/Shell/Settings/TestFrameFormatFunctionTemplateArguments.test
index abd0d3a1ba484..ac8a32820c888 100644
--- a/lldb/test/Shell/Settings/TestFrameFormatFunctionTemplateArguments.test
+++ b/lldb/test/Shell/Settings/TestFrameFormatFunctionTemplateArguments.test
@@ -33,7 +33,7 @@ int main() { return bar(); }
#--- commands.input
settings set -f frame-format "custom-frame '${function.template-arguments}'\n"
-break set -l 4 -f main.cpp
+break set -n func
run
bt
More information about the lldb-commits
mailing list