Using ipdb with emacs' gud without explicit breakpoints in code
Asked Answered
T

1

14

I'm using python.el If I choose 'debugger' from the menu, and enter 'python -m pdb myfile.py', gud starts, and in a split frame I see the (Pdb) prompt in one, and my python code in the other with a caret on the first line, indicating that it's ready to go. For example 'n' steps to the next line and the caret moves accordingly.

If instead I enter 'python -m ipdb myfile.py', the frame splits, and one split is labeled gud, but there's no ipdb console evident. In other words, this way of starting ipdb doesn't seem to work. Ipdb works just fine if I manually insert a breakpoint into my python code using ipdb.set_trace(), except that it does not use the gud interface. Is this intentional so that ipdb's stack trace will work nicely?

If so, that's fine, but is there a way to start ipdb from emacs without manually adding a set_trace() command?

Traherne answered 16/2, 2014 at 1:45 Comment(1)
It doesn't work just fine for me with ipdb.set_trace() -- it just hangs. What version of IPython and emacs are you using? Seems other people have the same problem: #29425825Corse
H
10

The basic problem here is that gud is looking for a (Pdb) prompt and ipdb doesn't prompt this way. There are three ways to fix this: fix ipdb to give a (Pdb) prompt, fix gud not to need to look for (Pdb) or (my favorite) use something else either on the gud side or on the ipdb side.

The problem with fixing up gud is that it is rather old and to my mind a bit creaky using global variables and not making use of Emacs Lisp data structures available other than lists and cons cells. A total rewrite of gud is called realgud, it is currently in MELPA and ELPA. And ipdb is supported.

The last option is to use something else, so let me suggest the Python trepan debugger which is already integrated into realgud (but not gud since I consider that a dead end). Although the backtraces it gives are not exactly like ipdb's, it does colorize them and the source code.

And recent versions of trepan3k backtraces will even show, on demand, you where in the line you are. So if you had say two calls of a function, like fib() it would distinguish which of the calls function was the one in progress.

Hyperesthesia answered 5/7, 2015 at 15:37 Comment(7)
It appears that trepan debugger is python 3 only. Is that correct?Traherne
It works on both python3 and python2, and actually statistics seem to show it is more used on python2. To install python2: pip install trepan. To install python3: pip install trepan3k.Hyperesthesia
Thanks ... I should have mentioned my reason for asking. The pypi link you posted starts with the words "GDB-like Python3 Debugger in the Trepan family" and I couldn't find any definitive statement beyond that.Traherne
@Traherne thanks for letting me know. In the next trepan for python2 release, this will be fixed.Hyperesthesia
I just landed on this answer searching for an ipdb-based debugger in Emacs. Thanks for the info Rocky. I see you are also the developer/maintainer of realgud. It looks great! Is ipdb still not supported? What's exactly missing to have realgud support ipdb?Calorie
There is a pull request for ipdb support from sean farley. Because right now manual intervention needs to happen from the Melpa folks when we add or remove debugger I will be batching this addition with the removal of some of the older debuggers: in fact, some of mine. And those will go into an external repo. I need however to find some time to be able to do this.Hyperesthesia
This is working for me with ipdb on Emacs 26.1 and realgud 1.4.5. I can also verify that ipdb does not work with GUD as of Emacs 26.1.Currish

© 2022 - 2024 — McMap. All rights reserved.