CS 14 - Lab
CS 14
Homepage
Makefile Creation and Debugging
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:
-
The compiler used is g++. Compiler flags will include: -g -Wall -W
-Werror -pedantic.
-
You must handle make clean.
-
The project contains the following files: main.cc, list.cc, list.h,
node.cc, node.h, sort.cc, and sort.h.
-
The executable will be called sort.
-
sort.cc is dependent on sort.h
-
main.cc and list.cc are dependent on list.h, node.h, and sort.h
-
node.cc is dependent on node.h
3. In a file titled "makefile_questions.txt", answer the following questions
(assuming the makefile that you just created):
Question 1: Assuming this is the first time you would type make, show the
commands that would be executed.
Question 2: Assuming you have already compiled the program, but then you
make a change to node.h, show the commands that would be executed if you
typed make.
Question 3: Assuming you have already compiled the program, but then make
a change to sort.cc, show the commands that would be executed if you
typed make.
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):
- break
- print
- step
- backtrace
- up
- down
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:
- makefile - The makefile you created above
- makefile_questions.txt - The answers to the makefile questions. You must
answer these questions in a text file and not answer them out loud.
- output from GDB showing the commands that you used
- What you have determined to have caused the mystery behavior
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
-
2 points - Attendance - Lab attendance will be 20% of the grade for each
lab. You will receive 1 point when the lab begins and 1 point when the lab
ends. Attendance will be taken during the first and last 5 minutes of the
lab period
-
2 points - Makefile portion
-
1 point - Makefile creation
-
1 point - Makefile questions
-
6 points - Debugging portion
-
3 points - Determine the cause of the mystery behavior
-
3 points - Using at least the commands listed above
- .3 extra credit points for demonstrating how watchpoints work
- Deductions
- -1 point - If both partners turn in the code. There should
only one turnin per group
- -5 points - Turned into the wrong lab section
- -1 point - No name on work turned in
- -5 points - Code not turned in at all. This deduction also applies to
turnins that do not contain a the partners name (only the name that is not
on the turnin will have 5 points deducted. The person that actually turned
the code in will only have 1 point deducted if their name is not on the
turnin).
- -5 points - If your currently assigned partner is in lab and you do not
work together
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.