Interactively tracing execution of a command¶
Evaluate Sage code using the interactive tracer and return the result. The string
codemust be a valid expression enclosed in quotes (no assignments - the result of the expression is returned). In the Sage notebook this just raises a NotImplementedException.
preparse- bool (default: True); if True, run expression through the Sage preparser.
REMARKS: This function is extremely powerful! For example, if you want to step through each line of execution of, e.g.,
sage: trace("factor(100)") # not tested
then at the (Pdb) prompt type
step), then press return over and over to step through every line of Python that is called in the course of the above computation. Type
?at any time for help on how to use the debugger (e.g.,
llists 11 lines around the current line;
btgives a back trace, etc.).
Setting a break point: If you have some code in a file and would like to drop into the debugger at a given point, put the following code at that point in the file:
import pdb; pdb.set_trace()
For an article on how to use the Python debugger, see http://www.onlamp.com/pub/a/python/2005/09/01/debugger.html