LHC Computing Grid > LCG App Area > SPI Home > SPI Workbook  

SPI - Workbook

Updated
18-Nov-2004 17:16

SPI Workbook

LCG Workbook

SPI Quick Links

SPI Home
SPI Index Page

SPI Workbook

SPI Services Links

LCG Workbook

Savannah Portal
External Software
Software Testing

Build servers
Software Configuration

Software Download
Quality Assurance

LCG App. Area

Home Page
LCG Agenda

PI Project
POOL Project
SEAL Project
Simulation Project

SPI Project

HowTo run Valgrind

Introduction
How to use Valgrind
Tips and Notes
Useful Links

Introduction

Valgrind is a GPL'd tool to help you find memory-management problems in your programs. When a program is run under Valgrind's supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Valgrind can detect problems
such as:

  • use of uninitialized memory
  • reading/writing of memory after it has been freed
  • reading/writing off the end of malloc'd blocks
  • reading/writing inappropriate areas on the stack
  • memory leaks in which pointers to malloc'd blocks are lost forever
  • passing of uninitialized and/or unaddressable memory to system calls
  • mismatched use of malloc/new/new [] vs. free/delete/delete [].
Valgrind can debug more or less any dynamically linked executable, without modification, recompilation, or anything.
In addition, a satellite program, cachegrind, can be used for processor-level (simulated) cache analysis.

For more information look at the Valgrind Homepage.
Full documentation of the tool is supplied. Techinical notes, explaining how Valgrind is implemented,  are also provided.
 

return to top of page


How to use Valgrind

Valgrind is installed at CERN in the LCG external area.  Currently version 1.04 is installed and only for Linux redhat72.
In order to use you have to set your path to  :

   /afs/cern.ch/sw/lcg/external/valgrind/1.0.4/rh72_gcc2952/bin
 

Then just run your application, but place the word valgrind in front of your usual command-line invocation.
For example, if you want to run Valgrind for the command "ls -l"  you do:

   valgrind ls -l
 

Note that you should run the real (machine-code) executable here. If your application is started by, for example, a shell or perl script, you'll need to modify it to invoke Valgrind on the real executables. Running such scripts directly under Valgrind will result in you getting error
reports pertaining to /bin/sh, /usr/bin/perl, or whatever interpreter you're using. This almost certainly isn't what you want and can be confusing.

 

The output of Valgrind consists of adding some commentary text to the program output, reporting for example errors.
All lines in the commentary are of the following form:

 ==12345== some-message-from-Valgrind

where 12345 is the process ID. This scheme makes it easy to distinguish program output from Valgrind commentary.
Each error detected produces a similar prefixed output, indicating the type of error (e.g. Invalid read of size 4), a stack trace indicating
where the error occurred and information about the memory location.
If your error will cause a segmentation fault,  your program will still suffer the same fate, but Valgrind will emit first the message which
cause the fault, with the indication where the error occurred. This results very useful in spotting the cause of the error
 

return to top of page


Tips and Notes

In order to get more information from Valgrind, build the code you analyse with debugging information. It is not required, but if you recompile your modules with the  "-g" option, Valgrind will tell you exactly the line where the error occurred.

Valgrind reports only unique errors. After certain number of errors is reached, Valgrind begins to suppress errors. After even more errors,
it suppresses error reporting completely. Both limits are controlled by command line options, however after having reached the limit of 300
errors is better going to fix your program !

return to top of page


Useful Links


return to top of page




Last modified: Tue Nov  5 CET 2002
$Revision: 1.10 $ $Author: aimar $ Untitled Document