Lab 8
 
Debugging Code with GDB

Answer Sheet
Name: _________________________

Lab Section: ____________________

Complete this answer sheet using the instructions given in the lab. Turn in a hard copy of your completed sheet to your TA by the beginning of your lab next week.

Compiling
1) Write the size (in bytes) of the executable ___________ (Note: The size in bytes is the number immediately before the date in the output from the ls -l command)

2) Now, recompile using the -g command line option and write the size in bytes of the new executable: _______________

Starting GDB
3)  Copy the first line that is printed when you run gdb: ___________________________________

4) Now, copy the portion in the quotes on the line that states "This GDB was configured as." For instance, in the example above, you would copy i686-linux-gnu:   _________________________________

Getting Help
5) Write the number of topics/classes: _____________

6) Now, type "help break" to get specific information:
Write the first line printed after executing the command here: _________________________________________

Running a Program
7) Try it now. What happened?  ___________________________________________

8) Try the run command again, this time adding the command line argument "1." What happened this time? ___________________________

Setting Breakpoints
9) At what line number does execution pause? _________________

A Brief Digression
10) Write what you see as a result: ________________________

Stepping Through Code
11) On what line does the program execution pause? _______________

12) Use the print statement mentioned above to print the current value of sum. What is its current value? _______________

13) Now, use the step command step over the current line. At what line does the execution pause? ___________________

14) Print the value of sum again. What is its value now? _______________

15) Continue stepping through the program until the following line is reached:
sum += sum + i;
16) Print the value of sum: ________________

Displaying Variables
17) What is the value of the variable 'i' at this point? ____________________

18) Once you see what the bug is, describe it below: