LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-10-2002, 06:22 PM   #1
cyent
Member
 
Registered: Aug 2001
Location: ChristChurch New Zealand
Distribution: Ubuntu
Posts: 374

Rep: Reputation: 83
Thumbs up Valgrind - an answer.


This is not a question.

It is an answer.

Use valgrind on your programs.

Disclaimer. I have no association with Valgrind. Merely a very satisfied user. (Who wishes that more of the tools I use had been valgrinded before released....)

(Hint: Test Driven Development + Unit Tests + Valgrind == Very Good Things)

From http://developer.kde.org/~sewardj/

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 uninitialised memory
* Reading/writing memory after it has been free'd
* Reading/writing off the end of malloc'd blocks
* Reading/writing inappropriate areas on the stack
* Memory leaks -- where pointers to malloc'd blocks are lost forever
* Passing of uninitialised and/or unaddressible memory to system calls
* Mismatched use of malloc/new/new [] vs free/delete/delete []
* Some misuses of the POSIX pthreads API

Valgrind tracks each byte of memory in the original program with nine status bits, one of which tracks addressibility of that byte, while the other eight track the validity of the byte. As a result, it can detect the use of single uninitialised bits, and does not report spurious errors on bitfield operations.

You can use it to debug more or less any dynamically-linked ELF x86 executable, without modification, recompilation, or anything. If you want, Valgrind can start GDB and attach it to your program at the point(s) where errors are detected, so that you can poke around and figure out what was going on at the time.

Valgrind works well enough to debug many large x86-linux applications. To give you some idea of the scale of programs it can run: most of KDE3, Gnome stuff, Mozilla, OpenOffice, MySQL, Opera, KOffice-1.2beta1, emacs-21.2, xemacs-21.5(--pdump), Netscape-4.78, Gcc, AbiWord, etc, etc. KDE3 was extensively valgrinded in the two months prior to the KDE 3.0 release. Valgrind is first and foremost a debugging tool for large, complex programs. It isn't a toy or a research vehicle.
 
Old 01-06-2006, 10:28 AM   #2
yakotey
LQ Newbie
 
Registered: Jun 2005
Posts: 22

Rep: Reputation: 0
Well then you can help me.

I have this strange error:

valgrind forum valgrind: failed to start tool 'memcheck' for platform 'x86-linux': No such file or directory

Thank you in advance.
 
Old 01-17-2006, 03:45 PM   #3
cyent
Member
 
Registered: Aug 2001
Location: ChristChurch New Zealand
Distribution: Ubuntu
Posts: 374

Original Poster
Rep: Reputation: 83
No idea. I need a little bit more information.

What system you are running, how did you install valgrind.

What is the output of...
valgrind --version

What si the output of
valgrind date
 
Old 01-18-2006, 02:18 AM   #4
stephenwalter
Member
 
Registered: Jul 2005
Location: india,coimbatore
Distribution: Fedora core 4
Posts: 85

Rep: Reputation: 15
Hello,
I too have a query about valgrind .I have tried to fix memory leaks using valgrind and it works fine , but sometimes i find that it is very slow and my application is a client server based one. The version of valgrind iam using is 2.4.0 and the 'C'code is built using gcc compiler version 4.0.0 . It seems that whenever i run valgrind my cpu usage goes to 100% and some times i have to close all other applications that iam running and just run valgrind other wise my application does not run successfully under valgrind. Iam not sure whether this is caused due to an inefficiency in my program or is this how valgrind works !!!!!(bcos i find no such issues when i simply run my application). Any help in this regard would be great.

Regards,
S.Suresh Stephen
 
Old 02-11-2010, 01:59 PM   #5
axisofevil
LQ Newbie
 
Registered: Feb 2010
Posts: 14

Rep: Reputation: 0
I had same problem although I was trying to run valgrind on a target embedded system, not my workstation. Fix below..

I had installed it on my target by doing configure --prefix=[ path to nfs-mounted root fs ].

I ran strace on the target for valgrind - it basically told me valgrind was attempting to start memcheck in [ path to nfs-mounted root fs ]/lib/valgrind - no such place on the target. So I symlinked [ path to nfs-mounted root fs ]/lib to /lib on my target, and it at least started to run. Now the fun starts.
 
Old 02-11-2010, 02:21 PM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
I use valgrind for my bigger projects!
 
Old 02-11-2010, 02:49 PM   #7
cyent
Member
 
Registered: Aug 2001
Location: ChristChurch New Zealand
Distribution: Ubuntu
Posts: 374

Original Poster
Rep: Reputation: 83
Quote:
Originally Posted by stephenwalter View Post
Hello,
I too have a query about valgrind .I have tried to fix memory leaks using valgrind and it works fine , but sometimes i find that it is very slow and my application is a client server based one. The version of valgrind iam using is 2.4.0 and the 'C'code is built using gcc compiler version 4.0.0 . It seems that whenever i run valgrind my cpu usage goes to 100% and some times i have to close all other applications that iam running and just run valgrind other wise my application does not run successfully under valgrind. Iam not sure whether this is caused due to an inefficiency in my program or is this how valgrind works !!!!!
Look at it this way.

When you run a program without valgrind the CPU executes each instruction directly.

When you run it under valgrind, valgrind interprets each instruction by running a little routine for each instruction that in addition to the work done by each instruction checks the memory it accesses. If you have leak check on every time you allocate memory it also stores the backtrace for that point. ie. Quite a bit of overhead.

You can tell valgrind to store fewer levels of backtrace for leak checks... but that will make debugging a bit harder.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Valgrind and Shared Memory nodger Programming 0 04-27-2005 08:29 AM
Valgrind 2.2.0 works sridurai Linux - General 0 02-18-2005 06:51 AM
valgrind terminates unexpectedly appas Linux - General 0 02-18-2005 03:30 AM
valgrind reports un-free'd memory in crypt()? Xagafinelle Programming 3 08-21-2004 12:02 PM
answer lakshman Linux - General 1 09-21-2002 02:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration