First page Back Continue Last page Overview Graphics
Valgrind
Rewrites program on the fly adding debugging code and monitoring.
Can spot reads from unitialised memory
- And then dump you in a debugger.
Spots memory leaks
Many other things as well.
But: x86 only
- Some false positives - but often buggy libraries!
Notes:
Valgrind is smart - it is by the author of bzip2 - and an ex-Manchester Uni postgrad.
It emulates your entire program (in an efficient way); but adds code to spot things that go wrong.
Compile the last example, badread: gcc badread.c -g -o badread
From the source we can see two errors; it reads a flag variable without initialising it and allocates memory and forgets about it.
Valgrind ./badread
Shows lots of errors about reads from unitialised memory from around the printf and a backtrace to show where it was called from.
Valgrind --leak-check=yes shows the unfreed malloc; and where the malloc was made from.