Project 0: Compiling & Debugging on GL
Due: Tuesday, September 11, 8:59:59pm
Note: there are no late submission folders for Project 0. Do this one on time.Change Log
Modified items are in highlighted in orange color.[Saturday Sep 8, 06:00pm] An update has been added to Step 1 regarding a directory referred to in the CMSC 202 Spring16 Lab. Also, the 00Proj0 directory referred to in Step 4 has been made available (it was installed in the wrong place!). The due date for the project has been pushed back to the end of the week (Fri at 9pm).
Objectives
The objective of this programming assignment is to make sure that you are set up to compile and debug C++ programs on GL and that you can copy programs into your submission folders.
Introduction
In this project, you will go through all of the mechanical steps of compiling, debugging and submitting a C++ program on GL. If you have submitted programs on GL using shared directories (instead of the submit command), then these steps should be quite familiar.
Assignment
Step 0: familiarize yourself with Unix
If you haven't used Unix before, go over the Unix guides listed in the Resources page.
Step 1: remember gdb
If you do not remember how to use the gdb debugger or never used it at all, then read this tutorial on debugging with gdb. (Yes, do actually read it.)
Next, complete the
Spring 2016 CMSC 202 gdb lab. (Yes, actually go through the
steps of this lab.)
Step 1 of the lab tells you to copy a .zip file from
Prof. Marron's directory. He has archived these files to a different
directory, so you should use the following command instead (note the
addition of "old" in the middle of the pathname):
cp /afs/umbc.edu/users/c/m/cmarron/pub/old/cmsc202/lab7.zip .
unzip lab7.zip
Step 2: link your shared directory
(Note that this, and subsequent, steps require you to have set up your submission directory first. The necessary system directories will not be set up until the second week of classes, so if you are an early starter, you might have to pause here.)
Follow the instructions on the Project Submission page to make a symbolic link to the shared directory in your home directory.
Step 3: copy the following program to your proj0 submission directory.
The file is also available on GL as:
/afs/umbc.edu/users/p/a/park/pub/cmsc341/f18/proj0/proj0.cpp
Step 4: Compile and run
Go to your proj0 submission directory. If you followed the recommended setup, you would use the Unix command:
Your copy of the proj0.cpp file should be in this directory. (Check using ls.) Then, compile using this exact Unix command (just cut and paste):
Here's what the command options mean:
- "-gstabs+" tells g++ to create debugging information that in the stabs format using extensions that is understood only by the gdb debugger. I.e., it tells g++ to play nice with gdb.
- "-I ../../00Proj0" tells g++ to look for header files in a directory called 00Proj0 two levels up. This is where proj0.h used by proj0.cpp lives. Without this option, g++ will say that it cannot find a file called proj0.h. You can go look at this file.
- "../../00Proj0/chaos.cpp" is just another C++ file to compile. The chaos.cpp file has the implementation of the chaos() function.
This will be the typical situation for project submission in this class. Some of the files are provided by you (e.g., proj0.cpp). Other files you are not allowed to change (e.g., proj0.h and chaos.cpp). If your files do not compile using the specified Unix command, you will receive a very low grade.
Now run the compiled program:
It should crash with an error that looks somewhat like:
Step 5: Debug the program using gdb
Use gdb to perform the following steps. (You can do this because you actually read the tutorial and worked on the lab in Step 1.)
- Determine the line number in proj0.cpp where the program crashed. (The GDB Lab you did in Step 1 above should have shown you how to use the where command to do this.)
- Set a breakpoint at that line.
- Re-run the program.
- The first time that the breakpoint is encountered, use the display command to print out the value of the variables i and size. (Use two separate display commands.)
- Use the continue command to keep running the program until it crashes. Each time the breakpoint is encountered, the values of i and size are printed out again. To continue running after the breakpoint, you can just hit the return key instead of typing continue if continue was the last command that you typed in.
- Remember the last value of i that was printed out before the program crashed.
- Exit the debugger.
Step 6: record yourself compiling and debugging
Note: if you are already familiar with gdb, you can do this step simultaneously with Steps 4 and 5.
The Unix script command records your console session. Everything you type is recorded in a file called typescript. All of the output produced by programs that you run will also be captured.
- Enter the script command by typing script.
You should see:
Script started, file is typescript - Compile proj0.out as you did in Step 4.
- Run proj0.out
- Debug using gdb as you did in Step 5.
- Exit the script command by typing exit
You should see:
exit Script done, file is typescript
You should double check that the typescript file actually recorded you compiling and using gdb. You can print out the contents of the typescript file using:
Step 7: save your answer
In Step 5, you remembered the last value of the variable i before proj0.out crashed. Now, create and edit a text file called answer.txt. In this file, type in this last value of i. Your file should have a single line that has one number. NB: do NOT put anything else in this file other than a single line with a single number! A complete, grammatically correct sentence is neither desired or considered correct, so do not enter "The answer that I got was 47" – we just want the number "47".
What's in your submit directory
After you are done, you should have the following files in your proj0 directory.
- proj0.cpp
- typescript
- answer.txt
Just leave these files in place and you are done.