Table of Contents
1. Build a program with debugging symbols
To use your program in the debugger you need to make sure to build
it with the -g flag:
g++ FILENAME.cpp -g -o PROG.exe
2. Start the debugger, load your program
Run the debugger with the program executable second to load it into the debugger program.
gdb PROG.exe
3. Debugger prompt
When the program is running you'll see a prompt where you can
enter commands. The prompt begins with (gdb).
4. Debugger prompt
When the program is running you'll see a prompt where you can
enter commands. The prompt begins with (gdb).
5. Debugging commands
| Command | What it does |
|---|---|
run |
Runs the program as normal |
break FUNCTION |
Sets a breakpoint at the start of the named function. |
break FILENAME:LINENUM |
Set a breakpoint on a specific line of a source file |
continue |
Continues the program run when in a paused state |
bt |
View the backtrace of function calls at the current point. |
print VARNAME |
Displays the value of a variable |
next |
Step (over) to the next line |
step |
Step (into) the next line (will enter function calls) |