DEBUGGER LAB
Lab on the Use of the Debugger
Due: by the end of the class, no 24 hours deadline extension.
No Gradecope submission. Lab instructor checks your program before you leave.
Introduction
In this lab we will learn how to use debugger GDB and its GUI front-end DDD. It has some convenient features, for example, it can show graphical diagrams with pointers and generally works pretty snappy, so don’t judge it by its old interface.
Basic debugging
To debug a program, it must be compiled using the -g
flag,
which tells the compiler to include appropriate debugging information in the produced executable file:
g++ -g program.cpp
Then, you can run DDD:
ddd a.out
Please see DDD manual for detailed information.
Follow the ReadMe.txt instructions and provided .cpp files in DB Files.zip
Breakpoints.
-
To set a breakpoint, Right-Click on the left edge of the line where you want to put a breakpoint. In the shown menu, choose
Set Breakpoint
.The debugger will be always stopping there, right before that line gets executed.
-
To remove or disable a breakpoint, Right-Click on it and choose the corresponding menu option.
Basic commands (Run, Continue, Next, Step, Finish).
Run
(or press[F3]
) to start program execution (but it will be stopping at breakpoints).
When stopped at a breakpoint:
Continue [F9]
continues execution after being stopped.Next [F6]
executes current lineStep [F5]
executes current line, allowing to step into function calls.Finish [F8]
steps out of the function call.
Inspecting variables and expressions.
- Holding mouse cursor over a variable name, shows its value in an overlay frame.
- Right-Click on a variable name shows a menu to
Print
orDisplay
its value (all displayed expressions are shown in the top panel). - Similarly, you can select any complex expression with the mouse cursor and
Print
orDisplay
it.
More documentation is available in DDD manual.
Lab Assignment
-
In this lab, first, the instructor will explain you how to use the debugger program DDD. They will demonstrate all the features mentioned in the section above, and you will follow along with the instructor, debugging a simple program.
When you feel that your are falling behind, ask for help right away.
-
After the first example is finished you will be given another more complex program to debug. You together find the bugs in the second program. The instructor will check your work at the end of the class, no Gradescope submission required.