有人知道c++filt源代码的链接吗?我想在我的代码中调用c++filt作为一个库。
发布于 2011-01-24 16:27:43
在Linux上,你可以使用binutils-dev包附带的/usr/include/demangle.h。您必须从binutils链接到libiberty。
发布于 2011-01-24 16:14:26
它是binutils的一部分:
http://ftp.gnu.org/gnu/binutils/
发布于 2011-01-24 16:24:37
考虑到不同的编译器可以有不同的处理方式,每个编译器都倾向于附带一个自定义的c++filt。但是,大多数系统都已经在某个地方提供了一个独立的库函数。在我的Linux机器上,我找到了定义__cxa_demangle()的/usr/include/c++/version/cxxabi.h头文件(参见http://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html)。我想我已经在过去使用了一些其他的函数,但是找不到细节(编辑:可能是demangle版本的İsmail文档)。在AIX上有一个demangle.h。
编辑:在大多数带有pstack和c++filt程序的系统上(例如Linux和Solaris),下面的命令应该可以工作...
#include <cstdio>
#include <iostream>
#include <sstream>
struct X
{
void f()
{
std::ostringstream cmd;
cmd << "pstack " << getpid() << " | c++filt";
if (FILE* f = popen(cmd.str().c_str(), "r"))
{
char buffer[1024];
int n;
while ((n = fread(buffer, 1, sizeof buffer, f)) > 0)
std::cout.write(buffer, n);
}
else
std::cerr << "popen() failed\n";
}
};
int main()
{
X x;
x.f();
}...output...
#0 0x003539be in __read_nocancel () from /lib/tls/i686/libc.so.6
#1 0x002ff590 in _IO_file_read_internal () from /lib/tls/i686/libc.so.6
#2 0x002fe522 in _IO_new_file_underflow () from /lib/tls/i686/libc.so.6
#3 0x00300371 in __underflow () from /lib/tls/i686/libc.so.6
#4 0x0030079d in _IO_default_xsgetn_internal () from /lib/tls/i686/libc.so.6
#5 0x00300733 in _IO_sgetn_internal () from /lib/tls/i686/libc.so.6
#6 0x002f666c in fread () from /lib/tls/i686/libc.so.6
#7 0x08048c36 in X::f ()
#8 0x08048ac0 in main ()请注意,__read_nocancel等不是C++损坏的标识符:它们只是内部C函数名,使用为实现保留的前导下划线和大写字母或前导双下划线。
X::f()是一个损坏的标识符,已经被破坏了。
https://stackoverflow.com/questions/4779857
复制相似问题