I'm starting to use realgud
in GNU Emacs 24.3.1 as an alternative to GUD. (Mainly because when I set break points with vanilla pdb it does not honor it.)
I'm starting the OpenERP web server with pdb bin/start_openerp
and it opens the main script. But I need to be able to place breakpoints in the buffers I'm working on.
I need to how can I attach my buffers to the debugger.
For OpenERP developing I'm using buildout and the anybox recipe. This creates the bin/start_openerp
script that rewrites the sys.path
to match my buildout environment.
I'm developing several OpenERP's custom addons. So I'm editing some when I need to enter the debugger session to tackle a problem. I do the following:
pdb bin/start_openerp
. This opens the script with ShortKeys
minor mode active.If I execute the break file:lineno
command on the realgud buffer it works and breaks are respected. But I need to go to one of the buffers and with the point in some line, set the breakpoint there.
There is a conceptual problem that has to be overcome here.
But first, I need to define a couple of terms. A "command buffer" is where you see (Pdb)
and it has the Python process and debugger associated with it. A "source-code buffer" is an Emacs buffer with Python source code in it.
When you are debugging several Python sessions, there are several command buffers. It is possible that several command buffers refer to the same Python source code at some point in the course of where they had stopped in running the Python program. So from inside a buffer of Python source code, how does one distinguish in which of several Python sessions you want the breakpoint to occur in?
When you are stopped in one of the sessions, the command buffer knows where you are. It arranges to pull up the source-code buffer and associate itself with that source-code buffer. The source-code buffer stores which Python command buffer is associated with it. In an ideal world it would store all of the associated command buffers and associate fringe marks with the right debugger process, but right now it can only store one pointer to a command buffer.
The source-code buffer may also go into "shortkey mode". Here, And typing "b" on any line will set a breakpoint at that line in the Python process associated with that source-code buffer.
But suppose there are several sessions and you are in a source-code buffer and don't know which command buffer is associated with that? The Emacs command and function realgud:srcbuf-info-describe when run from inside the source buffer will display information about the source-code buffer including which command buffer is associated with it.
So one simple way to set up a source-code buffer associated with the right Python process is to set a breakpoint from the right command buffer, and then clear the breakpoint. The source-code buffer will be in short-key mode, and then you can type "b" on any line and that will go to the right Python session.
The Emacs realgud function realgud-srcbuf-init-or-update can be used to initialize any Python buffer with a command buffer, but note that this is not an interactive command. You need to have the command buffer object and a source-code buffer
Finally let me put in a plug for a pdb-like and more gdb-like debugger trepan2 for Python2 and trepan3k for Python3.
See emacs-dbgr/common/buffer/source.el for more information about source buffers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With