2. 2012-02-06 vmontagh@uwaterloo.ca
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, ...
2
Monday, 6 February, 12
3. 2012-02-06 vmontagh@uwaterloo.ca
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.
3
Monday, 6 February, 12
4. 2012-02-06 vmontagh@uwaterloo.ca
Install and Run
4
http://developer.kde.org/~sewardj/1.
http://freshmeat.net/projects/valgrind/2.
3.2. Installing
Uncompress, compile and install it:
#tar xvfz valgrind−1.0.0.tar.gz
#cd valgrind−1.0.0
#./configure
#make
#make install
Add the path to your path variable. Now valgrind is ready to catch the bugs.
#apt-get install valgrind
Mac, Linux:
Debian:
Monday, 6 February, 12
5. 2012-02-06 vmontagh@uwaterloo.ca
Prepare to Check
Compile by gcc or g++:
-g: Debug Mode.
-O0: Turn of the Optimization.
Run by Valgrind:
5
-O0 means: line numbers
may be inaccurate and
you may occasionally
encounter false alarms.
$ valgrind --leak-check=full -v --show-reachable=yes --track-origins=yes ./example
Monday, 6 February, 12