GDB (the GNU Debugger) can be used for debugging code when adding a "cout" in every second line isn't doing the trick. With gdb, you can ee what’s going on in your code while it runs - or what the programm was doing when it decided to crash.
Contents
Debugging code with GDB
General idea:
- compile with ’-g’ flag to include debug information
g++ myProgram.cpp -g -Wall -Werror -o myProgram
- load it into gdb
gdb ./myProgram
- set points where you want to make your program stop
break <source code line number>
- run your program
run
- examine what happens when it stops
print <var name> to see the current value of a variable
set <var name> = <new value> to modify a variable value by hand
list to print a few lines of code surrounding the current breakpoint
step through the program line by line,
or continue to the next breakpoint