demangle.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2018 The Abseil Authors.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // An async-signal-safe and thread-safe demangler for Itanium C++ ABI
  15. // (aka G++ V3 ABI).
  16. //
  17. // The demangler is implemented to be used in async signal handlers to
  18. // symbolize stack traces. We cannot use libstdc++'s
  19. // abi::__cxa_demangle() in such signal handlers since it's not async
  20. // signal safe (it uses malloc() internally).
  21. //
  22. // Note that this demangler doesn't support full demangling. More
  23. // specifically, it doesn't print types of function parameters and
  24. // types of template arguments. It just skips them. However, it's
  25. // still very useful to extract basic information such as class,
  26. // function, constructor, destructor, and operator names.
  27. //
  28. // See the implementation note in demangle.cc if you are interested.
  29. //
  30. // Example:
  31. //
  32. // | Mangled Name | The Demangler | abi::__cxa_demangle()
  33. // |---------------|---------------|-----------------------
  34. // | _Z1fv | f() | f()
  35. // | _Z1fi | f() | f(int)
  36. // | _Z3foo3bar | foo() | foo(bar)
  37. // | _Z1fIiEvi | f<>() | void f<int>(int)
  38. // | _ZN1N1fE | N::f | N::f
  39. // | _ZN3Foo3BarEv | Foo::Bar() | Foo::Bar()
  40. // | _Zrm1XS_" | operator%() | operator%(X, X)
  41. // | _ZN3FooC1Ev | Foo::Foo() | Foo::Foo()
  42. // | _Z1fSs | f() | f(std::basic_string<char,
  43. // | | | std::char_traits<char>,
  44. // | | | std::allocator<char> >)
  45. //
  46. // See the unit test for more examples.
  47. //
  48. // Note: we might want to write demanglers for ABIs other than Itanium
  49. // C++ ABI in the future.
  50. //
  51. #ifndef Y_ABSL_DEBUGGING_INTERNAL_DEMANGLE_H_
  52. #define Y_ABSL_DEBUGGING_INTERNAL_DEMANGLE_H_
  53. #include "y_absl/base/config.h"
  54. namespace y_absl {
  55. Y_ABSL_NAMESPACE_BEGIN
  56. namespace debugging_internal {
  57. // Demangle `mangled`. On success, return true and write the
  58. // demangled symbol name to `out`. Otherwise, return false.
  59. // `out` is modified even if demangling is unsuccessful.
  60. bool Demangle(const char* mangled, char* out, size_t out_size);
  61. } // namespace debugging_internal
  62. Y_ABSL_NAMESPACE_END
  63. } // namespace y_absl
  64. #endif // Y_ABSL_DEBUGGING_INTERNAL_DEMANGLE_H_