Fork me on GitHub

Setting Breakpoints in dynamically loaded .so files

In my last debugging session with r2 i had the issue that i needet to set a breakpoint at the start of a function that was loaded after starting the applicaiton. I wanted to set a bp at the function __open in a file called io_gdb.c. To accomplish that i started r2 in gdb and called run to get all libs loaded into my current session. After that i could use:

(gdb) list __open
file: "p/io_bfdbg.c", line number: 147
file: "p/io_debug.c", line number: 270
file: "p/io_gdb.c", line number: 57
file: "p/io_http.c", line number: 71
file: "p/io_ihex.c", line number: 173
file: "p/io_malloc.c", line number: 108
file: "p/io_mmap.c", line number: 205
file: "p/io_procpid.c", line number: 59
file: "p/io_ptrace.c", line number: 130
file: "p/io_self.c", line number: 54

to see all files that contain a function named __open. The next step is trivial, just call

(gdb) break p/io_gdb.c:57
Breakpoint 1 at 0x7ffff5fab8cc: file p/io_gdb.c, line 57.
(gdb) run -a x86 -b 32 -D gdb gdb://localhost:33787
Breakpoint 1, __open (io=0x6a1860, file=0x751770 "gdb://localhost:33787", rw=4, mode=420) at p/io_gdb.c:59

links

social