Koinos
Koinos

Reputation: 301

GDB - Address of breakpoint

I scripted a simply assembly code, and now i'm trying to debug it using gdb.

In gdb i typed :

(gdb) break _start
Breakpoint 1 at 0x4000b0

Is the breakpoint address (0x4000b0) relative to the hard-disk memory location of the code line ? Or is it only relative to the program length ? (I think that at this point the program is still not loaded in RAM)

Upvotes: 2

Views: 2431

Answers (1)

Peter Cordes
Peter Cordes

Reputation: 363882

It's a virtual address in RAM. You have a position-dependent executable, so the absolute address it will be loaded to is right there in the ELF metadata. (you can use readelf my_program, or the GDB command info files.)

If you had a PIE executable and set a breakpoint before starting it, GDB will give you a breakpoint address that isn't relocated yet, so the first byte of the file is treated as address 0. e.g.

(gdb) b main
Breakpoint 1 at 0x64e: file hello.c, line 3.
(gdb) run
Starting program: /tmp/hello

Breakpoint 1, main () at hello.c:3
(gdb) info br
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x000055555555464e in main at hello.c:3
        breakpoint already hit 1 time

Note that 0x64e and 0x000055555555464e have the same offset within a 4k page, because the file gets mapped to a page-aligned address.

Upvotes: 4

Related Questions