Archive for August, 2010

Valgrind – Your Memory Assistant

Valgrind is a programmer tool that allows to track memory related errors in C and C++ programs. This tool helped me greatly when I was checking out potential memory leaks.

As we all know, it’s really difficult to ensure that your program don’t have any memory leak at all. A good coding practice always helps, but usually it’s infeasible to find all bugs by our eyes. So we need a tool to automatically find these bugs. Valgrind is such a tool and is very easy to use. Before using it, you could compile your program with -g to include debugging information and -O0 to disable compiler’s optimization. Doing these will let memcheck’s error messages include exact line numbers.

Then you just use:

valgrind --leak-check=yes myprog arg1 arg2

The result will be displayed and it will tell you where the potential memory leaks are. You could fix the bugs according to it. There are more options and you could check them out on man page.

For gnome applications building with glib, things are a little different since glib has it’s own memory management library. Here are some tips I stolen from  Gnome community:

G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=20 --log-file=vgdump your-program

and you could also use it for libtool program. Check this out to see how to do this.




Debug libtool program with gdb

libtool program is a shell script that can’t work with gdb.Here is an example:
$ ls -l check_ifnet
-rwxr-xr-x 1 gentoo gentoo 4269 Aug 18 20:46 check_ifnet
$file check_ifnet
check_ifnet: POSIX shell script text executable

For libtool programs, the shared libraries are put into .lib directory and that script sets up the running environment (See more information I find that many people manually copy the shared libraries for debugging purpose. That’s not quite convenient.

I have two ways to test these kind of programs with gdb:

  1. edit the program and change this line “exec “$progdir/$program” ${1+”$@”}” to “gdb “$progdir/$program” ${1+”$@”}”. Then run the program.
  2. libtool –mode=execute gdb your_program (This one is better)

, , ,


Gentoo NetworkManager Plug-in Final Report For GSoC


This is the last report for Gentoo NetworkManager plug-in during GSoC.

I’ll continue maintaining this project after GSoC and I’ll write new articles about the new life :).

I mentioned in last weekly report that I was going to merge our plug-in to NM upstream. Dan Williams gave me some great comments and I was working on them for the last two weeks. This includes code quality/format improvements, monitoring improvements, logic improvements and several bug fixes. Now all the problems are solved and we are agreed to merge our plug-in on Monday 23rd August.

Robert has helped me pushed the plug-in into portage and enabled it by default. We have got some great feedback. Right now, all the reported bugs were fixed and it’s looking good.

I want to maintain this project after GSoC and continue contributing myself to Gentoo community as a developer. Right now I’m working on Gentoo developer quiz.

This summer is really wonderful and thank Gentoo Community for giving such a great experience to me.

, ,

1 Comment

Pushing Gentoo NetworkManager Plug-in to upstream NetworkManager

Two weeks ago, I contacted Dan Williams who is the author of NetworkManager. We are talking about pushing our plug-in to upstream NetworkManager. Dan is really a kind guy and willing to accept our code. He made a long fix-up list and I’ve started working on them this week.

These requests would not only help make the code format compatible with NM’s, but also improve the quality of our plug-in. Thank Dan for his comments.

I’ll make all the necessary modification and I’m sure you will see it soon :-).

, ,