I just discovered Valgrind, it's about time.

By Ylian Saint-hilaire (Intel) (246 posts) on March 9, 2010 at 12:37 pm

Most of my coding career at Intel was been spend using C#, but with the mesh project, we needed to build the background peer-to-peer agent as small and as portable as possible and coding it in C made sense. Well, anything you code in raw C code, there are plenty of opportunities for problems. I have noticed that the mesh agent was not always stable and twice in the last month I saw it cause a segmentation fault. On Windows, the mesh agent runs as a service and the service manager is setup so it can restart the agent if anything goes wrong, but that only mask the problem.

Last week, I started looking at Valgrind more aggressively. Valgrind is an open source code checking tool. You just compile the code leaving in all of the debugging symbols and run "valgrind x" when x is your executable. In my case I run:

valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes --track-origins=yes x

Where the last x is the executable. It runs the code with additional instrumentation and prints out problems as they happen. For example: If you start using a pointer that is not valid at the given time, or try jumping on an un-initialized value, etc. A quick look at the error logs revealed that I had indeed some problems. Two small ones and a really big one that likely caused my segmentation fault. An hour later and my code was running without causing valgrind to show any errors. So far, the code is running flawlessly. I am still running the mesh agent in Valgrind on my Linux machine in case something happens. My guess is, I am going to take the habit of always using Valgrind on some of my machines when running the mesh agent.

All in all, after running Visual Studio Static Code Analysts, Klocworks and Valgrind, I am feeling pretty happy about this code. I would not have gotten it this stable without all of these tools.

Ylian
opentools.homeip.net

Categories: Open Source
Tags: , , ,

For more complete information about compiler optimizations, see our Optimization Notice.

Comments (1)

April 8, 2010 10:35 AM PDT

Roman Dementiev (Intel)
Roman Dementiev (Intel)Total Points:
2,205
Brown Belt
you can also try Intel(r) Parallel Inspector tool for memory checking: http://software.intel.com/en-us/intel-parallel-studio-home/

Trackbacks (1)


Leave a comment  

To obtain technical support, please go to Software Support.
Name (required)*

Email (required; will not be displayed on this page)*

Your URL (optional)


Comment*