From BlenderWiki

Jump to: navigation, search

Valgrind can be used to detect memory errors that a debugger such as gdb would not otherwise find.


[edit] Starting Blender

install valgrind on your system. (Linux only)

On ubuntu/debian

 sudo apt-get install valgrind

Now you can go to the place you built blender and type...

valgrind ./blender

This will run blender in valgrind and generate errors that you can use to find bugs before they crash blender or errors that may cause unpredictable behavior.

These options give more useful output but make blender run slower too.

valgrind --track-origins=yes  --error-limit=no ./blender

[edit] Error suppression

*Note*. setting suppressions is not necessary but if you run valgrind a lot you may want to set it up.

If you try running the command above you'll see meny errors, most of which are not useful. to address this you need to make a suppressions file.

touch ~/blender_sup.txt
valgrind --suppressions=~/blender_sup.txt --gen-suppressions=all ./blender 2> ~/blender_sup_TEMP.txt

The first time your run you'll get errors with python, ghost, X11 and OpenGL. For now assume they are not bugs. Open blender and do some basic operations. spin the view, open a simple file...

Now open ~/blender_sup_TEMP.txt, replace all '==' with '#==' in your text editor. Save the output into ~/blender_sup.txt (make sure there are no blender errors mixed in with the text)

Close blender and run again but dont redirect the output this time.

valgrind --suppressions=~/blender_sup.txt --gen-suppressions=all ./blender

The errors will now appier in the terminal and there shouldn't be too many, you can copy the errors to suppress into ~/blender_sup.txt by hand.

Some errors will keep appearing and you can ignore them.

  • Undo - blender compares un-initialized memory when running undo, you cant supress this from 1 place because undo is called in many areas.
  • Python - Python does its own memory management which confuses valgrind, and is also called in many places.

[edit] Compiler Considerations

A compiling with debug enabled is fine to start with. But when running valgrind for serious testing you'll want to make sure your compiler options are setup so valgrind works well.

Notes, Compile with no optimiztion -O0

Using -O2 and above are known to make valgrind report unimitialized memory incorrectly.

Use -fno-inline you dont have to but it helps valgrind produce more accurate and usable error reports.

When using scons you can do somthing like this...

scons BF_DEBUG_FLAGS="-O0 -g3 -ggdb3 -fno-inline"