Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Lab Assignment - - Compile and Debug Lab Code To get the sample and exercise code, please use the following commands in your Lab 2
Lab AssignmentCompile and Debug
Lab Code
To get the sample and exercise code, please use the following commands in your Lab folder:
wget wwwlabs.csuregina.caCompileDebugLabzip
unzip Labzip
Part Makefile
Use the code in the replit teams project
There is a makefile already in the project. Of note are:
it uses gcc instead of g which means that you will be writing pure C code
it provides the options to debug the program later. Any guesses what you will be doing?
Modify the makefile to:
target this exercises's C files
include at least one variable Not compile, will be lab demo
;
include a valgrind target so that you can type "make valgrind"
Part 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 leakcheckyes yourexecutable
you should see a message similar to the following:
HEAP SUMMARY:
in use at exit: bytes in blocks
total heap usage: allocs, frees, bytes allocated
All heap blocks were freed no leaks are possible
For counts of detected and suppressed errors, rerun with: v
ERROR SUMMARY: errors from contexts suppressed: from
Part 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
make valgrind this should compile the code and run valgrind on it
gdb executable substitute your own executable name
Set a breakpoint on the findMax function in the functions.c file
run the code with an input of for the size of the array
Using length, print all of the elements in the array
print the value stored at max's address
use next as many times as needed inside the "for" loop to see the value stored at max's address change
After the value stored at max's address has been modified inside the "for" loop, print the value stored at max's address
Use until at the "for" loop to skip over the other iterations of the loop
print the value stored at max's address
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 in URCourses: code files, makefile, script file
Debugged code: main.c functions.c and functions.h
Makefile for the project.
with at least one variable and valgrind target
when submitting, please rename as makefile.txt
Script of make, valgrind, and gdb from Part named with a txt extension
Notes
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started