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: 
cs_clients CL115.

Then, you pick one machine from the list and type: ssh machine

Follow all of the steps:
  1. start a script in your home directory
  2. (hint: script commands.log will start the script and save it to commands.log)
  3. display all of the Linux machines in CL115
  4. log onto one of the Linux machines in the list
  5. (create and) change into your cs330 directory
  6. (create and) change into your labs directory
  7. (create and) change into your lab1 directory
  8. create two new directories named unix and code
  9. change into your unix directory
  10. without using a text editor, create three files called 'one', 'two', and 'three'
  11. check the timestamps with ls -l
  12. create a directory named BAK
  13. copy the file 'three' to the directory BAK and rename it 'three.bak' (try to do it in one statement)
  14. change working directory to BAK
  15. check the timestamps and permissions with ls -l
  16. move up one directory
  17. remove the directory BAK and its contents
  18. logout of the Linux machine (hint: exit or lo)
  19. exit from the script (hint: exit)

Part 2 - Makefile

Copy three "C" files into your code directory by using the following command:
cp /net/data/ftp/pub/class/330/CompileDebug/Exercise/*.* .
Write a Makefile for these files with the following specifications:

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:

  1. script scriptname (use your own "scriptname")
  2. make clean
  3. make
  4. valgrind --leak-check=yes executable (substitute your own executable name)
  5. gdb executable (substitute your own executable name)
  6. Set a breakpoint on the findAndReturnMax (in the functions.c file)
  7. run the code with an input of 50 for the size of the array
  8. Using "length", print all of the elements in the array
  9. print the value of "max"
  10. use next as many times as needed (inside the "for" loop) to see the value of "max" change
  11. After "max" has been assigned a different value inside the "for" loop, print the value of "max"
  12. Use until at the "for" loop to skip over the other iterations of the loop
  13. print the value of "max"
  14. use next to continue through the code until you get a message that your program or process "exited normally"
  15. quit the debugger
  16. exit the script

Deliverables: 3 code files, 1 makefile, 2 script files

  1. Script of Unix commands from Part 1
  2. Debugged code: main.c, functions.c, and functions.h
  3. Makefile for the project.
  4. Script of make, valgrind, and gdb from Part 4