From SambaWiki
Revision as of 20:06, 30 April 2009 by JelmerVernooij (talk | contribs) (add some debugging notes)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Debugging Python code


A commonly used trick is to import the Python debugger at some point where you would like to do debugging. Just add something like this:

{{{ import pdb pdb.set_trace() }}}

and Python will drop into the Python debugger, allowing you to inspect variables, execute code, step into/next/continue, etc. The commands are pretty similar to those of gdb.

Debugging Python extensions


As Python extensions are written in C, it is usually not sufficient to rely on pdb when debugging extensions.


The following gdb macros (to be placed in ~/.gdbinit) allow you to easily inspect the reference count of python objects, their string representation as used in Python and the python stack from within gdb.


There is a suppressions file for Python's memory manager (pymalloc). It is part of the Python source tree, and distributed inside of the Python package in some distributions (Debian/Ubuntu put it in the "python" package, in /usr/lib/valgrind/python.supp). With this suppressions file enabled you *should* have no valgrind warnings from Python with any of the Samba modules loaded. See also /usr/share/doc/python2.4/README.valgrind for a more detailed explanation.

Example usage:

{{{ valgrind --suppressions=/usr/lib/valgrind/python.supp python }}}