


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A lab exercise for cmsc 321: operating systems, where students learn to use valgrind, a memory debugging tool, to identify and fix memory management errors in c/c++ programs. The lab includes three intentionally buggy example programs and instructions for using valgrind to find and correct the errors. Students are required to complete an answer sheet as they progress through the assignments.
Typology: Lab Reports
1 / 4
This page cannot be seen from the preview
Don't miss anything!
CMSC 321: Operating Systems Lab 2 — 22 January 2007 Using Valgrind Overview: In this lab, you will learn to use Valgrind, a very handy memory debugging tool. Using Valgrind, you can find many memory management errors in your programs, including memory leaks (more on memory leaks in a moment). So why should you use Valgrind? An entire list of reasons is provided on the Valgrind web site (http://valgrind.org/info/about.html), but the following is, from your perspective, the most important: Valgrind will save you hours of debugging time. Because many of you are new to, or at least relatively uncomfortable with, dynamic‐memory management in C/C++, you should make frequent use of Valgrind. Executing the Lab: On the Assignments page of the course web site, you will find the gzipped tarball lab2-examples.tgz — download and unpack the file into the directory of your choice. Here’s a quick primer on handling tar files: tar xvzf lab2‐examples.tgz Unpack the gzipped tar archive in the current directory tar czf lab2‐examples.tgz *.c Create the gzipped tar archive of all .c files in the current directory To create uncompressed .tar files, leave out the z flag. Tar has a huge number of other capabilities, which you can learn about from the tar man page. (Historical note: the popular .zip format is a combination of tar and the Unix compress compression utility. Gzip is a more effective compression algorithm that contains no patented software technology. Note also that Java .jar archive are really tar archives, and the command line flags for the two tools are very similar.) Now let’s walk through some intentionally buggy example programs, demonstrating the use of Valgrind to find the bugs and highlighting common memory mistakes along the way. Complete your electronic answer sheet (included in the tarball as lab2‐Ans.txt) as you complete the assignments below. Program #1:
Submitting: Create a gzipped tarball of your modified files (following the instructions above), choosing a name that identifies you and the assignment, and drop the tarball in my netfiles inbox. Be sure to include your answer sheet as well. Summary: You have seen that Valgrind is capable of finding uninitialized variables, problems with allocating and deallocating memory, and memory leaks. Valgrind is capable of much more than we can learn in one lab — I encourage you to visit the Valgrind Web site for more information. Acknowledgments: Thanks to Will Jones in the ECE Department at Clemson University for graciously permitting us to use and modify the example programs he created. If you found these to be helpful, send Will an email to that effect: wjones@parl.clemson.edu. Thanks also to Barry Lawson for the original formulation of this lab exercise.