View Compiler Mangled Names in C++

不打扰是莪最后的温柔 提交于 2019-12-19 02:03:14

问题


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.


回答1:


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




回答2:


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.




回答3:


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.




回答4:


You can view decorated (mangled) names with Dumpbin.




回答5:


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.)




回答6:


linux gnu tool chain nm command can be used to see mangled name.

#include<iostream> 
using namespace std;

int fun1(){}
int fun1(int){}
int main()
{
return 0;
}
#g++ name_decoration_2.cpp
#nm a.out
...
...
000000000040064e T _Z4fun1i
0000000000400648 T _Z4fun1v
U _ZNSt8ios_base4InitC1Ev@@GLIBCXX_3.4
U _ZNSt8ios_base4InitD1Ev@@GLIBCXX_3.4


来源:https://stackoverflow.com/questions/754865/view-compiler-mangled-names-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!