Skip to content

Commit f4ede08

Browse files
authored
[lldb][Format] Fix missing inlined function names in frame formatting. (#78494)
This fixes missing inlined function names when formatting frame and the `Block` in `SymbolContext` is a lexical block (e.g. `DW_TAG_lexical_block` in Dwarf).
1 parent f204886 commit f4ede08

File tree

5 files changed

+80
-49
lines changed

5 files changed

+80
-49
lines changed

lldb/source/Core/FormatEntity.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,19 @@ static void PrettyPrintFunctionNameWithArgs(Stream &out_stream,
10931093
out_stream.PutChar(')');
10941094
}
10951095

1096+
static void FormatInlinedBlock(Stream &out_stream, Block *block) {
1097+
if (!block)
1098+
return;
1099+
Block *inline_block = block->GetContainingInlinedBlock();
1100+
if (inline_block) {
1101+
if (const InlineFunctionInfo *inline_info =
1102+
inline_block->GetInlinedFunctionInfo()) {
1103+
out_stream.PutCString(" [inlined] ");
1104+
inline_info->GetName().Dump(&out_stream);
1105+
}
1106+
}
1107+
}
1108+
10961109
bool FormatEntity::FormatStringRef(const llvm::StringRef &format_str, Stream &s,
10971110
const SymbolContext *sc,
10981111
const ExecutionContext *exe_ctx,
@@ -1592,18 +1605,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
15921605

15931606
if (name) {
15941607
s.PutCString(name);
1595-
1596-
if (sc->block) {
1597-
Block *inline_block = sc->block->GetContainingInlinedBlock();
1598-
if (inline_block) {
1599-
const InlineFunctionInfo *inline_info =
1600-
sc->block->GetInlinedFunctionInfo();
1601-
if (inline_info) {
1602-
s.PutCString(" [inlined] ");
1603-
inline_info->GetName().Dump(&s);
1604-
}
1605-
}
1606-
}
1608+
FormatInlinedBlock(s, sc->block);
16071609
return true;
16081610
}
16091611
}
@@ -1638,6 +1640,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
16381640
name = sc->symbol->GetNameNoArguments();
16391641
if (name) {
16401642
s.PutCString(name.GetCString());
1643+
FormatInlinedBlock(s, sc->block);
16411644
return true;
16421645
}
16431646
}
@@ -1678,7 +1681,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
16781681

16791682
if (inline_block) {
16801683
get_function_vars = false;
1681-
inline_info = sc->block->GetInlinedFunctionInfo();
1684+
inline_info = inline_block->GetInlinedFunctionInfo();
16821685
if (inline_info)
16831686
variable_list_sp = inline_block->GetBlockVariableList(true);
16841687
}
@@ -1733,14 +1736,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
17331736
if (!name)
17341737
return false;
17351738
s.PutCString(name);
1736-
1737-
if (sc->block && sc->block->GetContainingInlinedBlock()) {
1738-
if (const InlineFunctionInfo *inline_info =
1739-
sc->block->GetInlinedFunctionInfo()) {
1740-
s.PutCString(" [inlined] ");
1741-
inline_info->GetName().Dump(&s);
1742-
}
1743-
}
1739+
FormatInlinedBlock(s, sc->block);
17441740
return true;
17451741
}
17461742
case Entry::Type::FunctionAddrOffset:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ bool CPlusPlusLanguage::GetFunctionDisplayName(
16461646

16471647
if (inline_block) {
16481648
get_function_vars = false;
1649-
inline_info = sc->block->GetInlinedFunctionInfo();
1649+
inline_info = inline_block->GetInlinedFunctionInfo();
16501650
if (inline_info)
16511651
variable_list_sp = inline_block->GetBlockVariableList(true);
16521652
}

lldb/test/Shell/Settings/Inputs/names.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ int anon_bar() { return 1; }
2626
auto anon_lambda = [] {};
2727
} // namespace
2828

29+
__attribute__((always_inline)) int inlined_foo(const char *str) {
30+
if (bool b = bar())
31+
return 1;
32+
return 2;
33+
}
34+
2935
int main() {
3036
ns::foo<decltype(bar)>(bar);
3137
ns::foo<decltype(bar)>("bar");
@@ -37,6 +43,6 @@ int main() {
3743
f.foo(anon_bar);
3844
f.operator<< <(2 > 1)>(0);
3945
f.returns_func_ptr<int>(detail::Quux<int>{});
40-
46+
inlined_foo("bar");
4147
return 0;
4248
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# UNSUPPORTED: system-windows
2+
# Test different name formats.
3+
4+
# RUN: %build %S/Inputs/names.cpp --std c++17 -o %t.out
5+
# RUN: split-file %s %t
6+
7+
#--- name_with_args.input
8+
# RUN: %lldb -b -s %t/name_with_args.input %t.out | FileCheck %s --check-prefix=NAME_WITH_ARGS
9+
settings set -f frame-format "frame ${function.name-with-args}\n"
10+
break set -n foo
11+
break set -n operator<<
12+
break set -n returns_func_ptr
13+
break set -n inlined_foo
14+
run
15+
# NAME_WITH_ARGS: frame int ns::foo<int ()>(t={{.*}})
16+
c
17+
# NAME_WITH_ARGS: frame int ns::foo<int ()>(str="bar")
18+
c
19+
# NAME_WITH_ARGS: frame int ns::foo<(anonymous namespace)::$_0>(t=(anonymous namespace)::(unnamed class) @ {{.*}})
20+
c
21+
# NAME_WITH_ARGS: frame int ns::foo<int (*)()>(t=({{.*}}`(anonymous namespace)::anon_bar() at {{.*}}))
22+
c
23+
# NAME_WITH_ARGS: frame int ns::foo<void (Foo::*)(int (*)(int)) const noexcept>(str="method")
24+
c
25+
# NAME_WITH_ARGS: frame ns::returns_func_ptr<int>((null)={{.*}})
26+
c
27+
# NAME_WITH_ARGS: frame void Foo::foo<int (*)()>(this={{.*}}, arg=({{.*}}`(anonymous namespace)::anon_bar() at {{.*}}))
28+
c
29+
# NAME_WITH_ARGS: frame void Foo::operator<<<1>(this={{.*}}, (null)=0)
30+
c
31+
# NAME_WITH_ARGS: frame Foo::returns_func_ptr<int>(this={{.*}}, (null)={{.*}})
32+
c
33+
# NAME_WITH_ARGS: frame main [inlined] inlined_foo(str="bar")
34+
q
35+
36+
#--- name.input
37+
# RUN: %lldb -b -s %t/name.input %t.out | FileCheck %s --check-prefix=NAME
38+
settings set -f frame-format "frame ${function.name}\n"
39+
break set -n inlined_foo
40+
run
41+
# NAME: frame main [inlined] inlined_foo(char const*)
42+
43+
#--- name_without_args.input
44+
# RUN: %lldb -b -s %t/name_without_args.input %t.out | FileCheck %s --check-prefix=NAME_WITHOUT_ARGS
45+
settings set -f frame-format "frame ${function.name-without-args}\n"
46+
break set -n inlined_foo
47+
run
48+
# NAME_WITHOUT_ARGS: frame main [inlined] inlined_foo(char const*)
49+
50+
#--- mangled_name.input
51+
# RUN: %lldb -b -s %t/mangled_name.input %t.out | FileCheck %s --check-prefix=MANGLED_NAME
52+
settings set -f frame-format "frame ${function.mangled-name}\n"
53+
break set -n inlined_foo
54+
run
55+
# MANGLED_NAME: frame main [inlined] inlined_foo(char const*)

lldb/test/Shell/Settings/TestFrameFormatNameWithArgs.test

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)