Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame^] | 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 | |
| 15 | // An async-signal-safe and thread-safe demangler for Itanium C++ ABI |
| 16 | // (aka G++ V3 ABI). |
| 17 | // |
| 18 | // The demangler is implemented to be used in async signal handlers to |
| 19 | // symbolize stack traces. We cannot use libstdc++'s |
| 20 | // abi::__cxa_demangle() in such signal handlers since it's not async |
| 21 | // signal safe (it uses malloc() internally). |
| 22 | // |
| 23 | // Note that this demangler doesn't support full demangling. More |
| 24 | // specifically, it doesn't print types of function parameters and |
| 25 | // types of template arguments. It just skips them. However, it's |
| 26 | // still very useful to extract basic information such as class, |
| 27 | // function, constructor, destructor, and operator names. |
| 28 | // |
| 29 | // See the implementation note in demangle.cc if you are interested. |
| 30 | // |
| 31 | // Example: |
| 32 | // |
| 33 | // | Mangled Name | The Demangler | abi::__cxa_demangle() |
| 34 | // |---------------|---------------|----------------------- |
| 35 | // | _Z1fv | f() | f() |
| 36 | // | _Z1fi | f() | f(int) |
| 37 | // | _Z3foo3bar | foo() | foo(bar) |
| 38 | // | _Z1fIiEvi | f<>() | void f<int>(int) |
| 39 | // | _ZN1N1fE | N::f | N::f |
| 40 | // | _ZN3Foo3BarEv | Foo::Bar() | Foo::Bar() |
| 41 | // | _Zrm1XS_" | operator%() | operator%(X, X) |
| 42 | // | _ZN3FooC1Ev | Foo::Foo() | Foo::Foo() |
| 43 | // | _Z1fSs | f() | f(std::basic_string<char, |
| 44 | // | | | std::char_traits<char>, |
| 45 | // | | | std::allocator<char> >) |
| 46 | // |
| 47 | // See the unit test for more examples. |
| 48 | // |
| 49 | // Note: we might want to write demanglers for ABIs other than Itanium |
| 50 | // C++ ABI in the future. |
| 51 | // |
| 52 | |
| 53 | #ifndef ABSL_DEBUGGING_INTERNAL_DEMANGLE_H_ |
| 54 | #define ABSL_DEBUGGING_INTERNAL_DEMANGLE_H_ |
| 55 | |
| 56 | namespace absl { |
| 57 | namespace debugging_internal { |
| 58 | |
| 59 | // Demangle `mangled`. On success, return true and write the |
| 60 | // demangled symbol name to `out`. Otherwise, return false. |
| 61 | // `out` is modified even if demangling is unsuccessful. |
| 62 | bool Demangle(const char *mangled, char *out, int out_size); |
| 63 | |
| 64 | } // namespace debugging_internal |
| 65 | } // namespace absl |
| 66 | |
| 67 | #endif // ABSL_DEBUGGING_INTERNAL_DEMANGLE_H_ |