objdump -C
The -C
flag enables demangling:
printf '
template<typename T>
T add(T x, T y) {
return x + y;
}
void h() {
add(1, 2);
add(1.0, 2.0);
}
' > a.cpp
g++ -g -std=c++11 a.cpp
objdump -CS a.out
The output contains demangled names:
int main() {
add(1, 2);
60c: e8 28 00 00 00 callq 639 <int add<int>(int, int)>
add(1.0, 2.0);
62d: e8 1b 00 00 00 callq 64d <double add<double>(double, double)>
0000000000000639 <int add<int>(int, int)>:
000000000000064d <double add<double>(double, double)>:
Without -C
, it contains mangled names instead:
0000000000000639 <_Z3addIiET_S0_S0_>:
000000000000064d <_Z3addIdET_S0_S0_>:
man objdump
says:
Decode (demangle) low-level symbol names into user-level names. Besides removing any initial underscore prepended by the system, this makes C++ function names readable. Different compilers have different mangling styles. The optional demangling style argument can be used to choose an appropriate demangling style for your compiler.
nm
also has the -C
option.
Tested in Ubuntu 18.04, g++
7.3.0, objdump
2.30.