The GNU Debugger (GDB) is available on HECC systems in the /usr/bin directory. GDB can be used to debug programs written in C, C++, Fortran, and Modula-a.
GDB can perform four main tasks:
Start your program, specifying anything that might affect its behavior.
Make your program stop on specified conditions.
Examine what happened when your program has stopped.
Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.
Be sure to compile your code with -g for symbolic debugging.
GDB is typically used in the following ways:
Start the debugger by itself:
% gdb
(gdb)
Start the debugger and specify the executable:
% gdb your_executable
(gdb)
Start the debugger, and specify the executable and core file:
% gdb your_executable core-file
(gdb)
Attach gdb to a running process:
%gdb your_executable pid
(gdb)
At the prompt (gdb), enter commands such as break (for setting a breakpoint), run (to start running your executable, and step (for stepping into next line). Read man gdb to learn more on using gdb.