Can I give objdump an address and have it disassemble the containing function?

Alex picture Alex · Jun 22, 2011 · Viewed 13.8k times · Source

I'm finding it really annoying to have to disassemble large swathes of library code just to get enough context to see what is causing a crash. Is there any way that I can just hand objdump an address, and have it find the boundaries of the containing function for me?

EDIT: Better yet, can I have it disassemble an entire stack trace for me?

Answer

ksk picture ksk · Jun 22, 2011

Something like this perhaps?

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

It prints the dis-assembly listing starting from 0x42 till it finds a ret(q), assuming the boundary is marked by ret(q)