Can I provide an objdump address and parse its containing function?

I am very unpleasant to parse large fragments of library code to get enough context to see what causes the crash. Is there a way that I can just pass the objdump address and find the bounds of the containing function for me?

EDIT: Even better, can I parse it an entire stack trace for me?

+13
c debugging disassembly objdump
Jun 22 '11 at 2:37 a.m.
source share
3 answers

Is something like this possible?

$ objdump -S --start-address=0x42 foo.o | awk '{print $0} $3~/retq?/{exit}' 

It prints a list of disk assemblies starting at 0x42 until it finds ret(q) , assuming the border is marked with ret(q)

+16
Jun 22 '11 at 18:10
source share

objdump --start-address= possible?

+2
Jun 22 2018-11-22T00:
source share

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.

+2
Aug 22 '18 at 16:36
source share



All Articles