Demangling C++ Symbols

Lately I’ve been looking at a lot of disassembled C++ code which means I’ve been looking at a lot of mangled C++ symbols. You know, crazy stuff like _ZNSt13basic_filebufIcSt11char_traitsIcEED1Ev or _ZNSsC1EPKcRKSaIcE. Actually these are short ones, some C++ symbols can easily be hundreds of characters long.

I wrote a simple C++ symbol demangler to help understand these. It can detect invalid symbols and works with both GCC and Clang. Example usage:

$ demangle -q _ZNSt13basic_filebufIcSt11char_traitsIcEED1Ev _ZNSsC1EPKcRKSaIcE THIS_IS_INVALID
std::basic_filebuf<char, std::char_traits<char> >::~basic_filebuf()
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)
FAIL: THIS_IS_INVALID is not a valid name under the C++ ABI mangling rules

The project README explains the details better than I care to in this blog post, so if you’re interested in C++ symbol demangling go check out the project on GitHub at eklitzke/demangle.