Before you learn to how to use GDB, it would be good idea to get to know some GDB commands.
GDB is command line utility. You will have to execute command on gdb shell.
For purpose of this tutorial, we will see few commands which are commonly used.
|Start running program until a breakpoint or end of program
|Set a breakpoint at the begining of function "fun"
|Set a breakpoint at line number N of source file currently executing
|Set a breakpoint at line number N of file "file.c"
|Remove breakpoint number N
|List all breakpoints
|Continues/Resumes running the program until the next breakpoint or end of program
|Runs until the current function is finished
|Runs the next line of the program
|Runs the next N lines of program
|Like s, but it does not step into functions
|Prints the current value of the variable "var"
|Assign "val" value to the variable "var"
|Prints a stack trace
|Quit from gdb
In next section, you will do your first debugging session and will learn how to use GDB.