Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How find find offset of a function using gdb?

Tags:

gdb

dwarf

I have a shared object file that has DWARF info. I want to find the offset of a function. My stack trace is in the format mangledFuncName + 0x123. I want to find the line of code for the corresponding frame. Ideally I'd like to build some sort of mapping between all offsets of a .so file and the filename/linenumber for the offset/range of offsets. Is this possible to do with gdb?

like image 633
TreeWater Avatar asked Sep 15 '25 21:09

TreeWater


1 Answers

gdb <so or file loading so>
(gdb) b main
(gdb) run
(gdb) p youfun
(gdb) info line *(0xabcdef+0xab)
(gdb) list *(0xabcdef+0xab)
(gdb) info symbol 0xabcdef
(gdb) b *(0xabcdef+0xab)
  • line 2 and 3 are there to make the .so file load. It is not needed if you have the debug info loaded already (file or as gdb argument).
  • line 4 will show the address of the function
  • replace 0xabcdef with the address of the function and 0xab with the offset
like image 157
Roland Puntaier Avatar answered Sep 17 '25 20:09

Roland Puntaier