gdb disassemble
gdb -batch -ex "file $EXECUTABLE" -ex "disassemble/rs $ADDRESS"
For example:
alternating current:
#include <assert.h> int myfunc(int i) { i = i + 2; i = i * 2; return i; } int main(void) { assert(myfunc(1) == 6); assert(myfunc(2) == 8); return 0; }
Compile and myfunc to find the address:
gcc -std=c99 -O0 -g ac gdb -batch -ex 'file a.out' -ex "disassemble/rs myfunc"
Exit:
Dump of assembler code for function myfunc: ac: 3 int myfunc(int i) { 0x000000000000064a <+0>: 55 push %rbp 0x000000000000064b <+1>: 48 89 e5 mov %rsp,%rbp 0x000000000000064e <+4>: 89 7d fc mov %edi,-0x4(%rbp) 4 i = i + 2; 0x0000000000000651 <+7>: 83 45 fc 02 addl $0x2,-0x4(%rbp) 5 i = i * 2; 0x0000000000000655 <+11>: d1 65 fc shll -0x4(%rbp) 6 return i; 0x0000000000000658 <+14>: 8b 45 fc mov -0x4(%rbp),%eax 7 } 0x000000000000065b <+17>: 5d pop %rbp 0x000000000000065c <+18>: c3 retq End of assembler dump.
So, 0x0000000000000655 in myfunc , let's confirm that it works:
gdb -batch -ex 'file a.out' -ex 'disassemble/rs 0x0000000000000655'
Conclusion: the same as in the previous disassembly.
See also: How to parse one function using objdump?
Tested on Ubuntu 18.04, GDB 8.1.
Ciro Santilli ๆฐ็ ๆน้ ไธญๅฟ ๅ
ญๅ ไบไปถ ๆณ่ฝฎๅ Aug 22 '18 at 16:36 2018-08-22 16:36
source share