Friday, May 6, 2011

View Compiler Mangled Names in C++

How do I view the compiler-generated mangled names for overloaded functions in C++? I'm using VC9 but answers for other compilers are welcome too.

Edit: I find all the answers useful here. Accepting the one I liked best.

From stackoverflow
  • You can view decorated (mangled) names with Dumpbin.

  • You could look in the map file. Assuming you have map file generation turned on.

    Ofek Shilon : What if you have multiple overloads of the same function?
    Simeon Pilgrim : Then you will see many functions with the same name wrapped in different mangled forms, for each overload.
    Simeon Pilgrim : Well you will then see multiple version of that function with each of there mangled names forms. Thus the purpose of name mangling, to avoid name conflicts.
  • You can see the decorated function names by using Dependency Walker.

    Open any DLL\EXE in dependency walker and in right pane you can see a list of decorated function names.

  • Since you also ask about other compilers. There is a tool called nm on the gnu toolchain. You will get it on linux and cygwin, and I believe that it is also available in mingw. Calling it with no parameters will show the mangled symbols in the binary. Calling it with --demangle will do the obvious.

  • look at similar question answered recently

    http://stackoverflow.com/questions/733056/is-there-a-way-to-get-function-name-inside-a-c-function

  • While all the above works, there is a nicely documented way to view the mangled names by use of Listing Files: Project Property Pages -> C/C++ -> Output Files -> Assembler Output.

    (EDIT:)

    There is a reason only Listing files and DUMPBIN are documented as ways to see decorated names. Both the map file and dependency walker, suggested as solutions, display only decorated names. If you have multiple overloads of a function name, you'll have a hard time matching them to the various decorated names you'd see. (That's more or less reconstructing the decoration scheme. While possible, it defeats the whole original purpose.)

0 comments:

Post a Comment