Lab Assignment--Compile and Debug


Lab Code

To get the sample and exercise code, please use the following commands in your Lab 2 folder:
   wget www.labs.cs.uregina.ca/330/CompileDebug/Lab2.zip
   unzip Lab2.zip

Part 1 - Makefile

Use the code in the replit teams project

There is a makefile already in the project. Of note are:

Modify the makefile to:

Part 2 - 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, with the following command:

valgrind --leak-check=yes ./your_executable
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== 
==5583== All heap blocks were freed -- no leaks are possible
==5583== 
==5583== For counts of detected and suppressed errors, rerun with: -v
==5583== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 8 from 6) 

Part 3 - 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 valgrind (this should compile the code and run valgrind on it)
  4. gdb executable (substitute your own executable name)
  5. Set a breakpoint on the findMax function (in the functions.c file)
  6. run the code with an input of 50 for the size of the array
  7. Using length, print all of the elements in the array
  8. print the value stored at max's address
  9. use next as many times as needed (inside the "for" loop) to see the value stored at max's address change
  10. After the value stored at max's address has been modified inside the "for" loop, print the value stored at max's address
  11. Use until at the "for" loop to skip over the other iterations of the loop
  12. print the value stored at max's address
  13. use next to continue through the code until you get a message that your program or process "exited normally"
  14. quit the debugger
  15. exit the script

Deliverables in URCourses: 3 code files, 1 makefile, 1 script file

  1. Debugged code: main.c, functions.c, and functions.h
     
  2. Makefile for the project.
  3. Script of make, valgrind, and gdb from Part 3 (named with a .txt extension)

Notes