Using gdb
gdb is a powerful debugger. The following describes gdb
commands (to be executed at the gdb prompt) enough for you
step through your code and find problems in your code.
Remember your code must be compiled with the -g option in
order to use the debugger.
- Running the debugger → gdb a.out (prompt will be (gdb))
- To exit → q
- To diplay/list code (list) → l (letter l)
- You can execute layout src to split the window and see the source code
- To run the program (run) → r
- To set breakpoints (break) → b
You need to set at least one breakpoint otherwise
your code will be run to completion
- To inspect variables (print) → p VARIABLENAME
- To execute a statement/function call (next) → n
- To execute a statement/function call (steps into the function) → s
- To continue execution, continue → c
- To see the frame stack → where
- To clear a breakpoint at a particular line → clear LINENUMBER
- To identify where a core dump takes place → where
- Running code with input redirection → r < DATA_FILE
Additional Information