More Valgrind

Contents | Up | Prev | Next

# 6.1. More Valgrind

- Valgrind does not require special compilation. You simply execute it like so: `valgrind --num-callers=15 progname`. It will run the program `progname` and intercept calls to malloc/free/new/delete and monitor all memory uses.
- Another useful flag is `--gdb-attach=yes` that invokes gdb on the process when errors are detected, and let you debug the place of the error.
- Valgrind is works only on x86s running a modern Linux version.
- Valgrind will report several types of errors:
  - Illegal read / illegal write errors.
  - Use of uninitialized values.
  - Illegal frees.
  - Inappropriate deallocation function.
  - Passing system call paramters with inadequate read/write permissions.
- Valgrind will tell you, when possible, where in your code the relevant memory blocks were allocated/freed.
- Valgrind is most probably not installed on the Linux box you are working on, however installation is trivial and fairly quick: download, unpack and then run one after another:
  `./configure`
  `make`
  `make install`
- Valgrind's manual is available in the directory of its unpacked distribution under `docs/index.html`.

Contents | Up | Prev | Next