Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Lab4 Lab XXXXXXXXXXIntroduction to Valgrind CIS2500 Winter 2021 This lab is about a command-line tool tool called Valgrind. It is a very useful tool to detect memory errors and to...

1 answer below »
Lab4
Lab XXXXXXXXXXIntroduction to Valgrind CIS2500 Winter 2021

This lab is about a command-line tool tool called Valgrind. It is a very useful tool to detect
memory e
ors and to detect memory leaks. To run valgrind, first you must compile your code
and create an executable. Now you can run valgrind on the executable. For example, if a.out is
the name of my executable, I will run vagrind as:

$ valgrind ./a.out

You can also run it using flags such as -g. To learn more on the syntax of valgrind, you can run
the man command:

$ man valgrind

In general, it reports a heap summary, a leak summary and an e
or summary.

Part I (ungraded part): Read more on valgrind and understand the leak summary, especially
how it calculates the “definitely lost” and “indirectly lost” bytes. Note that some memory leak
occurs when we use standard li
aries such as stdio.h.

1. Example report on heap, leak and e
or report:
For example, it reports the following for the “Hello world” program given in the textbox on the
ight-hand side:



2. Example on initialization e
or:
Valgrind is also useful in finding initialization e
ors. For example, it reports the following for the
program given in the textbox on the right-hand side. As you can see line 8 is attempting to print
a
[1] that has not been initialized – and valgrind reports this e
or, including the line number.




Part II (graded part):

You are given 3 program files. You must run each file using valgrind, understand the report it
generates and fix the memory / initialization issues with it.

For each given source file, you must submit

(a) the output generated by valgrind
To capture the output, you can use valgrind to log the report to a file (e.g.
log_file1), instead of displaying it on standard output.
valgrind --log-file=log_file1 ./a.out

(b) Improved program file such that
• “definitely lost” and “indirectly lost” bytes is zero.
• Source File is free of any initialization e
or

Part III (Submission):
There are a total of 6 files to submit (2 for each program file). You must create a tar file that
consists of these 6 files. A tar file can be created using the following command. Here -c is for
create, v for ve
ose and f for filename.

The following command will compress all files in the cu
ent folder to a file called lab3.tar.

tar -cvf lab3.tar *

The following command will compress files file1 and log_file1 to a file called lab3.tar.

tar -cvf lab3.tar file1 log_file1

To learn more on the tar command, man it!

At the end, submit the tar file lab3.tar to Gitlab.



*Note*\
Replace lab3.tar by lab4.tar at all places
in this document
Answered 1 days After Mar 13, 2023

Solution

Mohith answered on Mar 13 2023
29 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here