0% found this document useful (0 votes)
48 views10 pages

Tutorial 3: Valgrind: By: Vajih Montaghami

This document is a tutorial on using Valgrind, an open-source memory debugging and profiling tool. It introduces Valgrind's main components like Memcheck for detecting memory errors. It provides instructions on installing Valgrind and using it to check for uninitialized memory usage, memory leaks, and other errors. Examples are given to demonstrate Valgrind's ability to detect outbound access, uninitialized variables, and memory leaks. Limitations in Valgrind's stack checking are also mentioned.

Uploaded by

Lena M Zhao
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views10 pages

Tutorial 3: Valgrind: By: Vajih Montaghami

This document is a tutorial on using Valgrind, an open-source memory debugging and profiling tool. It introduces Valgrind's main components like Memcheck for detecting memory errors. It provides instructions on installing Valgrind and using it to check for uninitialized memory usage, memory leaks, and other errors. Examples are given to demonstrate Valgrind's ability to detect outbound access, uninitialized variables, and memory leaks. Limitations in Valgrind's stack checking are also mentioned.

Uploaded by

Lena M Zhao
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

SE465/ECE453/CS447/CS647

Tutorial 3: Valgrind
By: Vajih Montaghami
2012-02-17
Saturday, 18 February, 12

[email protected]

Introduction
framework for building dynamic analysis tools Memcheck is a memory error detector, Cachegrind is a cache and branch- prediction profiler, Callgrind is a call-graph generating cache profiler, Helgrind, DRD are thread error detectors, Massif is a heap profiler, DHAT, SGcheck, BBV, ...
2012-02-17
Saturday, 18 February, 12

[email protected]

Memory checker?!
Use of un-initialized memory, R/W memory after it has been free'd, R/W off the end of malloc'd blocks, R/W inappropriate areas on the stack, Memory leak: Somewhere, you call malloc but never call free, Mismatched use of malloc/new/new[] vs free/delete/delete[], Overlapping src and dst pointers in memcpy() and related functions.

2012-02-17
Saturday, 18 February, 12

[email protected]

1. http://developer.kde.org/~sewardj/ 2. http://freshmeat.net/projects/valgrind/

3.2. Installing Run Install and


Uncompress, compile and install it:
#tar xvfz valgrind1.0.0.tar.gz #cd valgrind1.0.0 #./configure #make #make install

Mac, Linux:

Add the path to your path variable. Now valgrind is ready to catch the bugs.

Ubuntu:

#apt-get install valgrind

2012-02-17
Saturday, 18 February, 12

[email protected]

Prepare to Check
Compile by gcc or g++: -g: Debug Mode. -O0: Turn of the Optimization. Run by Valgrind:
$ valgrind --leak-check=full -v --show-reachable=yes --track-origins=yes ./example
[email protected]

2012-02-17
Saturday, 18 February, 12

Example 1:Outbound Access

2012-02-17
Saturday, 18 February, 12

[email protected]

Example 2: Uninitialized Variables

2012-02-17
Saturday, 18 February, 12

[email protected]

Example 3: Memory leak

2012-02-17
Saturday, 18 February, 12

[email protected]

Limitation
bounds checking on stack/static arrays checks programs dynamically

2012-02-17
Saturday, 18 February, 12

[email protected]

Reference
valgrind.org Manual: valgrind.org/docs/manual/valgrind_manual.pdf HOWTO Manual: www.ibiblio.org/pub/Linux/docs/HOWTO/
other-formats/pdf/Valgrind-HOWTO.pdf

2012-02-17
Saturday, 18 February, 12

[email protected]

10

You might also like