Project 0: Compiling & Debugging on GL

Due: Tuesday, September 19, 8:59:59pm

Note: there are no late submission folders for Project 0. Do this one on time.

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 2: link your shared directory

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 2017 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/c/h/chang/pub/cs341stuff/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.


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.