Linux: Ode to valgrind

Everything todo with programming goes HERE.
Post Reply
User avatar
Z-Man
God & Project Admin
Posts: 11587
Joined: Sun Jan 23, 2005 6:01 pm
Location: Cologne
Contact:

Linux: Ode to valgrind

Post by Z-Man »

It works. End.

Well, it's a short ode. But I can't think of anything better to say about a tool.

For the uninformed: Valgrind is a powerful debugging tool. It runs your program inside a virtual machine where it has full control over what the program does. By default, it checks for all kinds of memory handling errors: read/writes to unallocated memory, double deallocation, memory leaks, and most amazingly, reads from allocated, but uninitialized memory.
User avatar
wrtlprnft
Reverse Outside Corner Grinder
Posts: 1679
Joined: Wed Jan 04, 2006 4:42 am
Location: 0x08048000
Contact:

Post by wrtlprnft »

sorry for digging out this old thread, but I tried it (mostly to check my own code), and out of frustration that it didn't find anything in my code I'll post this (CVS HEAD):

Code: Select all

==21111== Conditional jump or move depends on uninitialised value(s)
==21111==    at 0x81E4B73: tMemManager::tMemManager(int) (tMemManager.cpp:619)
==21111==    by 0x81E654A: __static_initialization_and_destruction_0(int, int) (tMemManager.cpp:964)
==21111==    by 0x81E72F9: _GLOBAL__I__Z4leakv (sstream.tcc:80)
==21111==    by 0x81EE7E4: (within /home/mathias/armagetronad/src/armagetronad_main)
==21111==    by 0x804EDA8: (within /home/mathias/armagetronad/src/armagetronad_main)
==21111==    by 0x81EE6DA: __libc_csu_init (in /home/mathias/armagetronad/src/armagetronad_main)
==21111==    by 0x4493081: (below main) (in /lib/libc-2.3.5.so)
Not sure exactly, but for reference, this is tMemManager.cpp:619:

Code: Select all

            if (cs>=0 && cs < MAXCHECKSUM && (ln < leaks[cs] || leaks[cs] == 0))
That might have something to do with the special nature of the memory manager, but the only time something writes to the leaks array is inside this if block...
There's no place like ::1
User avatar
Z-Man
God & Project Admin
Posts: 11587
Joined: Sun Jan 23, 2005 6:01 pm
Location: Cologne
Contact:

Post by Z-Man »

Two cascading memory managers give bad karma. Use either the internal one or valgrind, valgrind can't do its job fully when the internal manager is used.
But the warning is realy anyway and should be fixed now (in b0_2_8).
User avatar
Z-Man
God & Project Admin
Posts: 11587
Joined: Sun Jan 23, 2005 6:01 pm
Location: Cologne
Contact:

Post by Z-Man »

Valgrind is constantly cooler. Release 3.3 includes exp-omega, a memory checker that can report leaks as they happen, i.e. when the last pointer to a memory block gets assigned to point somewhere else. At the end, you'll get told where the block was allocated, and what bit of code lost it. Immensely useful.
Post Reply