Author Topic: Valgrind plugin  (Read 40209 times)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5234
Valgrind plugin
« on: August 12, 2007, 08:57:04 pm »
I started the development of a little Valgrind plug-in. At this very moment it is very basic (hey, 2 months ago I didn't even know what Valgrind is).
Attached are the sources and project files for the plug-in. Since Valgrind is only for linux, this is a linux only plug-in. I provide the sources, no binary. Unzip in the plug-ins contrib dir of the CB source tree. It will activate in your CB devel build. If you want it in your output dir or with autotools adjust your update script and top level makefiles accordingly.

Requirements to run it :
 - you must be working on an 'executable' project
 - it must have as such an executable target
 - that target should have the -g compiler option [this is no checked yet, so make sure it is]
 - have Valgrind installed
 - have kcachegrind installed (to view to cachegrind output)

So when you have such a project/target active and you have built it (say the Debug build -> -g option), then select from the Plugins menu : Valgrind, and Valgrind will run your project/target executable and will create a 2 new panes in the Messages panel and dump it's output in there.

Current limitations :
 - currently only for the memcheck/cachegrind tool
 - only tested on some simple apps (console apps)

Attached is also a small test example, where you can see the Valgrind plug-in at work


Future tasks :
- check on the -g option
 - try with xml output --> better parsing and hopefully click to offending line

 - Provide more click to line (next to offending line, this can give information on where something was allocated)
 - configurable : where is the valgrind exe [now your linux system has to be able to find it itself]
 - configurable : which tool, so other things next to memcheck
 - configurable : able to select/specify the options to valgrind tools
 - one day try it on CB itself .........



[attachment deleted by admin]
« Last Edit: July 13, 2008, 06:08:51 pm by killerbot »

Offline JGM

  • Lives here!
  • ****
  • Posts: 518
  • Got to practice :)
Re: Valgrind plugin
« Reply #1 on: April 17, 2008, 01:21:10 am »
Cool, I have been bothering you with instant messages and here is the source  :lol: thanksss!!!!

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5234
Re: Valgrind plugin
« Reply #2 on: July 09, 2008, 08:50:48 pm »
the plug-in has been updated and is now available as a contrib plug-in in CB.

So see Cb svn for latest source, or if you want to build it.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5234
Re: Valgrind plugin
« Reply #3 on: July 09, 2008, 08:54:41 pm »
create a console application and give main.cpp the following content (so you can try the plug-in) :
Code: [Select]
#include <iostream>

using namespace std;

int main()
{
// let's go for a memory leak
int* ArrayI = new int[10];
ArrayI[0] = 0;
// read out of bounds
cout << ArrayI[12] << endl;

//write out of bounds
ArrayI[10] = 15;

// uninitialized variable
int UnInitVar;
if(UnInitVar)
{
cout << "Hello" << endl;;
}

// mismatch new[] delete
char* MyString = new char[10];
delete MyString;

// double delete
int* pInt = new int;
delete pInt;
delete pInt;

// double alloc to same variable --> first one lost
int* First = new int;
First = new int;
delete First;
First = 0;

return 0;
} // end of main

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Valgrind plugin
« Reply #4 on: July 09, 2008, 10:36:03 pm »
The entry for the valgrind-plugin libs is missing frome "debian/codeblocks-contrib.install".

Patch:
Code: [Select]
--- codeblocks-1.0svn.orig/debian/codeblocks-contrib.install    2008-07-09 21:11:39.000000000 +0200
+++ codeblocks-1.0svn.work/debian/codeblocks-contrib.install    2008-07-09 22:25:02.000000000 +0200
@@ -39,6 +39,7 @@
 usr/share/codeblocks/plugins/libRegExTestbed.*
 usr/share/codeblocks/plugins/libSymTab.*
 usr/share/codeblocks/plugins/libThreadSearch.*
+usr/share/codeblocks/plugins/libValgrind.*
 usr/share/codeblocks/plugins/libwxsmith.*
 usr/share/codeblocks/plugins/libwxsmithcontribitems.*


Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5234
Re: Valgrind plugin
« Reply #5 on: July 10, 2008, 07:38:58 am »
done

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Valgrind plugin
« Reply #6 on: July 13, 2008, 08:14:21 pm »
If I try to disable the plugin C::B crashes with a segfault without showing the crash-report window.

Nevertheless the crash-report gets written into /tmp directory.
I attach it. It seems to crash in "PluginsConfigurationDlg::OnToggle(...)".

It only happens with Valgrind, egally if I remove it alone, as first or as last plugin.

And there is no "Valgrind"-entry in "default.conf" under "<plugins>".


[attachment deleted by admin]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5234
Re: Valgrind plugin
« Reply #7 on: July 14, 2008, 01:14:53 pm »
And there is no "Valgrind"-entry in "default.conf" under "<plugins>".

That's ok, since it does not have settings.

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Valgrind plugin
« Reply #8 on: July 14, 2008, 01:22:25 pm »
And there is no "Valgrind"-entry in "default.conf" under "<plugins>".

That's ok, since it does not have settings.

I meant the entry wher I can find the disabled and enabled status, but I see now that all (installed) plugins are enabled by default and the entry only occurs if a plugins status has toggled at least once.
And that could not happen for Valgrind because of the crash.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9594
Re: Valgrind plugin
« Reply #9 on: July 14, 2008, 02:31:51 pm »
I meant the entry wher I can find the disabled and enabled status [...]
And that could not happen for Valgrind because of the crash.
Probably due to the crash this setting was not saved. I had the same issue with the svnInside plugin. I disabled the plugin to avoid crashes on exit of C::B. But these settings were always lost until I really removed this plugin.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Valgrind plugin
« Reply #10 on: July 14, 2008, 03:03:16 pm »
I meant the entry wher I can find the disabled and enabled status [...]
And that could not happen for Valgrind because of the crash.
Probably due to the crash this setting was not saved. I had the same issue with the svnInside plugin. I disabled the plugin to avoid crashes on exit of C::B. But these settings were always lost until I really removed this plugin.

Afaik the "real" writing is done when C::B closes correctly. If C::B crashes all changes to default.conf are lost.

I can manually disable Valgrind-plugin, if I edit default.conf and set the value for "VALGRIND" to "0".
If I have done this, I can enable Valgrind-plugin from inside  C::B, but if I try to redisable it, the crash occurs again.

There is another issue, when I try to check a program on a

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5234
Re: Valgrind plugin
« Reply #11 on: July 14, 2008, 03:33:09 pm »
some part of your last post got lost ...

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Valgrind plugin
« Reply #12 on: July 14, 2008, 03:54:31 pm »
some part of your last post got lost ...

There is another issue, when I try to check a program on a

here it should continue:

But, the error is not related to what I thought before (so I can't continue my sentence from above).

Nevertheless it still occurs:

I have a workspace that includes a program and a shared library.
The output directory of the shared library is the same as the one of the program.
If I debug, the debuggerplugin sets the "LD_LIBRARY_PATH" correctly, but the Valgrind-plugin seems not to set it, and so valgrind does not find the library.
The error is not in the "Valgrind messages" list-logger, it's only (more or less hidden) in the xml-output.
The parent-element of the error-message is "<valgrindoutput>". I think, that might be the cause that it is not shown in the list-logger.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5234
Re: Valgrind plugin
« Reply #13 on: July 14, 2008, 03:57:59 pm »
the valgrind plug-in is currently very simple, I have tested it on simple applications.
Basically it is just calling valgrind with some parameters, one of those parameters is the name of the application valgrind is ordered to check.

Could you attach valgrind plugin log output.

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Valgrind plugin
« Reply #14 on: July 14, 2008, 04:07:54 pm »
Here it is.

It seems to be an error message of my executable (or better from linux), not from Valgrind.

[attachment deleted by admin]

Offline Der Meister

  • Regular
  • ***
  • Posts: 307
Re: Valgrind plugin
« Reply #15 on: July 14, 2008, 06:14:33 pm »
There is a missing #include in Valgrind.cpp:
Code: [Select]
Index: src/plugins/contrib/Valgrind/Valgrind.cpp
===================================================================
--- src/plugins/contrib/Valgrind/Valgrind.cpp (revision 5126)
+++ src/plugins/contrib/Valgrind/Valgrind.cpp (working copy)
@@ -13,6 +13,7 @@
 #include <wx/fs_zip.h>
 #include <wx/intl.h>
 #include <wx/string.h>
+#include <wx/menu.h>
 #include <wx/xrc/xmlres.h>
 #include "cbproject.h"
 #include "manager.h"
Without this compilation failes with wxGTK 2.8.
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand.
Real Programmers don't write in BASIC. Actually, no programmers write in BASIC, after the age of 12.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5234
Re: Valgrind plugin
« Reply #16 on: July 15, 2008, 09:37:57 am »
Here it is.

It seems to be an error message of my executable (or better from linux), not from Valgrind.

and this shows the thing I was afraid of :-(, program output and valgrind xml get mixed

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5234
Re: Valgrind plugin
« Reply #17 on: July 15, 2008, 10:07:20 am »
There is a missing #include in Valgrind.cpp:
Code: [Select]
Index: src/plugins/contrib/Valgrind/Valgrind.cpp
===================================================================
--- src/plugins/contrib/Valgrind/Valgrind.cpp (revision 5126)
+++ src/plugins/contrib/Valgrind/Valgrind.cpp (working copy)
@@ -13,6 +13,7 @@
 #include <wx/fs_zip.h>
 #include <wx/intl.h>
 #include <wx/string.h>
+#include <wx/menu.h>
 #include <wx/xrc/xmlres.h>
 #include "cbproject.h"
 #include "manager.h"
Without this compilation failes with wxGTK 2.8.

done : thanks !!

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Valgrind plugin
« Reply #18 on: July 15, 2008, 10:45:25 am »
Here it is.

It seems to be an error message of my executable (or better from linux), not from Valgrind.

and this shows the thing I was afraid of :-(, program output and valgrind xml get mixed

I can not test it at the moment, but it might be an error output using the error-stream.
In this case it should be possible to filter it.

Offline elfunesto

  • Single posting newcomer
  • *
  • Posts: 5
Re: Valgrind plugin
« Reply #19 on: July 03, 2009, 02:29:52 pm »
Sorry,
Were can I download the plugin: it seems that it has been deleted by the administrator.
Thanks by advance. Cheers,
Hilaire

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Valgrind plugin
« Reply #20 on: July 03, 2009, 02:53:14 pm »
Sorry,
Were can I download the plugin: it seems that it has been deleted by the administrator.
Thanks by advance. Cheers,
Hilaire
The valgrind plugin is part of the contrib-plugins and therefore included in the sources and nightlies since svn r5113 (2008-07-09).

Offline elfunesto

  • Single posting newcomer
  • *
  • Posts: 5
Re: Valgrind plugin
« Reply #21 on: July 03, 2009, 03:06:58 pm »
Thanks for your quick answer!
Hilaire

Offline AndiDog

  • Single posting newcomer
  • *
  • Posts: 6
Re: Valgrind plugin
« Reply #22 on: July 04, 2009, 01:48:35 pm »
I just downloaded the recent C::B nightly build for Windows and couldn't find the Valgrind plugin.

A search in the forum didn't give me any hints, and neither did I find it on http://svn.berlios.de/svnroot/repos/codeblocks/trunk/src/plugins/, http://valgrind.org/ or the Wiki. Really a lack of information here :wink: Anway, I'm sure that I've seen the Valgrind plugin on a recent CodeBlocks installation on Linux, though.

Where can I get that plugin for Windows??

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Valgrind plugin
« Reply #23 on: July 04, 2009, 01:53:10 pm »
Read this: http://valgrind.org/info/platforms.html and you will understand.

Offline kfmfe04

  • Multiple posting newcomer
  • *
  • Posts: 27
Re: Valgrind plugin
« Reply #24 on: July 13, 2009, 06:11:26 am »
What is the status of this Valgrind plugin?

I would like to try it on an Ubuntu/Amd64 set-up (never used Valgrind before) for profiling, mostly, but I don't want the attempt to turn into a massive time-sink...

Has anyone tried it recently?  What works?  What doesn't?
Thanks in advance.

- Ken
(BTW, I am running 8.02, Build: Jul 24 2008, 15:20:21, and I can't seem to find the plug-in under Plug-Ins... > Manage Plugins.)

Quote
The valgrind plugin is part of the contrib-plugins and therefore included in the sources and nightlies since svn r5113 (2008-07-09).
« Last Edit: July 13, 2009, 06:17:09 am by kfmfe04 »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6896
    • My Best Post
Re: Valgrind plugin
« Reply #25 on: July 13, 2009, 07:19:12 am »
What is the status of this Valgrind plugin?

I would like to try it on an Ubuntu/Amd64 set-up (never used Valgrind before) for profiling, mostly, but I don't want the attempt to turn into a massive time-sink...

Has anyone tried it recently?  What works?  What doesn't?
Thanks in advance.

- Ken
(BTW, I am running 8.02, Build: Jul 24 2008, 15:20:21, and I can't seem to find the plug-in under Plug-Ins... > Manage Plugins.)

Quote
The valgrind plugin is part of the contrib-plugins and therefore included in the sources and nightlies since svn r5113 (2008-07-09).

Feb 2008 (8.02) is before July 2008 that is why you do not see the plugin.

Tim S
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline yakumoklesk

  • Multiple posting newcomer
  • *
  • Posts: 34
Re: Valgrind plugin
« Reply #26 on: October 20, 2009, 06:51:41 pm »
I posted this in a wrong thread, so I put it here and the solution I found:


I am trying to run valgrind plugin, but it says that it needs to specify a XML file.

I have the valgrind version:

Code: [Select]
valgrind-3.5.0-Debian,

that needs the parameter

Code: [Select]
--xml-file=<file>         XML output to <file>
Is there any place where I can specify it?

Thanks in advance.

Workaround

Ok. I needed to find an older version. I did the following after installing apt-show-versions:

Code: [Select]
apt-show-versions -a valgrind
valgrind 1:3.5.0-2 install ok installed
valgrind 1:3.3.1-3 lenny   http.us.debian.org
valgrind 1:3.5.0-2 testing http.us.debian.org
valgrind 1:3.5.0-2 sid     ftp.de.debian.org
valgrind/testing uptodate 1:3.5.0-2

Then downgrade:

Code: [Select]
sudo apt-get install valgrind=1:3.3.1-3
This is just in case other people may have the same problem that me.

Now it launches.

Offline yakumoklesk

  • Multiple posting newcomer
  • *
  • Posts: 34
Re: Valgrind plugin
« Reply #27 on: October 20, 2009, 07:07:11 pm »
But it does nothing... The application is run, then I close it. Then nothing.

What is next?

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5234
Re: Valgrind plugin
« Reply #28 on: October 20, 2009, 09:50:44 pm »
It is well possible that it might not correctly run with valgrind 3.5, since a few things have changed in valgrind.
Currently I am still at 3.2.3 and 3.3.0.
And there i have been using it in august/september and it still worked ;-)

In a few weeks i will be at valgrind 3.5.0, I will look into the issues at that time. Unless people can already give hints on what is going wrong.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12597
    • Travis build status
Re: Valgrind plugin
« Reply #29 on: October 20, 2009, 10:16:39 pm »
You need to pass -xml-fd=0 or 2 (stdout or stderr) to make it happy
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline DrPatrock

  • Single posting newcomer
  • *
  • Posts: 4
Re: Valgrind plugin
« Reply #30 on: November 27, 2009, 12:34:35 pm »
Hello,

I'm using Codeblocks together with CMake (Unix Makefile Generator). With these external Makefiles there are no compiler options per target. In the Makefiles i have the -g option enabled but when i try to start valgrind, it complains about the  missing -g option... Is there a workaround for this problem ?? Where does valgrind look for this option ?

THX & Greets
Patrock

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5234
Re: Valgrind plugin
« Reply #31 on: November 27, 2009, 06:12:40 pm »
It looks at the codeblocks project, at the actual target (.cbp file). It doesn't work with external makefiles.

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Valgrind plugin
« Reply #32 on: November 27, 2009, 07:39:09 pm »
There is a workaround:

uncheck the "This is a custom makefile" check-box in the projects properties,
close the properties dialog (don't use the build-options button at the bottom),
open the build-options,
check the "Produce debugging symbols" checkbox in the "compiler flags" tab,
switch back to the properties,
check "This is a custom makefile" again.

Works for me here.

Offline DrPatrock

  • Single posting newcomer
  • *
  • Posts: 4
Re: Valgrind plugin
« Reply #33 on: December 02, 2009, 11:32:29 am »
thanks Jens...

It's working for me too now...


Offline Dikei

  • Single posting newcomer
  • *
  • Posts: 2
Re: Valgrind plugin
« Reply #34 on: January 01, 2010, 04:59:25 am »
Quote
valgrind --version
valgrind-3.5.0-Debian
valgrind --leak-check=yes --xml=yes "bin/Debug/Bai4"
==8013== --xml=yes has been specified, but there is no XML output
==8013== destination.  You must specify an XML output destination
==8013== using --xml-fd=, --xml-file= or --xml=socket=.
valgrind: Bad option '--xml=yes, but no XML destination specified'; aborting.
valgrind: Use --help for more information.

The Valgrind plugin keeps failing with the error message above.
I'm using codeblock svn 5911 on Ubuntu 9.10

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5234
Re: Valgrind plugin
« Reply #35 on: January 01, 2010, 09:22:33 am »
Thanks for reporting, I will fix this. It seems the new Valgrind wants an xml file to be specified.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5234
Re: Valgrind plugin
« Reply #36 on: January 01, 2010, 12:56:19 pm »
alright I know what to do.

Off course the fun is i will have to check valgrind versions since the changes valgrind has are not backwards compatible.

Old command :
Code: [Select]
valgrind --leak-check=yes --xml=yes ./DeleteMe
New command :
Code: [Select]
valgrind --leak-check=yes --xml=yes --xml-file=test.xml ./DeleteMe
Unfortunately the option 'xml-file=test.xml' will be flagged as an error by the old valgrind (valgrind: Bad option '--xml-file=test.xml'; aborting.).

Will start working on it soon.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12597
    • Travis build status
Re: Valgrind plugin
« Reply #37 on: January 01, 2010, 09:56:31 pm »
Why not use:
Code: [Select]
valgrind --leak-check=yes --xml=yes --xml-fd=1 ./test_cb_stl_debug

 --xml-fd=1 -> should mean use file that is the standard output
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5234
Re: Valgrind plugin
« Reply #38 on: January 01, 2010, 10:57:41 pm »
could work too, yes.
But the special version check logic will be needed, since also this will cause an error on pre 3.5.0 versions of valgrind.

But I think, putting it in a real file will be better, that way regular program output on stdout can not mix with the xml output parts.

Have already coded the change, test session should be carried out tomorrow.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12597
    • Travis build status
Re: Valgrind plugin
« Reply #39 on: May 06, 2010, 04:32:58 am »
C::B project - debugger branch:

Valgrind -> Run Valgrind::MemCheck says:
"You need to have an (executable) target in your open project before using the plugin!"

I've tried  targets: "All" and "src"
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Sqeaky

  • Single posting newcomer
  • *
  • Posts: 8
Re: Valgrind plugin
« Reply #40 on: December 19, 2010, 11:39:40 pm »
Quote
There is a workaround:

uncheck the "This is a custom makefile" check-box in the projects properties,
close the properties dialog (don't use the build-options button at the bottom),
open the build-options,
check the "Produce debugging symbols" checkbox in the "compiler flags" tab,
switch back to the properties,
check "This is a custom makefile" again.

Works for me here.

I have a project that uses cmake to create Makefiles, and this did not work for me. Where is the source for for the valgrind plugin? I bet I could make it skip this check if a custom makefile is used.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12597
    • Travis build status
Re: Valgrind plugin
« Reply #41 on: December 20, 2010, 01:39:43 am »
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Sqeaky

  • Single posting newcomer
  • *
  • Posts: 8
Re: Valgrind plugin
« Reply #42 on: December 22, 2010, 06:43:37 pm »
Thanks I am checking it out now.


Edit, I got the the source for it, and I will dig in in the next few days, it doesn't seem like this plugin is really a high priority for anyone else (because it seems to work most of the time) , so I will take my time.
« Last Edit: December 22, 2010, 07:11:39 pm by Sqeaky »