Debugging Assembly Programs with gdb

Is your program crashing due to a segmentation fault or some other error? Not sure why? Use gdb (GNU debugger) to pointpoint the section of code that’s causing problems. gdb comes installed by default on most linux installations.

In order for gdb to work, the program must be compiled with debugging flags. For example:

nasm -f elf -g -F dwarf spaceinv.asm

First, launch the program within gdb using the following command:

gdb program_name

The debugger will display some informational messages followed by a “(gdb)” prompt. From there, issue the run command to start the program.

(gdb) run

The program will execute normally, but when it crashes gdb will give you information about the signal received from the operating system and insight as to why it failed.