When the IBM C and C++ Compilers compiles a program, it encodes all function names and certain other identifiers to include type and scoping information. This encoding process is called mangling. The linker uses mangled names to ensure type-safe linkage. These mangled names are used in object files and in the final executable file. Tools that use these files must use the mangled names and not the original names used in the source code.
IBM C and C++ Compilers provides two methods of converting mangled names to the original source code names: demangling functions, and the CPPFILT utility.
Using the Demangling Functions
The run-time library contains a small class hierarchy of functions that you can use to demangle names and examine the resulting parts of the name. It also provides a C-language interface you can use in C programs. The functions use no external C++ features.
The demangling functions are available in both the static (.LIB) and dynamic(.DLL) versions of the library. The interface is documented in the <demangle.h> header file.
Using the demangling functions, you can write programs to convert a mangled name to a demangled and to determine characteristics of that name, such as its type qualifiers or scope. For example, given the mangled name of a function, the program returns the demangled name of the function and the name of its qualifiers. If the mangled name refers to a class member, you can determine if it is static, const, or volatile. You can also get the whole text of the mangled name.
To demangle a name that is represented as a character array, create a dynamic instance of the Name class and provide the character string to the class's constructor. For example, to demangle the name f__1XFi, create:
char *rest; Name *name = Demangle("f__1XFi", rest);
The demangling functions classify names into five categories:
After you construct an instance of class Name, you can use the Kind member function of Name to determine what kind of Name the instance is. Based on the kind of name returned, you can ask for the text of the different parts of the name or of the entire name.
For the mangled name f__1XFi, you can determine:
name->Kind() == MemberFunction ((MemberFunctionName *) name)->Scope()->Text() is "X" ((MemberFunctionName *) name)->RootName() is "f" ((MemberFunctionName *) name)->Text() is "X::f(int)"
If the character string passed to the Name constructor is not the mangled name, the Demangle function returns NULL.
For further details about the demangling functions and their C++ and C interfaces, refer to the information contained in the <demangle.h> header file.