15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2006, Google Inc.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// All rights reserved.
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Redistribution and use in source and binary forms, with or without
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// modification, are permitted provided that the following conditions are
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// met:
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//     * Redistributions of source code must retain the above copyright
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// notice, this list of conditions and the following disclaimer.
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//     * Redistributions in binary form must reproduce the above
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// copyright notice, this list of conditions and the following disclaimer
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// in the documentation and/or other materials provided with the
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// distribution.
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//     * Neither the name of Google Inc. nor the names of its
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// contributors may be used to endorse or promote products derived from
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// this software without specific prior written permission.
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Author: Satoru Takabayashi
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// An async-signal-safe and thread-safe demangler for Itanium C++ ABI
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (aka G++ V3 ABI).
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The demangler is implemented to be used in async signal handlers to
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// symbolize stack traces.  We cannot use libstdc++'s
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// abi::__cxa_demangle() in such signal handlers since it's not async
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// signal safe (it uses malloc() internally).
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Note that this demangler doesn't support full demangling.  More
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// specifically, it doesn't print types of function parameters and
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// types of template arguments.  It just skips them.  However, it's
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// still very useful to extract basic information such as class,
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// function, constructor, destructor, and operator names.
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// See the implementation note in demangle.cc if you are interested.
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Example:
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// | Mangled Name  | The Demangler | abi::__cxa_demangle()
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |---------------|---------------|-----------------------
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// | _Z1fv         | f()           | f()
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// | _Z1fi         | f()           | f(int)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// | _Z3foo3bar    | foo()         | foo(bar)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// | _Z1fIiEvi     | f<>()         | void f<int>(int)
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// | _ZN1N1fE      | N::f          | N::f
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// | _ZN3Foo3BarEv | Foo::Bar()    | Foo::Bar()
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// | _Zrm1XS_"     | operator%()   | operator%(X, X)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// | _ZN3FooC1Ev   | Foo::Foo()    | Foo::Foo()
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// | _Z1fSs        | f()           | f(std::basic_string<char,
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |               |               |   std::char_traits<char>,
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |               |               |   std::allocator<char> >)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// See the unit test for more examples.
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Note: we might want to write demanglers for ABIs other than Itanium
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// C++ ABI in the future.
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef BASE_DEMANGLE_H_
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define BASE_DEMANGLE_H_
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "config.h"
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)_START_GOOGLE_NAMESPACE_
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Demangle "mangled".  On success, return true and write the
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// demangled symbol name to "out".  Otherwise, return false.
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// "out" is modified even if demangling is unsuccessful.
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool Demangle(const char *mangled, char *out, int out_size);
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)_END_GOOGLE_NAMESPACE_
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // BASE_DEMANGLE_H_
85