This question already has an answer here:
-
Stopping at the first machine code instruction in GDB
5 answers
How do I set a breakpoint using GDB for x86 assembly code, when there is no symbol information, i.e. it is not possible to write b *_start
.
I'd like to stop execution immediately, but writing b *0
isn't very useful, because this would stop execution at address 0
, but I need to break execution at address x
relative to the starting point (which is unknown when no symbol information is present).
Use something like objdump -f
to show you the numeric value of the entry point address. Or inside gdb, info files
will show you the entry point.
Copy/paste that value into a gdb command: b *0x...
to break at the entry point. You can then single-step from there.
See also the bottom of the x86 tag wiki for some asm-debugging tips, like layout reg
.
Sample output from objdump -f
:
/bin/ls: file format elf64-x86-64
architecture: i386:x86-64, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x0000000000404870 <<---- copy this address
Instead of finding the entry-point address
b *0
will cause an error when gdb tries to set the breakpoint. This results in stopping before any instructions execute, at the entry point. Delete the bogus breakpoint (or it will keep erroring when you try to single-step or continue).
Stopping at the first machine code instruction in GDB