gcc 编译c++函数会对函数名重新命名保证重载等多态不会重名,
所以在查看时候很不方便,我们可以使用工具c++filt,
比如我们有一个函数名:
./filt _Z5test1PKc
解出来是这样的
test1(char const*)
我们调用函数也可以实现:
#include <cxxabi.h>
bool demangle(string s, string& res) {
int status;
char* name = abi::__cxa_demangle(s.c_str(), nullptr, 0, &status);
if (status != 0) {
string err;
switch(status) {
case -1: res = "memory allocation error"; break;
case -2: res = "invalid name given"; break;
case -3: res = "internal error: __cxa_demangle: invalid argument"; break;
default: res = "unknown error occured"; break;
}
return false;
}
res = name;
free(name);
return true;
}