Font Size

Cpanel

Debugging with Valgrind

Valgrind is a very good memory checker and debugger. It does the job by emulating the CPU and all of the instructions your program makes. Valgrind doesn't require specialized instrumentation or other tricks, but rather just requires that you compile your program with debugging information. If you want to debug OpenSceneGraph itself, just compile it with debugging information and link it in. The best part is that valgrind is itself Open Source. There is, however, a drawback. Your application, when run with the debugger, will be very slow.

It is recommended that valgrind 3.0.1 or later be used with OSG applications. I have only used valgrind under the GNU/Linux operating system on the x86 platform with Nvidia graphics cards, using Nvidia's proprietary driver. Valgrind has been used successfully with GCC 3.4.2 under Fedora Core 3, and with GCC 4.0.1 under Fedora Core 4. Other modern versions of GNU/Linux should work equally well.

Valgrind exposes many unfixable problems in the Nvidia graphics driver when running OSG applications. Valgrind also allows these errors to be suppressed by describing them in a separate suppression file, reproduced below. I called this file opengl.supp. Here is the command line that I use to run OSG applications with valgrind (<progname> and <progargs> are your own program name and arguments):

 valgrind --gen-suppressions=all --leak-check=full --num-callers=40 --log-file=out --suppressions=opengl.supp --error-limit=no -v <progname> <progargs>

Here are the contents of opengl.supp:

{
   opengl addr4 (1)
   Memcheck:Addr4
   obj:/usr/lib/libGL*
}
{
   opengl param (2)
   Memcheck:Param
   ioctl(generic)
   fun:ioctl
   fun:_nv*gl
   obj:/usr/lib/libGL*
}
{
   opengl cond (3)
   Memcheck:Cond
   obj:/usr/lib/libGL*
}
{
   opengl param (4)
   Memcheck:Param
   ioctl(generic)
   fun:ioctl
   obj:/usr/lib/libGL*
}
{
   opengl cond (5)
   Memcheck:Cond
   fun:_nv*gl
   obj:/usr/lib/libGL*
}
{
   opengl cond (6)
   Memcheck:Cond
   fun:strcat
   obj:/usr/lib/libGL*
}
{
   opengl value4 (7)
   Memcheck:Value4
   obj:/usr/lib/libGL*
}
{
   opengl memleak (8)
   Memcheck:Leak
   fun:calloc
   obj:/usr/lib/libGL*
}
{
   opengl memleak (9)
   Memcheck:Leak
   fun:malloc
   obj:/usr/lib/libGL*
}