CS 14 - Lab 2


CS 14 Homepage

Makefile Creation and Debugging

Note: Sometime during this lab, you must demo your progress on at-home programming assignment 1

Part 1 - Makefile Creation

In this portion of the lab, you will learn how to create makefiles. When working on large projects, compilation may take minutes to hours. If you make a small change to one file, you would not want to wait for your entire project to recompile. A makefile gives a very simple way of setting file dependencies so that when one file is changed, only the files that are dependent on that file are recompiled.

Procedure

1. Read the makefile tutorial.
2. Create a generalized makefile for a program with the following specifications:
3. In a file titled "makefile_questions.txt", answer the following questions (assuming the makefile that you just created):

Part 2 - Debugging

Knowing how (and when) to use the debugger is an important skill that will GREATLY reduce the time required for you to correct buggy programs or understand programs that are behaving in ways that you don't understand.

Download the sample solution to lab 1 and this new main.cc file. Draw on paper what you believe the two lists should look like step by step (main has the stages clearly labeled). Now compile and run it. There should be two major problems you can identify: the first is the strange behavior of push_back in the final stage, and the second is the Segmentation Fault at the end of the program. Turn in a copy of a gdb that shows you using at least the following commands to find out what causes this mystery behavior (copy your gdb session into a text editor as you go, turn in that document): You may also find the "watch" command to be useful in some situations, although probably not for debugging this particular program. For .3 extra credit points, demonstrate how watchpoints work. You may want to take a look at the GDB reference guide.

Point Breakdown

What to turn in:

There is no inlab demo for lab2. You must turn in the following files/information: Please turn in only once per pair. Remember to put both names on the files being turned in.

Note about collaboration for this lab

For this lab, you may not help any other group or student discover the mystery behavior if you finish early. Everyone needs to figure out the mystery on their own. You may however discuss GDB commands and how they work but please do not help another group discover the reason for the mystery behavior.