What is c++filt used for and how do I use it?
Environment
- Red Hat Enterprise Linux 5
- Red Hat Enterprise Linux 6
- binutils
Issue
- How do I use
c++filt?
Resolution
-
c++filtis a tool provided in the binutils package which allows you to demangle C++ symbols so they are human readable and easy to trace in the source code. -
Let's take the following simple program as an example.
# cat tmp.cpp
#include "stdio.h"
class foo
{
public:
int bar()
{
static int x = 1;
if (x != 5)
{
x = 5;
}
return 0;
}
};
int main()
{
foo myfoo;
myfoo.bar();
}
- If we compile the code we can look at the symbols for the binary using
nm.
# g++ -g tmp.cpp
# nm a.out
00000000006007b0 d _DYNAMIC
0000000000600978 d _GLOBAL_OFFSET_TABLE_
0000000000400688 R _IO_stdin_used
w _Jv_RegisterClasses
0000000000400570 W _ZN3foo3barEv
00000000006009a4 u _ZZN3foo3barEvE1x
0000000000600790 d __CTOR_END__
0000000000600788 d __CTOR_LIST__
00000000006007a0 D __DTOR_END__
0000000000600798 d __DTOR_LIST__
0000000000400780 r __FRAME_END__
00000000006007a8 d __JCR_END__
00000000006007a8 d __JCR_LIST__
00000000006009a8 A __bss_start
00000000006009a0 D __data_start
0000000000400640 t __do_global_ctors_aux
00000000004004c0 t __do_global_dtors_aux
0000000000400690 R __dso_handle
w __gmon_start__
U __gxx_personality_v0@@CXXABI_1.3
0000000000600784 d __init_array_end
0000000000600784 d __init_array_start
00000000004005a0 T __libc_csu_fini
00000000004005b0 T __libc_csu_init
U __libc_start_main@@GLIBC_2.2.5
00000000006009a8 A _edata
00000000006009b8 A _end
0000000000400678 T _fini
0000000000400428 T _init
0000000000400470 T _start
000000000040049c t call_gmon_start
00000000006009a8 b completed.6349
00000000006009a0 W data_start
00000000006009b0 b dtor_idx.6351
0000000000400530 t frame_dummy
0000000000400554 T main
- If we wish to look at one or two symbols in isolation we can pass it on the command line to
c++filt
# c++filt _ZZN3foo3barEvE1x _ZN3foo3barEv
foo::bar()::x
foo::bar()
- Alternatively,
c++filtcan take its input from a file.
# nm -f p a.out |cut -f1 -d" "|grep foo>tmpout
# c++filt <tmpout
foo::bar()
foo::bar()::x
SBR
Product(s)
Components
Category
Tags
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.