Author Topic: Valgrind plugin  (Read 49566 times)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
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: 5490
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: 5490
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
#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 Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
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
--- 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: 5490
Re: Valgrind plugin
« Reply #5 on: July 10, 2008, 07:38:58 am »
done

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
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: 5490
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 Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
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: 9694
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: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
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: 5490
Re: Valgrind plugin
« Reply #11 on: July 14, 2008, 03:33:09 pm »
some part of your last post got lost ...

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
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: 5490
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 Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
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]