Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to attach an existing buffer to a realgud debugger?

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.

More details about my environment

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:

  1. Edit my buffers and save them.
  2. Run 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.

like image 950
manu Avatar asked Oct 02 '22 17:10

manu


1 Answers

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.

like image 165
8 revs Avatar answered Oct 06 '22 00:10

8 revs