Here is a simple cpp
file:
#include <iostream>
void test(int x)
{
std::cout << "x is " << x << std::endl;
}
int main()
{
test(5);
return 0;
}
After compiling with g++
, suppose I want to use objdump
to show the disassembly only of the test
function (not main
):
objdump a.out --disassemble="test"
The resulting disassembly is empty, evidently because objdump
failed to find the symbol "test"
. If instead I use -t
to show the symbol table, I can see the symbol I'm looking for:
objdump -t a.out | grep test
0000000000000000 l df *ABS* 0000000000000000 test4.cpp
0000000000001285 l F .text 0000000000000019 _GLOBAL__sub_I__Z4testi
00000000000011c9 g F .text 000000000000004d _Z4testi
Using _Z4testi
instead of test
in the original objdump
command now works:
objdump a.out --disassemble="_Z4testi"
...
Disassembly of section .text:
00000000000011c9 <_Z4testi>:
11c9: f3 0f 1e fa endbr64
11cd: 55 push %rbp
11ce: 48 89 e5 mov %rsp,%rbp
11d1: 48 83 ec 10 sub $0x10,%rsp
...
Is there a way, for convenience, to make --disassemble
accept the unmangled symbol name?
g++ (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0
GNU objdump (GNU Binutils for Ubuntu) 2.38