Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

highlight current source line during debugging

35 views
Skip to first unread message

John Yates

unread,
Feb 4, 2013, 5:21:18 PM2/4/13
to help-gn...@gnu.org
When debugging I get a small triangular arrow in the left fringe.
Especially when stepping through disassembled machine instructions it
would be a big help to have the entire current line high lighted in
some fashion. Can anyone suggest a solution?

/john

(Not subscribed so please include my email address in any reply.)

John Yates

unread,
Feb 5, 2013, 9:56:38 AM2/5/13
to Stephen Berman, help-gn...@gnu.org
Hi Stephen,

Thanks for this suggestion. To implement it seems to require that one
know the name of the elisp function which places the overlay arrow. I
have been having a hard time figuring this out for gdb disassembly
buffers.

Performing cleanup based on an event in the buffer seems fragile.
Would it not be better to hook buffer destruction?

Finally, does this technique keep the line high lighted even when the
buffer is not selected? In a normal debugging session it is the
buffer with the gdb prompt that is selected most of the time.

/john

On Tue, Feb 5, 2013 at 4:11 AM, Stephen Berman <stephen...@gmx.net> wrote:
> On Mon, 4 Feb 2013 17:21:18 -0500 John Yates <jo...@yates-sheets.org> wrote:
>
>> When debugging I get a small triangular arrow in the left fringe.
>> Especially when stepping through disassembled machine instructions it
>> would be a big help to have the entire current line high lighted in
>> some fashion. Can anyone suggest a solution?
>
> A useful package for this is hl-line. How you use it might depend on
> what kind of program you are debugging and what debugger you are using.
> As an example, here's how you could get it for Emacs Lisp code using Edebug:
>
> (defadvice edebug-overlay-arrow (around highlight-line activate)
> "Highlight line currently being edebugged."
> (require 'hl-line)
> (hl-line-mode)
> ad-do-it)
>
> (defun my-edebug-quit ()
> "Stop edebugging and remove highlighting."
> (interactive)
> (hl-line-mode -1)
> (top-level))
>
> (define-key edebug-mode-map [remap top-level] 'my-edebug-quit)
>
> HTH
>
> Steve Berman

Sebastien Vauban

unread,
Feb 5, 2013, 10:16:04 AM2/5/13
to
Hi John and Stephen,

John Yates wrote:
> On Tue, Feb 5, 2013 at 4:11 AM, Stephen Berman <stephen...@gmx.net> wrote:
>> On Mon, 4 Feb 2013 17:21:18 -0500 John Yates <jo...@yates-sheets.org> wrote:
>>
>>> When debugging I get a small triangular arrow in the left fringe.
>>> Especially when stepping through disassembled machine instructions it
>>> would be a big help to have the entire current line high lighted in
>>> some fashion. Can anyone suggest a solution?
>>
>> A useful package for this is hl-line. How you use it might depend on
>> what kind of program you are debugging and what debugger you are using.
>> As an example, here's how you could get it for Emacs Lisp code using Edebug:
>>
>> (defadvice edebug-overlay-arrow (around highlight-line activate)
>> "Highlight line currently being edebugged."
>> (require 'hl-line)
>> (hl-line-mode)
>> ad-do-it)
>>
>> (defun my-edebug-quit ()
>> "Stop edebugging and remove highlighting."
>> (interactive)
>> (hl-line-mode -1)
>> (top-level))
>>
>> (define-key edebug-mode-map [remap top-level] 'my-edebug-quit)
>
> Thanks for this suggestion. To implement it seems to require that one
> know the name of the elisp function which places the overlay arrow. I
> have been having a hard time figuring this out for gdb disassembly
> buffers.
>
> Performing cleanup based on an event in the buffer seems fragile.
> Would it not be better to hook buffer destruction?
>
> Finally, does this technique keep the line high lighted even when the
> buffer is not selected? In a normal debugging session it is the
> buffer with the gdb prompt that is selected most of the time.

You could have a look at for another (?) solution (see last entry):

http://www.emacswiki.org/emacs/DebuggingWithEmacs

BTW, I've the same wish for EDebug. Don't know whether that code can be
adapted to serve so.

Best regards,
Seb

--
Sebastien Vauban

Stephen Berman

unread,
Feb 5, 2013, 5:11:31 AM2/5/13
to John Yates, help-gn...@gnu.org
On Mon, 4 Feb 2013 17:21:18 -0500 John Yates <jo...@yates-sheets.org> wrote:

> When debugging I get a small triangular arrow in the left fringe.
> Especially when stepping through disassembled machine instructions it
> would be a big help to have the entire current line high lighted in
> some fashion. Can anyone suggest a solution?

A useful package for this is hl-line. How you use it might depend on
what kind of program you are debugging and what debugger you are using.
As an example, here's how you could get it for Emacs Lisp code using Edebug:

(defadvice edebug-overlay-arrow (around highlight-line activate)
"Highlight line currently being edebugged."
(require 'hl-line)
(hl-line-mode)
ad-do-it)

(defun my-edebug-quit ()
"Stop edebugging and remove highlighting."
(interactive)
(hl-line-mode -1)
(top-level))

(define-key edebug-mode-map [remap top-level] 'my-edebug-quit)

HTH

Steve Berman

Stephen Berman

unread,
Feb 5, 2013, 5:36:04 PM2/5/13
to John Yates, help-gn...@gnu.org
On Tue, 5 Feb 2013 08:56:38 -0600 John Yates <jo...@yates-sheets.org> wrote:

> Thanks for this suggestion. To implement it seems to require that one
> know the name of the elisp function which places the overlay arrow. I
> have been having a hard time figuring this out for gdb disassembly
> buffers.

I'm not familiar with these, nor with the code for them, but glancing at
gdb-mi.el it looks like the overlay arrow is set in
gdb-disassembly-handler-custom, though I can't tell whether you can
advise this to get line highlighting. I also notice that gud.el appears
to provide support for hl-line (see gud-display-line), so maybe that can
be adapted to gdb disassembly buffers.

> Performing cleanup based on an event in the buffer seems fragile.

Do you mean the way I remapped top-level? This is just what is bound to
`q' in edebug-mode-map. When I'm debugging elisp code, I often quit
when I've found the bug, so this is a natural point to remove
highlighting. The code I posted doesn't remove highlighting when the
instrumented function returns, but the following does (this is rather
heavy-handed, but I can't think of a better way at the moment):

(defun my-edebug-finish ()
"Finish edebugging and remove highlighting."
(interactive)
(unless edebug-active
(hl-line-mode -1)))

(add-hook 'post-command-hook 'my-edebug-finish)

> Would it not be better to hook buffer destruction?

Well, if you kill the buffer you're debugging, that will automatically
end hl-line-mode, which is buffer-local, so in that case there's nothing
more to clean up. My approach provides highlighting only while
debugging, so when you're finished (or quit in the middle), you still
have the code buffer but no more highlighting.

> Finally, does this technique keep the line high lighted even when the
> buffer is not selected? In a normal debugging session it is the
> buffer with the gdb prompt that is selected most of the time.

The highlighting remains until removed by (hl-line-mode -1), even when
the buffer is not current.

Steve Berman

0 new messages