On Valgrind Mike Kordosky UCL Ely, 2005... if you are so unlucky as to have need of it.

Slides:



Advertisements
Similar presentations
Recitation By yzhuang, sseshadr. Agenda Debugging practices – GDB – Valgrind – Strace Errors and Wrappers – System call return values and wrappers – Uninitialization.
Advertisements

Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Introduction to GDB, Wireshark and Valgrind
CIS 415 – Operating System (Lab) CIS 415 Lab 5 Valgrind (memcheck) Dave Tian.
CSc 352 Freeing Dynamically Allocated Memory Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
CS 241 Section Week #2 2/4/10. 2 Topics This Section MP1 overview Part1: Pointer manipulation Part2: Basic dictionary structure implementation Review.
DEBUGGING IN THE REAL WORLD : Recitation 4.
File System Analysis.
1 Pointers A pointer variable holds an address We may add or subtract an integer to get a different address. Adding an integer k to a pointer p with base.
Adapted from Prof. Necula CS 169, Berkeley1 Memory Management and Debugging V Software Engineering Lecture 20.
CSE 303 Lecture 13a Debugging C programs
Overview Working directly with memory locations is beneficial. In C, pointers allow you to: change values passed as arguments to functions work directly.
Variables and Objects, pointers and addresses: Chapter 3, Slide 1 variables and data objects are data containers with names the value of the variable is.
IT253: Computer Organization
Use of Coverity & Valgrind in Geant4 Gabriele Cosmo.
RPROM , 2002 Lassi A. Tuura, Northeastern University Using Valgrind Lassi A. Tuura Northeastern University,
Pointers OVERVIEW.
1 8. Run-Time Arrays — Intro. to Pointers For declarations like double doubleVar; char charVar = 'A'; int intVar = 1234; the compiler____________the object.
C++ Memory Overview 4 major memory segments Key differences from Java
CS 241 Section Week #2 9/9/10. 2 Topics This Section MP1 issues MP2 overview Process creation using fork()‏ Debugging tools: valgrind, gdb.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 4 Pointers and Dynamic Arrays Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
SPL – Practical Session 2 Topics: – C++ Memory Management – Pointers.
CPSC 252 Dynamic Memory Allocation Page 1 Dynamic memory allocation Our first IntVector class has some serious limitations the capacity is fixed at MAX_SIZE.
Current Assignments Start Reading Chapter 6 Project 3 – Due Thursday, July 24 Contact List Program Homework 6 – Due Sunday, July 20 First part easy true/false.
C Programming Day 4. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 More on Pointers Constant Pointers Two ways to.
Dynamic Allocation Joe Meehean. Dynamic Allocation Memory for local objects is automatically created and reclaimed memory is created for it at beginning.
Chapter 7 Pointers: Java does not have pointers. Used for dynamic memory allocation.
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
Debugging of # P. Hristov 04/03/2013. Introduction Difficult problem – The behavior is “random” and depends on the “history” – The debugger doesn’t.
POINTERS. // Chapter 3 - Program 1 - POINTERS.CPP #include int main() { int *pt_int; float *pt_float; int pig = 7, dog = 27; float x = , y = 32.14;
NOVA art. memory leaking Alexey Naumov Lebedev Physical Institute Moscow 1.
System Programming Practical Session 7 C++ Memory Handling.
1 Debugging (Part 2). “Programming in the Large” Steps Design & Implement Program & programming style (done) Common data structures and algorithms Modularity.
1 C Basics Monday, August 30, 2010 CS 241. Announcements MP1, a short machine problem, will be released today. Due: Tuesday, Sept. 7 th at 11:59pm via.
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT:10 Advance Pointer Array, String and Dynamic Memory Allocation CS2311 Computer Programming.
Announcements You will receive your scores back for Assignment 2 this week. You will have an opportunity to correct your code and resubmit it for partial.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
Debugging Malloc Lab Detecting Memory-Related Errors.
CSE 333 – SECTION 2 Memory Management. Questions, Comments, Concerns Do you have any? Exercises going ok? Lectures make sense? Homework 1 – START EARLY!
HP-SEE Valgrind Usage Josip Jakić Scientific Computing Laboratory Institute of Physics Belgrade The HP-SEE initiative.
Variables and Types. Primitive Built-in Type Type Meaning Minimum Size bool boolean NA char character 8 bits wchar_t wide character 16 bits char16_t Unicode.
Basic Concepts:- Invalid use of Address Operator &75 &(‘a’) &(a+b)
Dynamic Instrumentation - Valgrind  Developed by Julian Seward at/around Cambridge University,UK  Google-O'Reilly Open Source Award for "Best Toolmaker"
From C to C++ Jyh-Shing Roger Jang (張智星)
a.k.a how we test Your code
Memory Leaks and Valgrind
C++ Catastrophes “if C allows you to shoot yourself in the foot, then C++ is giving you a machine gun!” James Prince.
CMSC 341 Lecture 2 – Dynamic Memory and Pointers (Review)
CDF Offline Operations
Debugging Memory Issues
CSE 220 – C Programming Pointers.
Lesson One – Creating a thread
Valgrind Overview What is Valgrind?
Valgrind, the anti-Alzheimer pill for your memory problems
Advanced course of C/C++
Week 7 Part 2 Kyle Dewey.
Student Book An Introduction
Dynamic Instrumentation - Valgrind
ניפוי שגיאות - Debugging
a.k.a how we test Your code
CS5123 Software Validation and Quality Assurance
Pointers Pointers point to memory locations
TUTORIAL 7 CS 137 F18 October 30th.
Dynamic Memory.
Pointer & Memory Allocation Review
CS703 - Advanced Operating Systems
Valgrind Overview What is Valgrind?
Dynamic Memory – A Review
Makefiles, GDB, Valgrind
SPL – PS2 C++ Memory Handling.
Presentation transcript:

On Valgrind Mike Kordosky UCL Ely, if you are so unlucky as to have need of it

What is it? ● Valgrind is a tool that finds: – uses of uninitialized memory – memory leaks (e.g. orphaned pointers) – cases of illegal memory access ● Runs on any code w/o recompilation... fabulous – Caveat: slow & uses lots of memory... run on minos?.fnal.gov ● Actually, this is just the Memcheck option. Valgrind has some other features too.

When to use it? ● Your program seems to leak memory ● Your program crashes in a bizarre way – inside an obviously safe function/class – depending on recompilation, time of day, and other voodoo ● Your program appears to be non- deterministic

How to use it ● Then wait a while... ● if you have db-attach set you need to monitor the job www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/valgrind.html valgrind --tool=memcheck\ --db-attach=yes\* --gen-suppressions=yes \* --suppressions=root.supp \* --error-limit=no \ --leak-check=yes \ (full) loon -bq my_script.C date_file

Example Output ● This is the source of the crash-on-exit problem Rustem was having ● TTree apparatus overwriting memory as a result of unallocated pointer ==2536== Invalid write of size 4 ==2536== at 0x1D350A4F: frombuf(char*&, unsigned*) (Bytes.h:319) ==2536== by 0x1D3501A6: TBuffer::operator>>(int&) (TBuffer.h:439) ==2536== by 0x1D43DFD8: int TStreamerInfo::ReadBuffer(TBuffer&, char** const&, int, int, int, int) (TStreamerInfoReadBuffer.cxx:589) ==2536== by 0x1E180306: TBranchElement::ReadLeaves(TBuffer&) (TBranchElement.cxx:1829) ==2536== by 0x1E171CAA: TBranch::GetEntry(long long, int) (TBranch.cxx:763) ==2536== by 0x1E17DB8A: TBranchElement::GetEntry(long long, int) (TBranchElement.cxx:1227) ==2536== by 0x1E61A6FD: TTreeIndex::GetEntry(long long) (TTreeIndex.cxx:182) ==2536== by 0x1E619EFA: TTreeIndex::TTreeIndex(TTree const*, char const*, char const*) (TTreeIndex.cxx:139) ==2536== by 0x1E61BF51: TTreePlayer::BuildIndex(TTree const*, char const*, char const*) (TTreePlayer.cxx:312) ==2536== by 0x1E1A757E: TTree::BuildIndex(char const*, char const*) (TTree.cxx:1482) ==2536== by 0x1CD5EAC2: PerOutputStream::BuildTreeIndex() (PerOutputStream.cxx:656) ==2536== by 0x1CD5E7F0: PerOutputStream::Write() (PerOutputStream.cxx:628) ==2536== Address 0x22815B40 is not stack'd, malloc'd or (recently) free'd ==2536==

Example II ● Valgrind's summary output ● The program consumed lots of memory but didn't actually “leak” (much) ● Valgrind didn't find the error.... or did it? ● Why? ==21775== LEAK SUMMARY: ==21775== definitely lost: bytes in 203 blocks. ==21775== indirectly lost: bytes in 968 blocks. ==21775== possibly lost: bytes in blocks. ==21775== still reachable: bytes in blocks. ==21775== suppressed: 0 bytes in 0 blocks. ==21775== Reachable blocks (those to which a pointer was found) are not shown. ==21775== To see them, rerun with: --show-reachable=yes

What was it? ● Was going on in tracker ● Isn't a real memory “leak”... just keeping hits in memory long after they were necessary ● Found using google-perftools – but only after identifying tracker as the problem ● Lesson: Valgrind useful but not appropriate for all leaks... try multiple tools if possible CandSliceHandle * dupSlice=slice->DupHandle(); but never deleted CandSliceHandle created:

Example: google- perftools AlgTrackSRList::RunAlg() CandSliceHandle::DupHandle() new TObject leak