Using GNU Debugger (GDB)
To debug a C/C++ application using GDB the executable has to be compiled with the -g flag.
Start the debugger
sh
$ gdb main$ gdb mainUse the -q option to supress GDB's intro text
Set breakpoints with b. For, example
sh
(gdb) b 19(gdb) b 19will set a breakpoint at line 43 of the source file.
Start the program in the debugger
sh
(gdb) run(gdb) runCommand line arguments can be provided as normal after the run command.
At breakpoints you can step into a function with step or s
sh
(gdb) s(gdb) sAlternatively you can step over a function with next or n
sh
(gdb) n(gdb) nYou can help determine where you are in a program's execution with the backtrace or bt command
sh
(gdb) bt(gdb) btYou can view the values in a program with the print or p command
sh