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?

garyp
  • 967
  • 7
  • 36
  • 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: http://stackoverflow.com/questions/29425325/using-ipdb-for-debugging-python-inside-emacs – Croad Langshan Aug 22 '15 at 15:59

1 Answers1

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.

rocky
  • 7,226
  • 3
  • 33
  • 74
  • It appears that trepan debugger is python 3 only. Is that correct? – garyp Oct 12 '15 at 13:06
  • 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`. – rocky Oct 12 '15 at 13:48
  • 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. – garyp Oct 12 '15 at 14:11
  • @garyp thanks for letting me know. In the next trepan for python2 release, this will be fixed. – rocky Oct 12 '15 at 14:15
  • 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`? – Amelio Vazquez-Reina Feb 17 '16 at 01:51
  • 2
    There is a [pull request for ipdb support](https://github.com/rocky/emacs-dbgr/pull/71) 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. – rocky Feb 18 '16 at 02:31
  • 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. – aparkerlue Jun 27 '18 at 18:56