Demangling Compiled C++ Names with CPPFILT (OS/2, Windows)

When the IBM C and C++ Compilers compiles a C++ program, it encodes all C++ symbolic names to include type and scoping information. This encoding process is called mangling. The linker uses the mangled names in the object files to resolve external references using the exported names.

Tools that use the files with mangled names do not have access to the original source code names, and therefore present the mangled names in their output. Using a process called demangling, the CPPFILT utility converts the mangled names to their original source code names so that they can be easily identified.

Note: The demangling routines in the run-time library provided with IBM C and C++ Compilersoffer another method for converting mangled names to their original source code names. You can use these routines to develop tools that manipulate mangled names. For more information on the demangling routines, see Demangling (Decoding) C++ Function Names, and the information in the <demangle.h> header file.

Using the CPPFILT Utility

The CPPFILT utility converts mangled names to demangled names in two separate modes:

Text
Specify the names of one or more ASCII text files to have the CPPFILT utility substitute demangled names for mangled names wherever it finds them in the text. Input can also be read from stdin.
Binary
Specify the names of one or more object (.obj) and library (.lib) files to produce demangled output in a format that is suitable for inclusion in a DLL module definition (.def) file.

All output is sent to stdout.

Text Mode

Use the CPPFILT utility in Text mode when you want to simply substitute demangled names for mangled names wherever they are found in the text.

To use the CPPFILT utility in text mode, type cppfilt followed by any valid text mode options on the command line.

The syntax for the cppfilt command in Text mode is:

cppfilt /option text-filename

Text Files

The file you specify for the cppfilt command in text mode should be an ASCII text file that is present in the current directory, unless you specify its path.

If you do not specify a text file, the input is read from stdin.

Output in Text Mode

Output in text mode would be the input text with the mangled names replaced by their demangled names wherever they are found in the text.

All output is sent to stdout.

Text Mode Options

The CPPFILT utility has the following options in Text mode:

/C Demangle stand-alone class names
/H or /? Display help for CPPFILT
/M Produce symbol map
/Q Suppress display of logo
/S Demangle compiler-generated symbol names
/T Produce side-by-side demangling
/Wnnn Specify width of field for demangled names

Note: You can specify options using the slash form /S or the dash form -S.

/C (Class Names)

Syntax Default
/C Do not demangle stand-alone class names

Use /C to instruct the CPPFILT utility to demangle stand-alone class names. Stand-alone class names are names that do not appear within the context of a function name or member variable. These names are not normally produced by the compiler.

For example, the stand-alone class name Q2_1X1Y would be demangled as X::Y if you specify the /C option.

If you do not specify the /C option, the default is not to demangle stand-alone class names.

/H (Help)

Syntax Default
/H
/?
None

Specify the /H or /? option on the CPPFILT command line to see a short online help on the CPPFILT command syntax and options.

If you do not specify this option, the default is not to display any online help.

/M Symbol Map

Syntax Default
/M Do not produce symbol map

Specify the /M option on the CPPFILT command line to produce a symbol map on standard output. The map contains a list of the mangled names and their corresponding demangled names. This output follows the normal filtered output.

If you do not specify the /M option, the default is not to produce a symbol map.

/Q (Do Not Display Logo)

Syntax Default
/Q Display logo and copyright notice

Specify the /Q option on the CPPFILT command line to suppress the display of the logo and copyright notice for the CPPFILT utility.

If you do not specify this option, the default is to display the logo and copyright notice.

/S (Special Symbol Names)

Syntax Default
/S Do not demangle special compiler-generated symbol names

Specify the /S option on the CPPFILT command line to instruct the CPPFILT utility to demangle special compiler-generated symbol names.

For example, the compiler-generated symbol name, __ct__3FooFUi, that represents a constructor for the class Foo would be demangled as Foo::Foo(unsigned int).

If you do not specify the /S option, the default is not to demangle special compiler-generated symbol names.

/T (Mangled and Demangled Names Together)

Syntax Default
/T Replace mangled name with demangled name only

Specify the /T option on the CPPFILT command line to produce side-by-side demangling. That is, each mangled name is replaced with the demangled name followed by the original mangled name in the text.

If you do not specify the /T option, the default is to replace the mangled name by the demangled name only.

/Wnnn (Width)

Syntax Default
/Wwidth Do not demangle stand-alone class names

Specify the /Wwidth option on the CPPFILT command line to have the CPPFILT utility print the demangled names in fields width characters wide. If the name is shorter than width, it is padded to the right with blanks; if longer, it is truncated to width characters.

If you do not specify the /Wwidth option, the default is not to have a fixed field width when printing demangled names in the text.

Binary Mode

Use the CPPFILT utility in Binary mode when you want to demangle names in object (.obj) and library (.lib) files to produce output that is suitable for inclusion in a DLL module definition (.def) file.

To use the CPPFILT utility in Binary mode, type cppfilt /Bfollowed by any valid Binary mode options on the command line. The CPPFILT utility switches to the Binary mode of operation when it encounters the /B option.

The syntax for the cppfilt command in Binary mode is:

cppfilt /B /option .obj-filename .LIB-filename

.obj and .lib Files

The file names that you specify after the cppfilt /B binary-mode command must be object (.obj) or library (.lib) files. They must be present in the current directory, unless their paths are specified. CPPFILT will also search for library files along the paths specified in the LIB environment variable if the files are not found in the current directory.

Input cannot be read from stdin in binary mode. You must specify object or library filenames for input.

All output is sent to stdout.

Output in Binary Mode

CPPFILT output in Binary mode lists any libraries and any object files within each library. If you specify the /X, /R, and /P options, the exported, referenced, and public symbols are also listed for each object file.

For example, the command

cppfilt /B /P /O 1000 /N c:\ibmcpp\lib\dde4cc.lib

would produce the following output for a library file called DDE4CC.LIB:

;From library:  c:\ibmcpp\lib\dde4cc.lib
  ;From object file:  C:\ibmcpp\src\IILNSEQ.C
    ;PUBDEFs (Symbols available from object file):
      ;ILinkedSequenceImpl::setToPrevious(ILinkedSequenceImpl::Node*&) const
      setToPrevious__19ILinkedSequenceImplCFRPQ2_19ILinkedSequenceImpl4Node    @1000 NONAME
      ;ILinkedSequenceImpl::allElementsDo(void*,void*) const
      allElementsDo__19ILinkedSequenceImplCFPvT1    @1001 NONAME
      ;ILinkedSequenceImpl::isConsistent() const
      isConsistent__19ILinkedSequenceImplCFv    @1002 NONAME
      ;ILinkedSequenceImpl::setToNext(ILinkedSequenceImpl::Node*&) const
      setToNext__19ILinkedSequenceImplCFRPQ2_19ILinkedSequenceImpl4Node    @1003 NONAME
      ;ILinkedSequenceImpl::addAsNext(ILinkedSequenceImpl::Node*,ILinkedSequenceImpl::Node*)
      addAsNext__19ILinkedSequenceImplFPQ2_19ILinkedSequenceImpl4NodeT1    @1004 NONAME
  ;From object file:  C:\ibmcpp\src\IITBSEQ.C
    ;PUBDEFs (Symbols available from object file):
      ;ITabularSequenceImpl::setToPrevious(ITabularSequenceImpl::Cursor&) const
      setToPrevious__20ITabularSequenceImplCFRQ2_20ITabularSequenceImpl6Cursor    @1034 NONAME
      ;ITabularSequenceImpl::allElementsDo(void*)
      allElementsDo__20ITabularSequenceImplFPv    @1035 NONAME
      ;ITabularSequenceImpl::removeAll(void*,void*)
      removeAll__20ITabularSequenceImplFPvT1    @1036 NONAME
      ;ITabularSequenceImpl::addAllFrom(const ITabularSequenceImpl&)
      addAllFrom__20ITabularSequenceImplFRC20ITabularSequenceImpl    @1037 NONAME
  ;From object file:  IIAVLKSS.C
    ;PUBDEFs (Symbols available from object file):
      ;IAvlKeySortedSetImpl::allElementsDo(void*,void*) const
      allElementsDo__20IAvlKeySortedSetImplCFPvT1    @1080 NONAME
      ;IAvlKeySortedSetImpl::isFirst(const IAvlKeySortedSetImpl::Node*) const
      isFirst__20IAvlKeySortedSetImplCFPCQ2_20IAvlKeySortedSetImpl4Node    @1081 NONAME
      ;IAvlKeySortedSetImpl::setToPosition(unsigned long,IAvlKeySortedSetImpl::Node*&) const
      setToPosition__20IAvlKeySortedSetImplCFUlRPQ2_20IAvlKeySortedSetImpl4Node    @1082 NONAME
      ;IAvlKeySortedSetImpl::locateOrAddElementWithKey(const void*)
      locateOrAddElementWithKey__20IAvlKeySortedSetImplFPCv    @1083 NONAME

Note: This is only a partial listing of the actual output.

Binary Mode Options

In binary mode, the CPPFILT utility has the following options:

/B Operate in Binary mode
/C Demangle stand-alone class names
/H or /? Display help
/N Reference exported names by ordinal number
/O[ord] Generate ordinals after each demangled name
/P Include public symbols in output
/Q Suppress display of logo
/R Include referenced symbols in output
/S Demangle special compiler-generated symbol names
/U Removes a leading underscore from demangled names
/X Include exported symbols in output
/Z Suppresses comments in the output

Note: You can specify options using the slash form /R or the dash form -R.

/B (Operate in Binary Mode)

Syntax Default
/B Operate in Text mode

Specify /B on the CPPFILT command line to instruct CPPFILT to operate in Binary mode.

If you do not specify the /B option, CPPFILT will operate in the default Text mode.

/H (Help)

Syntax Default
/H
/?
None

Specify the /H or /? option on the CPPFILT command line to see a short online help on the CPPFILT command syntax and options.

If you do not specify this option, the default is not to display any online help.

/N (NONAME Keyword)

Syntax Default
/N Reference exported names by name

Specify the /N option on the CPPFILT command line to instruct CPPFILT to generate the NONAME keyword as consistent with the module definition (.def) file EXPORTS statement syntax. The NONAME keyword indicates that the exported names should be referenced by their ordinals, and not by their names.

Note: You should also specify /N together with the /O option to generate ordinals.

For example, if you specify /N/O 1000, the output for a single name would look something like this:

;ILinkedSequenceImpl::isConsistent() const isConsistent__19ILinkedSequenceImplCFv @1000 NONAME

/O (Ordinals)

Syntax Default
/O[ord] Do not generate ordinals

Specify the /O[ord] option on the CPPFILT command line to generate ordinals after each demangled name. If the optional numeric parameter ord is specified, CPPFILT will generate the ordinals starting from ord.

The ordinals are generated along with the @ character as consistent with the module definition (.def) file EXPORTS statement syntax.

For example, if you specify /O 1000, the output for a single name would look something like this:

;ILinkedSequenceImpl::isConsistent() const isConsistent__19ILinkedSequenceImplCFv @1000

If you do not specify the /O option, the default is not to generate ordinals after each demangled name.

/P (Public Symbols)

Syntax Default
/P Do not include public symbols in output

Specify the /P option on the CPPFILT command line to include all public (PUBDEF, COMDAT, COMDEF) symbols in the output.

Note: Only the first occurrence of a symbol found within the COMDAT sections will be included in the output. Subsequent occurrences of the same COMDAT symbol will appear as comments in the output.

If you do not specify this option, the default is not to include public symbols in the output.

Note: If you do not specify any of the /X, /R, or /P options, the Binary mode output will include only the library and object names, without any symbol names.

/Q (Do Not Display Logo)

Syntax Default
/Q Display logo and copyright notice

Specify the /Q option on the CPPFILT command line to suppress the display of the logo and copyright notice for the CPPFILT utility.

If you do not specify this option, the default is to display the logo and copyright notice.

/R (Referenced Symbols)

Syntax Default
/R Do not include referenced symbols in output

Specify the /R option on the CPPFILT command line to include all referenced (EXTDEF) symbols in the output.

If you do not specify this option, the default is not to include referenced symbols in the output.

Note: If you do not specify any of the /X, /R, or /P options, the binary-mode output will include only the library and object names, without any symbol names.

/S (Special Symbol Names)

Syntax Default
/S Do not demangle special compiler-generated symbol names

Specify the /S option on the CPPFILT command line to instruct the CPPFILT utility to demangle special compiler-generated symbol names.

For example, the compiler-generated symbol name, __ct__3FooFUi, that represents a constructor for the class Foo would be demangled as Foo::Foo(unsigned int).

If you do not specify the /S option, the default is not to demangle special compiler-generated symbol names.

/U (Underscore Removal)

Syntax Default
/U Leave leading underscores in mangled names

Specify the /U option on the CPPFILT command line to instruct the CPPFILT utility to remove a single leading underscore (if present) from mangled names. If more than one leading underscore is present, only one is removed.

If you do not specify the /U option, any leading underscores on mangled names are left.

/X (Exported Symbols)

Syntax Default
/X Do not include exported symbols in output

Specify the /X option on the CPPFILT command line to include all exported (EXPDEF) symbols in the output.

If you do not specify /X, the default is not to include exported symbols in the output.

Note: If you do not specify any of the /X, /R, or /P options, the Binary mode output will include only the library and object names, without any symbol names.

/Z (Suppresses Comments)

Syntax Default
/Z Leave comments in output

Specify the /Z option on the CPPFILT command line to instruct the CPPFILT utility to suppress all comments in the output.

By default, mangled names are left in the output as comments.



Demangling C++ Function Names