abi::__cxa_demangle
g++函数不返回成员函数返回值的原因是什么?
这是此行为的一个工作示例
#include <execinfo.h>
#include <cxxabi.h>
#include <iostream>
struct Foo {
void operator()() const
{
constexpr int buf_size = 100;
static void *buffer[buf_size];
int nptrs = backtrace(buffer, buf_size);
char **strings = backtrace_symbols(buffer, nptrs);
for(int i = 0; i < nptrs; ++i) {
auto str = std::string(strings[i]);
auto first = str.find_last_of('(') + 1;
auto last = str.find_last_of(')');
auto mas = str.find_last_of('+');
int status;
char* result = abi::__cxa_demangle(str.substr(first, mas-first).c_str(), nullptr, nullptr, &status);
if (status == 0) std::cout << result << std::endl;
}
}
};
int main () {
Foo f;
f();
}
编译后
g++ foo.cpp -std=c++11 -rdynamic
的输出是
Foo::operator()() const
有没有办法获得一致的行为,也就是获得成员函数的返回值?