Debugging with GDB
| Assemble with debug info | |
| Breakpoints | |
| Stepping and registers |
Assemble with debug info
Add -g to the NASM command to embed source-line information, then run the program under gdb:
nasm -f elf64 -g -F dwarf -o hello.o hello.asm
ld -o hello hello.o
gdb ./hello
Breakpoints
Set a breakpoint on the entry point or a label, and run. The program stops before the instruction executes:
break _start
run
break my_label
Stepping and registers
stepi executes one machine instruction. info registers shows all registers, and x/8xb addr dumps eight bytes of memory in hex. These three commands cover most assembly debugging:
stepi
info registers rax rbx rcx
x/8xb &msg
Next: The ELF format
Article author: Arthur Isaev