Entering and Exiting gdb Mode
Learn how to debug code using gdb.
We'll cover the following
Compile the program
To be able to debug a program using gdb, we must, first, compile it using the -g
flag.
gcc main.c -g
The output of this program will be available in a.out
(or a.exe
).
Run a.out/a.exe
under gdb
Then, we should execute the program using gdb. When we do that, we enter the gdb mode.
gdb a.out
Once into this mode, we can perform a variety of operations as the execution proceeds. These tasks are discussed in upcoming lessons.
View the source code
The list
command in gdb is used to see the source code. For longer programs, the list
command can be issued repeatedly to see the complete source code in chunks.
list
Exit from gdb debugger
To exit the gdb debugger, run the following command on the terminal:
quit
Get hands-on with 1200+ tech skills courses.