Showing posts with label cpp. Show all posts
Showing posts with label cpp. Show all posts

Friday, October 26, 2012

Demangling the namemangling

Found an awesome command today. Thanks to the "symbol not found" error. As usual i was debugging using "nm" command. It tells me if a symbol is present or not, but it doesn't tell me what that symbol stands for.

tada...thats where "c++filt" comes to rescue.

The C++ and Java languages provides function overloading, which means that you can write many functions with the same name (providing each takes parameters of different types). All C++ and Java function names are encoded into a low-level assembly label (this process is known as mangling). The c++filt program does the inverse mapping: it decodes (demangles) low-level names into user-level names so that the linker can keep these overloaded functions from clashing.

Every alphanumeric word (consisting of letters, digits, underscores, dollars, or periods) seen in the input is a potential label. If the label decodes into a C++ name, the C++ name replaces the low-level name in the output.

$ c++filt -n -s gnu-v3 _ZN8BcastMsg10mBroadcastE6AppMsgz
BcastMsg::mBroadcast(AppMsg, ...)
 

Ain't she beautiful?