I am using GUD for debugging C code. Because many of the lines and variables have been optimized away, it is necessary to follow the C source and the corresponding disassembly simultaneously. I want the current line in the disassembler window to be highlighted each time I "step instruction." Right now the cursor moves automatically, in the disassembler window, but hl-line-mode does not highlight the line that the cursor moved to. If I switch to that window, the new line gets highlighted, and remains highlighted when I move away from that window again. But each time I step, the highlighting from hl-line-mode disappears in the inactive window.

How can I get a good visual indication of the "current line" in the disassembler window? The tiny triangle in the fringe is not enough, because the lines are quite long, and it is difficult to tell at a glance which instruction will be executed next.

  • Wherever you see gud-overlay-arrow-position (make-marker) ... set-marker, you can put something after that location using (marker-position gud-overlay-arrow-position) as the point at which to update hl-line-mode or other gizmo that suits your needs. I see two (2) locations in the version I am using: gud-display-line and gdb-frame-handler. However, I have limited experience using gdb and am unfamiliar with terms such as disassembler and step instruction ... Therefore, I am unable to write up an answer because I cannot test it myself.
    – lawlist
    Oct 16 '18 at 18:33
  • Thanks, @lawlist. I tried this and found out that the gud-overlay-arrow-position is different from the gdb-disassembly-position overlay. Interestingly the gud-display-line function already has special handling for hl-line-mode, so regular source buffers already work as expected with hl-line-mode, even when the source buffer is not the active window. (re-reading this comment right after typing it, I realize that it might be more confusing than anything.)
    – nispio
    Oct 16 '18 at 21:57

Thanks to @lawlist nudging me into the source code, I found out that gdb mode will highlight the line for me, but only on the condition that the window containing the disassembly does not have fringes. The following was enough to make that happen:

;; Enable automatic highlighting of the active line in disassembly window
(defun nispio/disable-window-fringes () (set-window-fringes nil 0 0))
(add-hook 'gdb-disassembly-mode-hook #'nispio/disable-window-fringes)

Because I usually pop the disassembly window out into a separate frame, this is okay. Otherwise, it would disable the fringes on some semi-arbitrary window.


This is the solution I came up with using hl-line. I needed to advise the function that updates the disassembly buffer and invoke hl-line-highlight directly to make it work.

(defadvice gdb-disassembly-handler-custom
    (after nispio/ad-after-disas-handler-hl-line activate)
  "Make sure that `hl-line' gets updated after updating disassembly buffer"
  (let* ((buffer (gdb-get-buffer 'gdb-disassembly-buffer))
         (window (get-buffer-window buffer 0)))
    (when (and window (featurep 'hl-line))
      (with-current-buffer buffer
          (goto-char gdb-disassembly-position)
         ((and hl-line-mode hl-line-sticky-flag)
          (goto-char gdb-disassembly-position)

(add-hook 'gdb-disassembly-mode-hook #'hl-line-mode)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.