Lab 1: Text Editors and Using the Debugger

Submission Due: the beginning of your next lab session

In this lab, we will review some of the features of text editors designed for programmers. We will also cover how to use the debugger. You will need to fix a segmentation fault in the ispell Benchmark using GDB, as well as, set a watchpoint to follow the modifications of a specific variable throughout the execution of the program. To complete the lab successfully, you will need to submit both your modified code and a 1 page report answering the questions below. No demonstration will be required for this laboratory.

Lab Materials

  1. Vim and GDB Overview

  2. ispell Benchmark Source Files

Lab Assignment

During this laboratory you will invoke GCC tools in order to build a benchmark program. Additionally, you will learn to use the Make build system to automate this process. Once this has been completed, you will learn to use the GDB debugger and a Unix text editor (vim or emacs is recommended) to fix errors in the source code, as well as, watch a specific variable's value change throughout execution. Follow the steps below to complete this lab:

  1. Setup your EECS 665 lab directory. You will store all of your labs for the EECS 665 course in this directory, with one sub-directory per lab. You can accomplish this task on your Unix console by typing the following at the command prompt. NOTE: the command prompt is represented using > in the steps below. You should only type the command appearing after the >:

    > mkdir eecs665_labs
    > cd eecs665_labs
  2. Setup your lab01 sub-directory inside of the EECS 665 lab directory. After having completed the step above, this can be accomplished by typing the following at the command prompt:

    > mkdir lab01
    > cd lab01
  3. Download the ispell Benchmark and extract the source code into your EECS 665 lab01 directory. You can accomplish the extraction using the following extraction tool tar:

    > tar -xvf eecs665-lab01.tar.gz
  4. At this point you should have the ispell directory in your lab01 directory which includes a Makefile. The files in the ispell directory represent the ispell Benchmark. Before we build the lab using make, we are going to build the lab by hand. To do this, perform the following:

    > gcc -g -w defmt.c hash.c lookup.c tgood.c correct.c dump.c good.c ispell.c makedent.c term.c tree.c xgets.c -o ispell
  5. Now that you can build the program yourself, you can start using the Makefile to build your lab. Restore the ispell directory to its original state by issuing a make clean in the console. Build ispell by issuing make. Perform the following:

    > make clean
    > make
  6. The ispell program that you have been given has one error in it that must be fixed. The benchmark I've provided currently produces a SEGFAULT before exiting. Try running the benchmark as it is and see what happens. Fix the error using the GDB debugger. See the GDB references mentioned in the slides for more information, as well as, the GDB cheat sheet provided on the class homepage. NOTE: you should be able to fix this error by modifying one line of code.

    Run the benchmark without GDB:

    > ./ispell -a -d americanmed+ < small.txt > ispell.out

    OR:

    > make execute

    Run the benchmark using GDB:

    > gdb ./ispell
    (gdb) run -a -d americanmed+ < small.txt > ispell.out

    You can compare the output of your program with the program's standard output (ispell.std.out) when given the specified input parameters mentioned above. Do this by typing make diff into your console. This should perform a diff comparison between the execution's output (ispell.out) and the standard output provided. Fixing the SEGFAULT that is signaled before the program finishes executing should result in the two files matching.

  7. At this point, you should have fixed the error in the program. The second part of this lab involves ispell's global variable my_watch. Throughout execution, this value will change several times. You need to add a watchpoint using GDB that allows you to follow the modifications of my_watch. Every time the value of my_watch changes, you need to note both its old value and its new value (this information will be required in your lab submission, in the order that the variable is modified during execution). NOTE: you do not need to watch for when my_watch is read, just written to.

  8. You have completed your debugging session! Make sure you make clean your ispell directory before submitting and do not forget to answer the questions below.

Lab Questions

Answer the following questions and submit this lab according to the deliverables guidelines found on the lab website's homepage (for this lab, you can either rename the ispell directory as source or leave it as is). No demonstration will be required for this laboratory.

  1. Quickly describe the exact changes you made and why you made them. Discuss how you approached the problem and exactly how you determined the source of the problem. Discuss which debugger commands you found most helpful.

  2. List (in order) the modifications of my_watch, including both the old value and new value it was set with.

Lab Resources

  1. EMACS Reference Card

  2. VIM Reference Card

  3. GDB Reference Card