Using the Debugger¶
The Cython debugger comes with a set of commands that support breakpoints,
stack inspection, source code listing, stepping, stepping over, etc. Most
of these commands are analogous to their respective gdb command.
cy break breakpoints...
Break in a Python, Cython or C function. First it will look for a Cython
function with that name, if cygdb doesn’t know about a function (or method)
with that name, it will set a (pending) C breakpoint. The -p option can
be used to specify a Python breakpoint.
Breakpoints can be set for either the function or method name, or they can
be fully “qualified”, which means that the entire “path” to a function is
given:
(gdb) cy break cython_function_or_method
(gdb) cy break packagename.cython_module.cython_function
(gdb) cy break packagename.cython_module.ClassName.cython_method
(gdb) cy break c_function
You can also break on Cython line numbers:
(gdb) cy break :14
(gdb) cy break cython_module:14
(gdb) cy break packagename.cython_module:14
Python breakpoints currently support names of the module (not the entire
package path) and the function or method:
(gdb) cy break -p python_module.python_function_or_method
(gdb) cy break -p python_function_or_method
Note
Python breakpoints only work in Python builds where the Python frame
information can be read from the debugger. To ensure this, use a
Python debug build or a non-stripped build compiled with debug
support.
cy step
Step through Python, Cython or C code. Python, Cython and C functions
called directly from Cython code are considered relevant and will be
stepped into.
cy next
Step over Python, Cython or C code.
cy run
Run the program. The default interpreter is the interpreter that was used
to build your extensions with, or the interpreter cygdb is run with
in case the “don’t import debug information” option was in effect.
The interpreter can be overridden using gdb’s file command.
cy cont
Continue the program.
cy up
cy down
Go up and down the stack to what is considered a relevant frame.
cy finish
Execute until an upward relevant frame is met or something halts
execution.
cy bt
cy backtrace
Print a traceback of all frames considered relevant. The -a option
makes it print the full traceback (all C frames).
cy select
Select a stack frame by number as listed by cy backtrace. This
command is introduced because cy backtrace prints a reversed stack
trace, so frame numbers differ from gdb’s bt.
cy print varname
Print a local or global Cython, Python or C variable (depending on the
context). Variables may also be dereferenced:
(gdb) cy print x
x = 1
(gdb) cy print *x
*x = (PyObject) {
_ob_next = 0x93efd8,
_ob_prev = 0x93ef88,
ob_refcnt = 65,
ob_type = 0x83a3e0
}
cy set cython_variable = value
Set a Cython variable on the Cython stack to value.
cy list
List the source code surrounding the current line.
cy locals
cy globals
Print all the local and global variables and their values.
cy import FILE...
Import debug information from files given as arguments. The easiest way to
import debug information is to use the cygdb command line tool.
cy exec code
Execute code in the current Python or Cython frame. This works like
Python’s interactive interpreter.
For Python frames it uses the globals and locals from the Python frame,
for Cython frames it uses the dict of globals used on the Cython module
and a new dict filled with the local Cython variables.
Note
cy exec modifies state and executes code in the debuggee and is
therefore potentially dangerous.
Example:
(gdb) cy exec x + 1
2
(gdb) cy exec import sys; print sys.version_info
(2, 6, 5, 'final', 0)
(gdb) cy exec
>global foo
>
>foo = 'something'
>end