CS 270 Lab 2

Introduction to gdb

In this lab, you will be introduced to the gdb debugger. Later labs and assignments will provide more advanced uses of gdb. In this assignment, you will use gdb to debug a simple program that has a bug. For information about gdb commands, please refer to these slides. To obtain a copy of the program to debug, following the link to match.c, or you can use the wget command:
wget http://www.cs.uky.edu/~raphael/courses/CS270/laboratory2/match.c
The instructions that you need to follow for this lab are as follows (also contained at the the top of match.c):
There are two bugs in this program.  In both cases the bug is
an incorrect constant in the program.  Find the incorrect constant,
fix it, and you will get the memcmp() call to be equal -- i.e., match!

Your goal is to use gdb to debug the program.  You should record your
debugging session using the script program, and then upload the
resulting file to the csportal.


To record your session:
  1. Use the script command (script session.txt).

To debug the program:
  2. Compile the program so that it can be debugged
     (gcc -Wall -g -o match match.c)
     Debugging is far easier if gcc does not optimize the program.
  3. Run gdb on the program (gdb ./match).
  4. Use gdb commands to run the program and find the bugs.
  5. Edit the program to fix the bugs, recompile, and rerun the
     program without gdb, which should print out a message indicating
     that you have debugged both phases correctly.
  6. Display your new version of the program (cat match.c).

To stop recording your session:
  7. Type exit.

Now submit session.txt to https://www.cs.uky.edu/csportal.
You can either start a browser on your VM, or you can copy the file to some
other machine and use a browser there.