https://github.com/ZequanWu created https://github.com/llvm/llvm-project/pull/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). >From dbd04f25ccb37a18b316078df7817a603f007396 Mon Sep 17 00:00:00 2001 From: Zequan Wu <zequa...@google.com> Date: Wed, 17 Jan 2024 14:22:01 -0500 Subject: [PATCH 1/2] [lldb][Format] Fix missing inlined function names in frame formatting. --- lldb/source/Core/FormatEntity.cpp | 29 +++++++--- .../Language/CPlusPlus/CPlusPlusLanguage.cpp | 2 +- lldb/test/Shell/Settings/Inputs/names.cpp | 8 ++- .../Shell/Settings/TestFrameFormatName.test | 55 +++++++++++++++++++ .../Settings/TestFrameFormatNameWithArgs.test | 26 --------- 5 files changed, 85 insertions(+), 35 deletions(-) create mode 100644 lldb/test/Shell/Settings/TestFrameFormatName.test delete mode 100644 lldb/test/Shell/Settings/TestFrameFormatNameWithArgs.test diff --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp index 94986457552d949..d5adcb9d863f334 100644 --- a/lldb/source/Core/FormatEntity.cpp +++ b/lldb/source/Core/FormatEntity.cpp @@ -1597,7 +1597,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s, Block *inline_block = sc->block->GetContainingInlinedBlock(); if (inline_block) { const InlineFunctionInfo *inline_info = - sc->block->GetInlinedFunctionInfo(); + inline_block->GetInlinedFunctionInfo(); if (inline_info) { s.PutCString(" [inlined] "); inline_info->GetName().Dump(&s); @@ -1638,6 +1638,17 @@ bool FormatEntity::Format(const Entry &entry, Stream &s, name = sc->symbol->GetNameNoArguments(); if (name) { s.PutCString(name.GetCString()); + if (sc->block) { + Block *inline_block = sc->block->GetContainingInlinedBlock(); + if (inline_block) { + const InlineFunctionInfo *inline_info = + inline_block->GetInlinedFunctionInfo(); + if (inline_info) { + s.PutCString(" [inlined] "); + inline_info->GetName().Dump(&s); + } + } + } return true; } } @@ -1678,7 +1689,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s, if (inline_block) { get_function_vars = false; - inline_info = sc->block->GetInlinedFunctionInfo(); + inline_info = inline_block->GetInlinedFunctionInfo(); if (inline_info) variable_list_sp = inline_block->GetBlockVariableList(true); } @@ -1734,11 +1745,15 @@ bool FormatEntity::Format(const Entry &entry, Stream &s, return false; s.PutCString(name); - if (sc->block && sc->block->GetContainingInlinedBlock()) { - if (const InlineFunctionInfo *inline_info = - sc->block->GetInlinedFunctionInfo()) { - s.PutCString(" [inlined] "); - inline_info->GetName().Dump(&s); + if (sc->block) { + Block *inline_block = sc->block->GetContainingInlinedBlock(); + if (inline_block) { + const InlineFunctionInfo *inline_info = + inline_block->GetInlinedFunctionInfo(); + if (inline_info) { + s.PutCString(" [inlined] "); + inline_info->GetName().Dump(&s); + } } } return true; diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp index 7131ccb9d05ecae..21c73e6361904e5 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp @@ -1646,7 +1646,7 @@ bool CPlusPlusLanguage::GetFunctionDisplayName( if (inline_block) { get_function_vars = false; - inline_info = sc->block->GetInlinedFunctionInfo(); + inline_info = inline_block->GetInlinedFunctionInfo(); if (inline_info) variable_list_sp = inline_block->GetBlockVariableList(true); } diff --git a/lldb/test/Shell/Settings/Inputs/names.cpp b/lldb/test/Shell/Settings/Inputs/names.cpp index cf6982abb8f3546..79ff93be6b76ed3 100644 --- a/lldb/test/Shell/Settings/Inputs/names.cpp +++ b/lldb/test/Shell/Settings/Inputs/names.cpp @@ -26,6 +26,12 @@ int anon_bar() { return 1; } auto anon_lambda = [] {}; } // namespace +__attribute__((always_inline)) int inlined_foo(const char *str) { + if (bool b = bar()) + return 1; + return 2; +} + int main() { ns::foo<decltype(bar)>(bar); ns::foo<decltype(bar)>("bar"); @@ -37,6 +43,6 @@ int main() { f.foo(anon_bar); f.operator<< <(2 > 1)>(0); f.returns_func_ptr<int>(detail::Quux<int>{}); - + inlined_foo("bar"); return 0; } diff --git a/lldb/test/Shell/Settings/TestFrameFormatName.test b/lldb/test/Shell/Settings/TestFrameFormatName.test new file mode 100644 index 000000000000000..caa3242527c6ef4 --- /dev/null +++ b/lldb/test/Shell/Settings/TestFrameFormatName.test @@ -0,0 +1,55 @@ +# UNSUPPORTED: system-windows +# Test different name formats. + +# RUN: %build %S/Inputs/names.cpp --std c++17 -o %t.out +# RUN: split-file %s %t + +#--- name_with_args.input +# RUN: %lldb -b -s %t/name_with_args.input %t.out | FileCheck %s --check-prefix=NAME_WITH_ARGS +settings set -f frame-format "frame ${function.name-with-args}\n" +break set -n foo +break set -n operator<< +break set -n returns_func_ptr +break set -n inlined_foo +run +# NAME_WITH_ARGS: frame int ns::foo<int ()>(t={{.*}}) +c +# NAME_WITH_ARGS: frame int ns::foo<int ()>(str="bar") +c +# NAME_WITH_ARGS: frame int ns::foo<(anonymous namespace)::$_0>(t=(anonymous namespace)::(unnamed class) @ {{.*}}) +c +# NAME_WITH_ARGS: frame int ns::foo<int (*)()>(t=({{.*}}`(anonymous namespace)::anon_bar() at {{.*}})) +c +# NAME_WITH_ARGS: frame int ns::foo<void (Foo::*)(int (*)(int)) const noexcept>(str="method") +c +# NAME_WITH_ARGS: frame ns::returns_func_ptr<int>((null)={{.*}}) +c +# NAME_WITH_ARGS: frame void Foo::foo<int (*)()>(this={{.*}}, arg=({{.*}}`(anonymous namespace)::anon_bar() at {{.*}})) +c +# NAME_WITH_ARGS: frame void Foo::operator<<<1>(this={{.*}}, (null)=0) +c +# NAME_WITH_ARGS: frame Foo::returns_func_ptr<int>(this={{.*}}, (null)={{.*}}) +c +# NAME_WITH_ARGS: frame main [inlined] inlined_foo(str="bar") +q + +#--- name.input +# RUN: %lldb -b -s %t/name.input %t.out | FileCheck %s --check-prefix=NAME +settings set -f frame-format "frame ${function.name}\n" +break set -n inlined_foo +run +# NAME: frame main [inlined] inlined_foo(char const*) + +#--- name_without_args.input +# RUN: %lldb -b -s %t/name_without_args.input %t.out | FileCheck %s --check-prefix=NAME_WITHOUT_ARGS +settings set -f frame-format "frame ${function.name-without-args}\n" +break set -n inlined_foo +run +# NAME_WITHOUT_ARGS: frame main [inlined] inlined_foo(char const*) + +#--- mangled_name.input +# RUN: %lldb -b -s %t/mangled_name.input %t.out | FileCheck %s --check-prefix=MANGLED_NAME +settings set -f frame-format "frame ${function.mangled-name}\n" +break set -n inlined_foo +run +# MANGLED_NAME: frame main [inlined] inlined_foo(char const*) diff --git a/lldb/test/Shell/Settings/TestFrameFormatNameWithArgs.test b/lldb/test/Shell/Settings/TestFrameFormatNameWithArgs.test deleted file mode 100644 index eeb46cfd6bf9d6c..000000000000000 --- a/lldb/test/Shell/Settings/TestFrameFormatNameWithArgs.test +++ /dev/null @@ -1,26 +0,0 @@ -# UNSUPPORTED: system-windows -# RUN: %build %S/Inputs/names.cpp --std c++17 -o %t.out -# RUN: %lldb -b -s %s %t.out | FileCheck %s -settings set -f frame-format "frame ${function.name-with-args}\n" -break set -n foo -break set -n operator<< -break set -n returns_func_ptr -run -# CHECK: frame int ns::foo<int ()>(t={{.*}}) -c -# CHECK: frame int ns::foo<int ()>(str="bar") -c -# CHECK: frame int ns::foo<(anonymous namespace)::$_0>(t=(anonymous namespace)::(unnamed class) @ {{.*}}) -c -# CHECK: frame int ns::foo<int (*)()>(t=({{.*}}`(anonymous namespace)::anon_bar() at {{.*}})) -c -# CHECK: frame int ns::foo<void (Foo::*)(int (*)(int)) const noexcept>(str="method") -c -# CHECK: frame ns::returns_func_ptr<int>((null)={{.*}}) -c -# CHECK: frame void Foo::foo<int (*)()>(this={{.*}}, arg=({{.*}}`(anonymous namespace)::anon_bar() at {{.*}})) -c -# CHECK: frame void Foo::operator<<<1>(this={{.*}}, (null)=0) -c -# CHECK: frame Foo::returns_func_ptr<int>(this={{.*}}, (null)={{.*}}) -q >From c47a0d524eb24b2609864829c17de9835ba9cfd3 Mon Sep 17 00:00:00 2001 From: Zequan Wu <zequa...@google.com> Date: Wed, 17 Jan 2024 14:38:17 -0500 Subject: [PATCH 2/2] [lldb][NFC] Refactor common logic for formatting inlined blocks. --- lldb/source/Core/FormatEntity.cpp | 52 ++++++++++--------------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp index d5adcb9d863f334..b7fb1e06e75b9e9 100644 --- a/lldb/source/Core/FormatEntity.cpp +++ b/lldb/source/Core/FormatEntity.cpp @@ -1093,6 +1093,20 @@ static void PrettyPrintFunctionNameWithArgs(Stream &out_stream, out_stream.PutChar(')'); } +static void FormatInlinedBlock(Stream &out_stream, Block *block) { + if (!block) + return; + Block *inline_block = block->GetContainingInlinedBlock(); + if (inline_block) { + const InlineFunctionInfo *inline_info = + inline_block->GetInlinedFunctionInfo(); + if (inline_info) { + out_stream.PutCString(" [inlined] "); + inline_info->GetName().Dump(&out_stream); + } + } +} + bool FormatEntity::FormatStringRef(const llvm::StringRef &format_str, Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, @@ -1592,18 +1606,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s, if (name) { s.PutCString(name); - - if (sc->block) { - Block *inline_block = sc->block->GetContainingInlinedBlock(); - if (inline_block) { - const InlineFunctionInfo *inline_info = - inline_block->GetInlinedFunctionInfo(); - if (inline_info) { - s.PutCString(" [inlined] "); - inline_info->GetName().Dump(&s); - } - } - } + FormatInlinedBlock(s, sc->block); return true; } } @@ -1638,17 +1641,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s, name = sc->symbol->GetNameNoArguments(); if (name) { s.PutCString(name.GetCString()); - if (sc->block) { - Block *inline_block = sc->block->GetContainingInlinedBlock(); - if (inline_block) { - const InlineFunctionInfo *inline_info = - inline_block->GetInlinedFunctionInfo(); - if (inline_info) { - s.PutCString(" [inlined] "); - inline_info->GetName().Dump(&s); - } - } - } + FormatInlinedBlock(s, sc->block); return true; } } @@ -1744,18 +1737,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s, if (!name) return false; s.PutCString(name); - - if (sc->block) { - Block *inline_block = sc->block->GetContainingInlinedBlock(); - if (inline_block) { - const InlineFunctionInfo *inline_info = - inline_block->GetInlinedFunctionInfo(); - if (inline_info) { - s.PutCString(" [inlined] "); - inline_info->GetName().Dump(&s); - } - } - } + FormatInlinedBlock(s, sc->block); return true; } case Entry::Type::FunctionAddrOffset: _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits