TMS320C28x Optimizing C/C++ Compiler v15.9.0.STS User's Guide
SPRU514 - REVISED SEPTEMBER, 2015

9 C++ Name Demangler

The C++ compiler implements function overloading, operator overloading, and type-safe linking by encoding a function's prototype and namespace in its link-level name. The process of encoding the prototype into the linkname is often referred to as name mangling. When you inspect mangled names, such as in assembly files, disassembler output, or compiler or linker diagnostic messages, it can be difficult to associate a mangled name with its corresponding name in the C++ source code. The C++ name demangler is a debugging aid that translates each mangled name it detects to its original name found in the C++ source code.

These topics tell you how to invoke and use the C++ name demangler. The C++ name demangler reads in input, looking for mangled names. All unmangled text is copied to output unaltered. All mangled names are demangled before being copied to output.

9.1 Invoking the C++ Name Demangler

The syntax for invoking the C++ name demangler is:

dem2000 [options ] [filenames]
dem2000 Command that invokes the C++ name demangler.
options Options affect how the name demangler behaves. Options can appear anywhere on the command line. (Options are discussed in Section 9.2.)
filenames Text input files, such as the assembly file output by the compiler, the assembler listing file, the disassembly file, and the linker map file. If no filenames are specified on the command line, dem2000 uses standard input.

By default, the C++ name demangler outputs to standard output. You can use the -o file option if you want to output to a file.

9.2 C++ Name Demangler Options

The following options apply only to the C++ name demangler:

--debug Prints debug messages.
--diag_wrap[=on,off] Sets diagnostic messages to wrap at 79 columns (on, which is the default) or not (off).
--help Prints a help screen that provides an online summary of the C++ name demangler options.
--output= file Outputs to the specified file rather than to standard out.
--quiet Reduces the number of messages generated during execution.
-u Specifies that external names do not have a C++ prefix.
-v Enables verbose mode (outputs a banner).

9.3 Sample Usage of the C++ Name Demangler

The examples in this section illustrate the demangling process. Example 9-1 shows a sample C++ program. Example 9-2 shows the resulting assembly that is output by the compiler. In this example, the linknames of all the functions are mangled; that is, their signature information is encoded into their names.

Example 9-1 C++ Code

int compute(int val, int *err); int foo(int val, int *err) { static int last_err = 0; int result = 0 if (last_err == 0) result = compute(val, &last_err); *err = last_err; return result; }

Example 9-2 Resulting Assembly for Example 9-1

;*************************************************************** ;* FNAME: _foo_FiPi FR SIZE: 4 * ;* * ;* FUNCTION ENVIRONMENT * ;* * ;* FUNCTION PROPERTIES * ;* 0 Parameter, 3 Auto, 0 SOE * ;*************************************************************** _foo_FiPi: ADDB SP,#4 MOVZ DP,#_last_err$1 MOV *-SP[1],AL MOV AL,@_last_err$1 MOV *-SP[2],AR4 MOV *-SP[3],#0 BF L1,NEQ ; branch occurs MOVL XAR4,#_last_err$1 MOV AL,*-SP[1] LCR #_compute__FiPi ; call occurs [#_compute__FiPi] MOV *-SP[3],AL L1: MOVZ AR6,*-SP[2] MOV *+XAR6[0],*(0:_last_err$1) MOV AL,*-SP[3] SUBB SP,#4 LRETR ; return occurs

Executing the C++ name demangler demangles all names that it believes to be mangled. Enter:

dem2000 foo.asm

The result is shown in Example 9-3. The linknames in Example 9-2 foo( ) and compute( ) are demangled.

Example 9-3 Result After Running the C++ Name Demangler

;*************************************************************** ;* FNAME: foo(int, int *) FR SIZE: 4 * ;* * ;* FUNCTION ENVIRONMENT * ;* * ;* FUNCTION PROPERTIES * ;* 0 Parameter, 3 Auto, 0 SOE * ;*************************************************************** foo(int, int *): ADDB SP,#4 MOVZ DP,#_last_err$1 MOV *-SP[1],AL MOV AL,@_last_err$1 MOV *-SP[2],AR4 MOV *-SP[3],#0 BF L1,NEQ ; branch occurs MOVL XAR4,#_last_err$1 MOV AL,*-SP[1] LCR #compute(int, int *) ; call occurs [#compute(int, int *)] MOV *-SP[3],AL L1: MOVZ AR6,*-SP[2] MOV *+XAR6[0],*(0:_last_err$1) MOV AL,*-SP[3] SUBB SP,#4 LRETR ; return occurs
Submit Documentation Feedback

Copyright© 2015, Texas Instruments Incorporated. An IMPORTANT NOTICE for this document addresses availability, warranty, changes, use in safety-critical applications, intellectual property matters and other important disclaimers.