c++命名粉碎及快速还原

name mangling跟函数重载紧密相关。mangling就是将参数、命名空间、返回值、调用方式等信息加入函数名中,目的就是为了给重载的函数不同的签名,因此调用函数的时候才好确认。

但是有个问题,vsgcc使用了不同的命名粉碎规则,我们不可能花大量精力在学习粉碎规则,如何快速还原,其实编译器早就有对应的工具

vs

undname.exe

这个工具在vs安装时附带的,具体位置可以用evething搜一下,或者打开Visual Studio Developer Command Prompt 即可使用

D:\devel-tools\vs>undname ??2@YAPAXI@Z
Microsoft (R) C++ Name Undecorator
Copyright (C) Microsoft Corporation. All rights reserved.

Undecoration of :- "??2@YAPAXI@Z"
is :- "void * __cdecl operator new(unsigned int)"
gcc

c++filt

这个工具是gcc安装时附带的,在gcc.exe同目录

D:\devel-tools\LLVM\bin>c++filt _ZN6PersonC1Ev
Person::Person()

clang 的命令粉碎和vs是一样的

最后推荐一个网站,它可以解码gccvs的粉碎名称

posted @ 2022-03-15 12:55  乘舟凉  阅读(446)  评论(0编辑  收藏  举报