Open nthiery opened 7 years ago
This is very interesting idea. I like it. What is the expected behavior of trace
. Does it set invoke the debugger, set a breakpoint in max
and run the process?
On Sat, Aug 19, 2017 at 06:17:20AM -0700, Vassil Vassilev wrote:
This is very interesting idea. I like it.
:-)
What is the expected behavior of trace. Does it set invoke the debugger, set a breakpoint in max and run the process?
Yes, exactly.
By the way, I should have provided a complete running example in
Python to draw the analogy from. Occasion for me to notice that
trace
is a SageMath specific shorthand for Python's pdb.run
.
Here is the example:
In [1]: def max(x,y):
...: if x>y: return x
...: return y
In [3]: import pdb
In [4]: pdb.run('max(3,4)')
> <string>(1)<module>()
(Pdb) w
/usr/lib/python2.7/bdb.py(400)run()
-> exec cmd in globals, locals
> <string>(1)<module>()
(Pdb) s
--Call--
> <ipython-input-1-5ea54c7318af>(1)max()
-> def max(x,y):
(Pdb) p x
3
(Pdb) p y
4
(Pdb) s
> <ipython-input-1-5ea54c7318af>(2)max()
-> if x>y: return x
(Pdb) w
/usr/lib/python2.7/bdb.py(400)run()
-> exec cmd in globals, locals
<string>(1)<module>()
> <ipython-input-1-5ea54c7318af>(2)max()
-> if x>y: return x
(Pdb) p x>y
False
(Pdb) s
> <ipython-input-1-5ea54c7318af>(3)max()
-> return y
(Pdb) s
--Return--
> <ipython-input-1-5ea54c7318af>(3)max()->4
-> return y
(Pdb) s
--Return--
> <string>(1)<module>()->None
(Pdb) s
> /usr/lib/python2.7/bdb.py(404)run()
-> self.quitting = 1
(Pdb) s
In [5]:
Thinking about it a bit more, here are potential cherries on the cake, by decreasing order or priority:
Integration in Jupyter (the above example works as is with the Python kernel)
Ability to jump into the debugger for postmorten introspection after an exception was raised and not caught (see pdb.post_mortem() in https://docs.python.org/2/library/pdb.html)
Triggering a launch of the debugger from within the code (see pdb.set_trace())
Cheers,
In particular for teaching purposes, it would be very neat to be able to launch a debugger (e.g. gdb) from cling, as can be done in other interpreted language. Taking Python/pdb as example, that could look like: