valgrind - Linux Tools For Debugging And Profiling Programs ( bug reporting tool )
Few days back I wrote about strace tool for reporting and finding bug in program. Today I'm going to talk about another interesting tool called valgrind.
Valgrind is a flexible program for debugging and profiling Linux executables. It consists of a core, which provides a synthetic CPU in software, and a series of "tools", each of which is a debugging or profiling tool. The architecture is modular, so that new tools can be created easily and without disturbing the existing structure. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools.
The Valgrind distribution currently includes five production-quality tools:
- a memory error detector
- a thread error detector
- a cache and branch-prediction profiler
- a call-graph generating cache profiler
- a heap profiler
It also includes two experimental tools:
- a data race detector
- an instant memory leak detector.
It runs on the following platforms:
- X86/Linux
- AMD64/Linux
- PPC32/Linux
- PPC64/Linux
How do I use valgrind?
Valgrind is typically run as follows:
$ valgrind command-name arg1 arg2 argN
$ valgrind program args
$ valgrind ./myapp -d /tmp -f 120
You can select tool using the --tool=TOOLName option. For example use memcheck which is a fine-grained memory checker. To generate trace back for command called myapp, enter:
$ valgrind --tool=memcheck -v --log-file=myapp.dbg --num-callers=8 ./myapp -d /tmp -f 120
Where,
- --tool=memcheck : Run the Valgrind tool called memcheck
- -v : Verbose output
- --log-file=myapp.dbg : Specifies that Valgrind should send all of its messages to the specified file.
- --num-callers=8 : By default, Valgrind shows twelve levels of function call names to help you identify program locations. You can change that number with this option. This can help in determining the program’s location in deeply-nested call chains.
The --leak-check option turns on the detailed memory leak detector:
$ valgrind --tool=memcheck -v --log-file=myapp.dbg --num-callers=8 --leak-check=yes ./myapp -d /tmp -f 120
Further readings:
Continue reading rest of the How to report / Find a bug under Linux series.
Contents
- Debugging Tip: Trace the Process and See What It is Doing with strace
- valgrind - Linux Tools For Debugging And Profiling Programs ( bug reporting tool )
- ktrace - FreeBSD / Mac OS X Process Tracing and Reporting Tool
Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or full RSS feed to get all updates.
You can Email this page to a friend.
You may also be interested in...
- ktrace - FreeBSD / Mac OS X Process Tracing and Reporting Tool
- Apache httpd debugging Logs on steroids
- How to debug a Shell Script under Linux or UNIX
- Testing Connectivity with fping and send mail if any hosts are unreachable
- How to debug make: tips for debugging makefiles
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: check option, debugging, leak check, memcheck, memory checker.instant memory, memory error, memory leaks, memory management, quality tools, segmentation fault, using valgrind, valgrind command, valgrind memory, valgrind tutorial ~ Last updated on: April 15, 2008



Recent Comments
Today ~ 2 Comments
Today ~ 37 Comments
Today ~ 1 Comment
Yesterday ~ 12 Comments
Yesterday ~ 2 Comments