Michael137 created this revision. Michael137 added reviewers: aprantl, labath, jingham. Herald added a project: All. Michael137 requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
Previously we would try to find the closing parenthesis by doing a forward scan through the demangled function name. However, for arguments that contain parenthesis (e.g., function pointers) this would leave garbage in the frame function name. This patch addresses this by doing a reverse scan to find the closing parenthesis. **Example** For following function: int foo(std::function<int(void)> const& func) { return 1; } Before patch: frame #0: 0x000000010000151c a.out`foo(func= Function = bar() )> const&) at sample.cpp:11:49 After patch: frame #0: 0x000000010000151c a.out`foo(func= Function = bar() ) at sample.cpp:11:49 **Testing** - Added shell test Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D136761 Files: lldb/source/Core/FormatEntity.cpp lldb/test/Shell/Settings/Inputs/names.cpp lldb/test/Shell/Settings/TestFrameFormatNameWithArgs.test Index: lldb/test/Shell/Settings/TestFrameFormatNameWithArgs.test =================================================================== --- /dev/null +++ lldb/test/Shell/Settings/TestFrameFormatNameWithArgs.test @@ -0,0 +1,13 @@ +# RUN: %clangxx_host -g -O0 %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 +run +# CHECK: frame int foo<int ()>(t={{.*}}) +c +# CHECK: frame int foo<std::__1::function<int ()>>(t= Function = bar() ) +c +# CHECK: frame int foo<(anonymous namespace)::$_0>(t={{.*}}) +c +# CHECK: frame int foo<std::__1::function<int ()>>(t= Function = (anonymous namespace)::anon_bar() ) +q Index: lldb/test/Shell/Settings/Inputs/names.cpp =================================================================== --- /dev/null +++ lldb/test/Shell/Settings/Inputs/names.cpp @@ -0,0 +1,18 @@ +#include <functional> + +template <typename T> int foo(T const &t) { return 0; } + +int bar() { return 1; } + +namespace { +int anon_bar() { return 1; } +auto anon_lambda = [](std::function<int(int (*)(int))>) mutable {}; +} // namespace + +int main() { + foo(bar); + foo(std::function{bar}); + foo(anon_lambda); + foo(std::function{anon_bar}); + return 0; +} Index: lldb/source/Core/FormatEntity.cpp =================================================================== --- lldb/source/Core/FormatEntity.cpp +++ lldb/source/Core/FormatEntity.cpp @@ -1670,9 +1670,9 @@ open_paren = strchr(open_paren + strlen("(anonymous namespace)"), '('); if (open_paren) - close_paren = strchr(open_paren, ')'); + close_paren = strrchr(open_paren, ')'); } else - close_paren = strchr(open_paren, ')'); + close_paren = strrchr(open_paren, ')'); } if (open_paren)
Index: lldb/test/Shell/Settings/TestFrameFormatNameWithArgs.test =================================================================== --- /dev/null +++ lldb/test/Shell/Settings/TestFrameFormatNameWithArgs.test @@ -0,0 +1,13 @@ +# RUN: %clangxx_host -g -O0 %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 +run +# CHECK: frame int foo<int ()>(t={{.*}}) +c +# CHECK: frame int foo<std::__1::function<int ()>>(t= Function = bar() ) +c +# CHECK: frame int foo<(anonymous namespace)::$_0>(t={{.*}}) +c +# CHECK: frame int foo<std::__1::function<int ()>>(t= Function = (anonymous namespace)::anon_bar() ) +q Index: lldb/test/Shell/Settings/Inputs/names.cpp =================================================================== --- /dev/null +++ lldb/test/Shell/Settings/Inputs/names.cpp @@ -0,0 +1,18 @@ +#include <functional> + +template <typename T> int foo(T const &t) { return 0; } + +int bar() { return 1; } + +namespace { +int anon_bar() { return 1; } +auto anon_lambda = [](std::function<int(int (*)(int))>) mutable {}; +} // namespace + +int main() { + foo(bar); + foo(std::function{bar}); + foo(anon_lambda); + foo(std::function{anon_bar}); + return 0; +} Index: lldb/source/Core/FormatEntity.cpp =================================================================== --- lldb/source/Core/FormatEntity.cpp +++ lldb/source/Core/FormatEntity.cpp @@ -1670,9 +1670,9 @@ open_paren = strchr(open_paren + strlen("(anonymous namespace)"), '('); if (open_paren) - close_paren = strchr(open_paren, ')'); + close_paren = strrchr(open_paren, ')'); } else - close_paren = strchr(open_paren, ')'); + close_paren = strrchr(open_paren, ')'); } if (open_paren)
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits