This patch implements the `GetFunctionDisplayName` API which gets
used by the frame-formatting code to decide how to print a
function name.
Currently this API trivially returns `false`, so we try to parse
the demangled function base-name by hand. We try find the closing
parenthesis by doing a forward scan through the demangled name. However,
for arguments that contain parenthesis (e.g., function pointers)
this would leave garbage in the frame function name.
By re-using the `CPlusPlusLanguage` parser for this we offload the
need to parse function names to a component that knows how to do this
already.
We leave the existing parsing code in `FormatEntity` since it's used
in cases where a language-plugin is not available (and is not
necessarily C++ specific).
**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
44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
#include <functional>
|
|
|
|
namespace detail {
|
|
template <typename T> struct Quux {};
|
|
} // namespace detail
|
|
|
|
using FuncPtr = detail::Quux<double> (*(*)(int))(float);
|
|
|
|
struct Foo {
|
|
template <typename T> void foo(T const &t) const noexcept(true) {}
|
|
|
|
template <size_t T> void operator<<(size_t) {}
|
|
|
|
template <typename T> FuncPtr returns_func_ptr(detail::Quux<int> &&) const noexcept(false) { return nullptr; }
|
|
};
|
|
|
|
namespace ns {
|
|
template <typename T> int foo(T const &t) noexcept(false) { return 0; }
|
|
|
|
template <typename T> FuncPtr returns_func_ptr(detail::Quux<int> &&) { return nullptr; }
|
|
} // namespace ns
|
|
|
|
int bar() { return 1; }
|
|
|
|
namespace {
|
|
int anon_bar() { return 1; }
|
|
auto anon_lambda = [](std::function<int(int (*)(int))>) mutable {};
|
|
} // namespace
|
|
|
|
int main() {
|
|
ns::foo(bar);
|
|
ns::foo(std::function{bar});
|
|
ns::foo(anon_lambda);
|
|
ns::foo(std::function{anon_bar});
|
|
ns::foo(&Foo::foo<std::function<int(int)>>);
|
|
ns::returns_func_ptr<int>(detail::Quux<int>{});
|
|
Foo f;
|
|
f.foo(std::function{bar});
|
|
f.foo(std::function{anon_bar});
|
|
f.operator<< <(2 > 1)>(0);
|
|
f.returns_func_ptr<int>(detail::Quux<int>{});
|
|
return 0;
|
|
}
|