demangle.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright (c) 2006, Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. //
  30. // Author: Satoru Takabayashi
  31. //
  32. // An async-signal-safe and thread-safe demangler for Itanium C++ ABI
  33. // (aka G++ V3 ABI).
  34. // The demangler is implemented to be used in async signal handlers to
  35. // symbolize stack traces. We cannot use libstdc++'s
  36. // abi::__cxa_demangle() in such signal handlers since it's not async
  37. // signal safe (it uses malloc() internally).
  38. //
  39. // Note that this demangler doesn't support full demangling. More
  40. // specifically, it doesn't print types of function parameters and
  41. // types of template arguments. It just skips them. However, it's
  42. // still very useful to extract basic information such as class,
  43. // function, constructor, destructor, and operator names.
  44. //
  45. // See the implementation note in demangle.cc if you are interested.
  46. //
  47. // Example:
  48. //
  49. // | Mangled Name | The Demangler | abi::__cxa_demangle()
  50. // |---------------|---------------|-----------------------
  51. // | _Z1fv | f() | f()
  52. // | _Z1fi | f() | f(int)
  53. // | _Z3foo3bar | foo() | foo(bar)
  54. // | _Z1fIiEvi | f<>() | void f<int>(int)
  55. // | _ZN1N1fE | N::f | N::f
  56. // | _ZN3Foo3BarEv | Foo::Bar() | Foo::Bar()
  57. // | _Zrm1XS_" | operator%() | operator%(X, X)
  58. // | _ZN3FooC1Ev | Foo::Foo() | Foo::Foo()
  59. // | _Z1fSs | f() | f(std::basic_string<char,
  60. // | | | std::char_traits<char>,
  61. // | | | std::allocator<char> >)
  62. //
  63. // See the unit test for more examples.
  64. //
  65. // Note: we might want to write demanglers for ABIs other than Itanium
  66. // C++ ABI in the future.
  67. //
  68. #ifndef BASE_DEMANGLE_H_
  69. #define BASE_DEMANGLE_H_
  70. #include "config.h"
  71. #include "glog/logging.h"
  72. _START_GOOGLE_NAMESPACE_
  73. // Demangle "mangled". On success, return true and write the
  74. // demangled symbol name to "out". Otherwise, return false.
  75. // "out" is modified even if demangling is unsuccessful.
  76. bool GOOGLE_GLOG_DLL_DECL Demangle(const char *mangled, char *out, int out_size);
  77. _END_GOOGLE_NAMESPACE_
  78. #endif // BASE_DEMANGLE_H_