gdb
?GDB, which is short for the GNU debugger, allows you to see what is happening inside of a program as it executes, or what it was doing at the moment it crashed. It's a powerful debugger for Linux and other UNIX-like operating systems.
gdb
To be able to access gdb
, be sure you are logged into your spirit
account.
Then type the following command, attatching it to the name of the program you want to debug:
gdb <program_name>
Please note that <program_name>
must be the name of an executable file (e.g. a.out
). Passing the source code file (e.g. my_program.c
) will not work.
After this command, you are officially in the debugger and you are able to run various types of gdb
commands.
gdb
CommandsBefore you type any command, note that there is a (gdb)
already there beforehand. It shows you that you are in the debugger.
The following are some basic gdb
commands:
(gdb) run
: Runs the program(gdb) break <function_name>
or (gdb) break <line_number>
: Allows you to set a breakpoint at a specific function/line number(gdb) where
: Shows where you are in the program(gdb) continue
: Resumes the code until the next breakpoint or until the end of the program(gdb) step
: Runs current line of code and stops at the next function call(gdb) next
: Executes current line of code but does not step into the function(gdb) print <var_name>
: Prints out value of a variable(gdb) quit
: Exits out of the debugger, returning to shell