Starting up the GDB tool GDB is a popular standard debugger in the GNU operating system. In this lab we first review the basic commands and options of gdb, which is the executable file of GDB. To compile a program with debugger symbols, use the -g flag when you compile. For programs with a Makefile, it can also be included. Once compilation with -g is done, you may use the executable to debug the program. The command to run gdb is gdb EXECUTABLE_NAME Here you may run the executable using by entering run or r. If you need to add command line arguments, you may add them when you run the executable. For example: run ARG_1 ARG_2 ... Breakpoints & Printing Info If your program has a segmentation fault, memory error, or some other program-terminating problems, gdb will halt and let you know that you have hit an error. It is useful to stop the execution of your program at an arbitrary point. This can be accomplished by setting breakpoints. To set a breakpoint, use the break command. The break requires a line number to be specified, and if there are multiple source files, you must specify that too. For example: break LINE_NUMBER break sourcefile.cpp:LINE_NUMBER Once you hit a breakpoint, you may use the print and backtrace commands. When the program stops, they can be used as described below: print VARIABLE_NAME will print the value of a given variable name. This can be used to see what value is incorrect and is usually a good point to start looking for bugs. backtrace or bt will print the stack trace; this will show you the functions that have been called up to the point of the crash. To proceed with the program execution, there are several commonly used commands: continue or c to run the program until it encounters the next breakpoint or the end of execution. step or s to step through the program line by line. next or n to step through the program, but skip over function calls (i.e. treat the function call as one line of code rather than stepping through each subsequent line of the function call) To delete a breakpoint: delete BREAKPOINT_NUMBER To list all breakpoints: info breakpoints To quit gdb: quit