vgvassilev / cling

The interactive C++ interpreter Cling
https://rawgit.com/vgvassilev/cling/master/www/index.html
Other
1.77k stars 100 forks source link

Launching a debogger within cling #158

Open nthiery opened 7 years ago

nthiery commented 7 years ago

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:

cling>int max(int x, int y) {
               if x > y return x;
               return y;
         }
cling> trace('max(3,4)')
... in function max ....
cling-gdb>  p x
3
cling-gdb>  s
vgvassilev commented 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?

nthiery commented 7 years ago

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:

Cheers,