I've got an executable file and stripped lib.so
file that is used by executable.
I have decompiled lib.so
file and defined the function fun
I want to set breakpoint and its internal address.
Is it possible to set breakpoint on function fun
using gdb?
How to define the address of fun
at runtime?
Is it possible to set breakpoint on function
fun
using gdb?
Yes: GDB can set a breakpoint on arbitrary address:
(gdb) break *0x12345678
How to define the address of fun at runtime?
Since GDB by default disables ASLR, the address of fun
will not change from run to run (assuming you run the program under GDB from the start).
Therefore, you only need to find the address of fun
once.
Let's assume that your lib.so
is linked at 0
(most non-prelinked shared libraries are).
Further let's assume that you are on Linux.
Then info proc map
will tell you where the lib.so
is loaded (you want the first start address belonging to it). Add that start address to the value of fun
you found by disassembling, and set a breakpoint there.