SlideShare a Scribd company logo
1 of 10
Download to read offline
By:
2012-02-06 vmontagh@uwaterloo.cavmontagh@uwaterloo.ca
Tutorial 3: Valgrind
SE465/ECE453/CS447/CS647
Vajih Montaghami
Monday, 6 February, 12
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
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
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
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
2012-02-06 vmontagh@uwaterloo.ca
Example 1:Outbound Access
6
Monday, 6 February, 12
2012-02-06 vmontagh@uwaterloo.ca
Example 2: Uninitialized Variables
7
Monday, 6 February, 12
2012-02-06 vmontagh@uwaterloo.ca
Example 3: Memory leak
8
Monday, 6 February, 12
2012-02-06 vmontagh@uwaterloo.ca
Limitation
9
bounds checking on stack/static arrays checks programs dynamically
Monday, 6 February, 12
2012-02-06 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
10
Monday, 6 February, 12

More Related Content

Similar to Valgrind

0628阙宏宇
0628阙宏宇0628阙宏宇
0628阙宏宇
zhu02
 
SSD Caching: Device-Mapper- and Hardware-based solutions compared
SSD Caching: Device-Mapper- and Hardware-based solutions compared SSD Caching: Device-Mapper- and Hardware-based solutions compared
SSD Caching: Device-Mapper- and Hardware-based solutions compared
Werner Fischer
 

Similar to Valgrind (20)

0628阙宏宇
0628阙宏宇0628阙宏宇
0628阙宏宇
 
Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)
 
High Availability in YARN
High Availability in YARNHigh Availability in YARN
High Availability in YARN
 
TDMA Cluster-based MAC for VANETs (TC-MAC)
TDMA Cluster-based MAC for VANETs (TC-MAC)TDMA Cluster-based MAC for VANETs (TC-MAC)
TDMA Cluster-based MAC for VANETs (TC-MAC)
 
Quantifying the Performance of Garbage Collection vs. Explicit Memory Management
Quantifying the Performance of Garbage Collection vs. Explicit Memory ManagementQuantifying the Performance of Garbage Collection vs. Explicit Memory Management
Quantifying the Performance of Garbage Collection vs. Explicit Memory Management
 
Introduction to Parallelization ans performance optimization
Introduction to Parallelization ans performance optimizationIntroduction to Parallelization ans performance optimization
Introduction to Parallelization ans performance optimization
 
MariaDB/MySQL pitfalls - And how to come out again...
MariaDB/MySQL pitfalls - And how to come out again...MariaDB/MySQL pitfalls - And how to come out again...
MariaDB/MySQL pitfalls - And how to come out again...
 
Tips of Malloc & Free
Tips of Malloc & FreeTips of Malloc & Free
Tips of Malloc & Free
 
Drupal 8 Cache: Under the hood
Drupal 8 Cache: Under the hoodDrupal 8 Cache: Under the hood
Drupal 8 Cache: Under the hood
 
Give Your Site a Boost with Memcache
Give Your Site a Boost with MemcacheGive Your Site a Boost with Memcache
Give Your Site a Boost with Memcache
 
MM-4097, OpenCV-CL, by Harris Gasparakis, Vadim Pisarevsky and Andrey Pavlenko
MM-4097, OpenCV-CL, by Harris Gasparakis, Vadim Pisarevsky and Andrey PavlenkoMM-4097, OpenCV-CL, by Harris Gasparakis, Vadim Pisarevsky and Andrey Pavlenko
MM-4097, OpenCV-CL, by Harris Gasparakis, Vadim Pisarevsky and Andrey Pavlenko
 
Architecting Wide-ranging Analytical Solutions with MongoDB
Architecting Wide-ranging Analytical Solutions with MongoDBArchitecting Wide-ranging Analytical Solutions with MongoDB
Architecting Wide-ranging Analytical Solutions with MongoDB
 
Gluster: where weve been - a history
Gluster: where weve been - a historyGluster: where weve been - a history
Gluster: where weve been - a history
 
Effective UI Tests Scaling on Java
Effective UI Tests Scaling on JavaEffective UI Tests Scaling on Java
Effective UI Tests Scaling on Java
 
Selenium Camp 2016 - Effective UI tests scaling on Java
Selenium Camp 2016 - Effective UI tests scaling on JavaSelenium Camp 2016 - Effective UI tests scaling on Java
Selenium Camp 2016 - Effective UI tests scaling on Java
 
Cmp cache architectures a survey
Cmp cache architectures   a surveyCmp cache architectures   a survey
Cmp cache architectures a survey
 
SSD Caching: Device-Mapper- and Hardware-based solutions compared
SSD Caching: Device-Mapper- and Hardware-based solutions compared SSD Caching: Device-Mapper- and Hardware-based solutions compared
SSD Caching: Device-Mapper- and Hardware-based solutions compared
 
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
 
Matlab for a computational PhD
Matlab for a computational PhDMatlab for a computational PhD
Matlab for a computational PhD
 
Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Code
 

Recently uploaded

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

Valgrind