I needed a C++ symbol name demangler for my (our) OS project. Obviously because we're not hosted we can't use c++filt or cxx::abi::demangle so I had to make my own.
My first attempt was based on me playing with c++filt and working out by hand how the symbols were created, and worked pretty well. But not well enough for me! I found the mangling spec that GCC uses (the Itanium IA64 ABI), which included a grammar and a brief explanation of the substitution/compression techniques used (the most difficult bit!). So after much typing, debugging, and removal of left recursion (damn them, I'm not implementing a bottom-up parser by myself, and I don't want the bloat that bison gives in a core kernel file (plus I would then be bound by the GPL - eek!), I came up with this:
.cc file
.h file
It can be run under linux (possibly windows too but I haven't tried) - just comment out the #includes there and uncomment the #includes / #defines below (and the main() function).
If someone does fancy using it under linux (not sure why, but meh just in case) you'll also need the StaticString header file:
StaticString.h
I hope that it brings joy to some child, somewhere.
Cheers,
James
EDIT: forgot to mention that if you change the "#undef MANGLE_DEBUG" to "#define MANGLE_DEBUG" you get some rather nice debug output
EDIT2: It working:
Code: Select all
[13:31:29] ~/pedigree $ ./testmangle _ZN12StaticStringILj32EEpLERKi
_ZN12StaticStringILj32EEpLERKi -> StaticString<unsigned int=32>::operator+=(const int&)
Substitutions:
S_: StaticString
S0_: StaticString<unsigned int=32>
S1_: const int
S2_: const int&
Template params:
[13:32:03] ~/pedigree $