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. You will receive 1 point for each test case you get working for a total of 4 points for the demo. When the TA comes over, download a new copy of main_lab.cc and main_lab.txt. You can do this by typing the following commands at your command prompt while in your as1 directory. wget http://www.cs.ucr.edu/cs14/cs14_04fal/assignments/as1/main_lab.cc and wget http://www.cs.ucr.edu/cs14/cs14_04fal/assignments/as1/main_lab.txt. Compile your assignment. Run your assignment and redirect the output to temp.txt. Use the diff command to compare your output to my output. You will receive one point for each test case that matches my output. The TA will check your code to make sure that you implemented the functionalty and did not just hardcode the correct output.

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.

In lab demo

To avoid a mad rush at the end of lab to check out, I suggest that you get checked out for part 1 before starting part 2. If you wait until the end to check everything out and the TA does not get to you, you will not get points. Show the TA the following items: Remember to turn these files in and please turn in only once per pair. Remember to put both names on the files being turned in.

Point Breakdown

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.