The goal of this lab is to give students practice finding errors using a debugger program: gdb. You will be given a program that contains both syntax and logical errors. Your job is to find and fix the ``bugs'' so that the program runs correctly.
Syntax errors are the ``grammatical'' kinds of errors found by the compiler. However, even though a program compiles correctly it may still contain errors in logic. A debugger program is the tool to use to help you find the logical errors.
lab3.cxx) and the data file
(lab3.data), into your directory as follows. (Note that
the 'cp' command has a space and a '.' at the end of it).
> cp /cs/cs1005/labs/lab3/* .
> g++ -g lab3.cxx
Entering daily noon temps Out of 5 days: There are 1 hot days There are 2 pleasant days There are 2 cold days The average temp is 73.8 This is NOT a perfectly pleasurable climate.Carefully read the comments in the program so that you understand what the program is supposed to do. Unless you happened to catch all of the logical errors as well as all the syntax errors, your program probably does not give you that output. The program gdb (Gnu DeBugger) lets you run your program in a controlled way, one command at a time, so you can see exactly what's going on. Here are some useful gdb commands:
help help
list display ten more lines
list <line number> display ten lines centered around
<line number>
list - display ten lines previous to the lines
just printed
print <variable name> print the value of a variable
break <function name> set a breakpoint at the start of a function
break <line number> set a breakpoint at the specified line
cont continue execution after a breakpoint
clear <function name> remove all breakpoints from function
run run program with optional arguments
step resume execution for just a single statement
quit exit the debugger
backtrace shows layers of functions you are into
(gdb)
Once you're in the debugger, you can use any of the gdb commands given above to interrupt execution of your program, and to examine the values of variables. I suggest you use the following gdb commands to help you trace the execution of the main program loop:
lab3.script.
/cs/bin/turnin submit cs1005 lab3 lab3.cxx lab3.script