[IPython-dev] Patches to use pydb instead of pdb for debugging

R. Bernstein rocky at panix.com
Sun Oct 8 00:11:44 CDT 2006


I was not have been clear on what I was hoping to do.

Let's say I'm inside the debugger and I want to get the equivalent
information for a local object "a" that I would get were I in the
shell with that variable defined and were I to type "a?".

And let's forget about how to handle the syntax of ? or ??. So let's
add a new debugger command called "pinfo". All it wants to do is call
Magic.magic_pinfo(), but somehow set up the local and global
namespaces correctly. One could add to Debugger.py the following
method which sort of works, but really isn't right. It hackily
modifies one of the dictionaries that gets used via Magic.magic_pinfo.

    def do_pinfo(self, arg):
        """Sort of The debugger equivalant of obj? for a local variable"""
        # Find a dictionary to smack before the call. We'll use the
        # alias table.
        old_ns = __IPYTHON__.shell.alias_table   # save
        __IPYTHON__.shell.alias_table = self.curframe.f_locals  # smack
        __IPYTHON__.magic_pinfo("pinfo %s" % arg)
        __IPYTHON__.shell.alias_table = old_ns   # restore

Possibly the alias table shouldn't be wiped out -- I don't know
possibly it is irrelevant in this context anyway. And the alias table
is searched last whereas local variables are searched first by Python.

Instead I think one would like a variant of Magic._ofind which has a
notion of a local and global name spaces separate from the shell's
namespace and some way for a debugger to hook in the current
local/global namespaces to that. (Could the global namespace replace
user_ns of the shell? Maybe, I don't know.)

Note that such a routine as do_pinfo really has nothing to do with
pydb at all. Short of finding incidental misfeatures in pdb (or pydb
as I've been finding) which prevent this, to first approximation it
should work equally well in both. Or any debugger; or any user
application called from the ipython shell that want's to interact with
ipython for that matter.

- - - 

As a related but separate problem, now that I've go a way to invoke
the debugger in full generaltity from ipython I'd also like to be able
run such a "pinfo" command from that.  By virtue of starting inside
ipython I have all of the ipython routines around. In particular I
have __IPYTHON__ defined. So moving that same do_pinfo routine from
Debugger.py into someplace inside pydb's code would roughly do the
same thing. But again, that code is really fairly wrong for the same
reasons.


Ville M. Vainio writes:
 > On 10/6/06, R. Bernstein <rocky at panix.com> wrote:
 > 
 > > ??object here). This could either be done inside pydb code, but maybe
 > > it would be neater to do inside ipython since it looks like there are
 > > routines already for decorating debugger commands. Suggestions on
 > > where to look to hook into '?' and '??'?
 > 
 > Now they are handled by "handle_help" in iplib.py, but you should
 > create an input_prefilter hook function that catches the ? commands
 > and translates them to something you want, e.g. ??foo ->
 > _pydb.detailedhelpcommand("foo"). see ext_rescapture.py on how to
 > implement one.
 > 
 > -- 
 > Ville M. Vainio - vivainio.googlepages.com
 > blog=360.yahoo.com/villevainio - g[mail | talk]='vivainio'
 > 


More information about the IPython-dev mailing list