Lab Assignment--Compile and Debug
Part 1 - Linux/Unix Commands
Before you get started, you need to know the script command and how to
remotely log onto a Linux machine.
You can think of the script as a "recording" of your Unix commands.
A script is started by typing: script filename.
Typically, you want to name your files with an extension of .log.
You end the script by typing exit.
To remotely log on to the Linux machines, you first need to know the Linux
machines that are available to you. The command to tell you that is:
Then, you pick one machine from the list and type: ssh machine
ALL LABS (AND SCRIPTS) SHOULD BE DONE ON LINUX
Follow all of the steps:
- start a script in your home directory
(hint: script commands.log will start the script and save it to commands.log)
- display all of the Linux machines in CL115
- log onto one of the Linux machines in the list
- (create and) change into your cs330 directory
- (create and) change into your labs directory
- (create and) change into your lab1 directory
- create two new directories named
unix and code
- change into your unix directory
- without using a text editor, create three files called 'one', 'two', and 'three'
- check the timestamps with ls -l
- create a directory named BAK
- copy the file 'three' to the directory BAK and rename it 'three.bak' (try to do it in one statement)
- change working directory to BAK
- check the timestamps and permissions with ls -l
- move up one directory
- remove the directory BAK and its contents
- logout of the Linux machine (hint: exit or lo)
- exit from the script (hint: exit)
Part 2 - Makefile
Copy three "C" files into your code directory by using the following
cp /net/data/ftp/pub/class/330/CompileDebug/Exercise/*.* .
Write a Makefile for these files with the following specifications:
- Use gcc instead of g++
- Provide the options to debug the program later.
- Include at least one variable in your Makefile.
- Add a clean target that will remove the executable, any core files, and any .o files
Part 3 - Fix the Code
The code provided should compile; but it contains several logic errors.
Use gdb and valgrind to help you find these errors.
In the end, when you run your code through valgrind, you should see a
message similar to the following:
==5583== HEAP SUMMARY:
==5583== in use at exit: 0 bytes in 0 blocks
==5583== total heap usage: 1 allocs, 1 frees, 400 bytes allocated
==5583== All heap blocks were freed -- no leaks are possible
==5583== For counts of detected and suppressed errors, rerun with: -v
==5583== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 8 from 6)
Part 4 - Capture: "make", "valgrind", and "gdb"
In this part, you will bring together all of the tools from this lab
into one script. Follow the steps below
using your debugged code from this lab:
- script scriptname (use your own "scriptname")
- make clean
- valgrind --leak-check=yes executable
(substitute your own executable name)
- gdb executable (substitute your own executable name)
- Set a breakpoint on the findAndReturnMax (in the
- run the code with an input of 50 for the size of the array
- Using "length", print all of the elements in the array
- print the value of "max"
- use next as many times as needed (inside the "for" loop) to see the value of "max" change
- After "max" has been assigned a different value inside the "for" loop, print the value of "max"
- Use until at the "for" loop to skip over the other
iterations of the loop
- print the value of "max"
- use next to continue through the code until you get a
message that your program or process "exited normally"
- quit the debugger
- exit the script
Deliverables: 3 code files, 1 makefile, 2 script files
- Script of Unix commands from Part 1
- Debugged code: main.c, functions.c,
- Makefile for the project.
Script of make, valgrind,
and gdb from Part 4
- with at least one variable
- with a clean target
- with debug options
- using gcc as the compiler
- Do not create a zip file
- Submission is on UR Courses
- Submit your own work
- Be mindful that your assignment is due two hours before the start of your next lab