CSC 101 Lab Week 4
Using a Debugger to Investigate Program Behavior
There is no programming for you in this lab. Your job is to figure out what's going on in the following program:
and add comments that describe the program's behavior. When you're done, you'll submit your commented version of precision.c.~gfisher/classes/101/examples/simple-stuff/precision.c
For this lab, you can use the C debugger of your choice. The two most likely candidates are gdb and jGrasp.
There are two handouts that describe the gdb command-line debugger:
If you want to use gdb, read through these handouts and give it try. If you want to use another debugger, such as the one in jGrasp or other lab IDE, you may do so. Read the appropriate documentation, and ask your instructor for help during lab.
Two of the most fundamental commands in a debugger are setting breakpoints and single stepping in a program. For this lab, your specific assignment is as follows:
You can repeat this debugging procedure as many times as you need to figure things out. If you want, make another copy of the program that you can modify experimentally as necessary.
Once you think you've figured out the behavior of the program, add a comment above each of lines 15 through 22 that explains what each line is doing. As a concrete example and hint, here's my comment for line 15:
You can use the comment as is. Then for lines 16-22, add similar comments. Your comments may need to be more than one line long to fully explain things./* Assigns the value 0 to i, the remainder of 0.5 is lost */ i = 1/2;
Sometime before end of lab on Monday, demonstrate in person to your instructor that you know how to set a breakpoint and print a variable when stopped at a breakpoint. During your demonstration, your instructor will ask some additional questions about the use of a debugger.
To verify that you've completed the lab, submit your commented version of precision.c on unix1:
Be sure to submit a version that has the same code as the original, with only your comments added. If you modify the code to play around with it, do the code modifications in another copy of the program.handin gfisher 101_lab4 precision.c