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

c language have to be done in linux environment


Microsoft Word - Lab4.docx Lab 4 Introduction to Valgrind CIS2500 This lab is about a command-line tool tool called Valgrind. It is a very useful tool to detect memory errors and to detect memory leaks. You are required to do this lab on the school server (linux.socs.uoguelph.ca). 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 may also run it using flags such as -g and others. 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 error 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 libraries such as stdio.h. 1. Example report on heap, leak and error report: For example, it reports the following for the “Hello world” program given in the textbox on the right-hand side: 2. Example on initialization error: Valgrind is also useful in finding initialization errors. 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 arr [1] that has not been initialized – and valgrind reports this error, including the line number. Part II (graded part): You are given 3 source 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 on the given source file To save the output to a file, use valgrind with --log-file flag to log the report to a file (e.g. logFile1.txt), instead of displaying it on standard output. valgrind --log-file=logFile1.txt ./a.out Note that you are allowed to use other flags with valgrind. (b) an improved C program file such that • “definitely lost” and “indirectly lost” bytes is zero. • source file is free of any initialization error Part III (Submission): There are a total of 6 files to submit (2 for each source 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 flag c is for create, v for verbose and f for filename. The following command will compress all files in the current folder to a file called lab4.tar. tar -cvf lab4.tar * The following command will compress files file1.c and log_file1.txt to a file called lab4.tar. tar -cvf lab4.tar file1.c log_file1.txt To learn more on the tar command, man it! At the end, submit the tar file lab4.tar to Gitlab.
Mar 19, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here