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.

// File: proj0.cpp // // CMSC 341 Fall 2018 Project 0 // // Buggy program to be tested with gdb #include <iostream> #include <cmath> #include "proj0.h" using namespace std; int main() { int previous, current, size; int *ptr ; previous = 0 ; for (int i = 1; i < 35; i++) { current = chaos(i); size = current - previous; ptr = new int[size]; // allocate array previous = current; delete[] ptr; } return 0; }

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:

cd ~/cs341proj/proj0

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):

g++ -gstabs+ -I ../../00Proj0 ../../00Proj0/chaos.cpp proj0.cpp -o proj0.out

Here's what the command options mean:

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:

./proj0.out

It should crash with an error that looks somewhat like:

terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Abort


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.)


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.

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:

cat typescript


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.

Just leave these files in place and you are done.