Professional Documents
Culture Documents
Tutorial 3: Valgrind: By: Vajih Montaghami
Tutorial 3: Valgrind: By: Vajih Montaghami
Tutorial 3: Valgrind: By: Vajih Montaghami
Tutorial 3: Valgrind
By: Vajih Montaghami
2012-02-17
Saturday, 18 February, 12
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, ...
2012-02-17
Saturday, 18 February, 12
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.
2012-02-17
Saturday, 18 February, 12
vmontagh@uwaterloo.ca
1. http://developer.kde.org/~sewardj/ 2. http://freshmeat.net/projects/valgrind/
Mac, Linux:
Add the path to your path variable. Now valgrind is ready to catch the bugs.
Ubuntu:
2012-02-17
Saturday, 18 February, 12
vmontagh@uwaterloo.ca
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
vmontagh@uwaterloo.ca
2012-02-17
Saturday, 18 February, 12
2012-02-17
Saturday, 18 February, 12
vmontagh@uwaterloo.ca
2012-02-17
Saturday, 18 February, 12
vmontagh@uwaterloo.ca
2012-02-17
Saturday, 18 February, 12
vmontagh@uwaterloo.ca
Limitation
bounds checking on stack/static arrays checks programs dynamically
2012-02-17
Saturday, 18 February, 12
vmontagh@uwaterloo.ca
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
vmontagh@uwaterloo.ca
10