Project 0: Compiling & Debugging on GL
Due: Tuesday, February 13, 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.
The file is also available on GL as:
/afs/umbc.edu/users/p/a/park/pub/cmsc341/s18/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):
The command option "-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.
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 print out a few numbers, then crash with "Segmentation fault" error; this should feel very familiar from your CMSC 202 days. You do not have to actually fix the code: just find out where and why it crashed.
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.
- 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 pick and str[pick]. (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 pick and str[pick] 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 pick 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 pick before proj0.out crashed. Now, create and edit a text file called answer.txt. In this file, type in this last value of pick. 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.
- proj0.cpp
- typescript
- answer.txt
Just leave these files in place and you are done.