6

I'm using emacs 23.1.1 with gdb and gdb-many-windows.

My question is if it's possible to force gdb to always use the main source window for stepping through the code. What happens is that as I move through stack frames, if I happen to have the source file up in another emacs frames, emacs brings that frame to the foreground while leaving the gud frame in the background with keyboard focus.

What I'd like to do is to force emacs/gdb to use the primary source window for all tracing even if there is another frame with the same source file laying around somewhere.

Any ideas?

Yung
  • 61
  • 1
  • on debian with emacs 24.4.1, this still happens to me. FWIW, i found a bug report, but without (yet) any patch: http://lists.gnu.org/archive/html/bug-gnu-emacs/2014-06/msg00097.html – pestophagous Oct 18 '15 at 23:44

2 Answers2

4

My emacs version is 24.3. So I am not really sure whether the following advice will solve your problem:

(defadvice gud-display-line (before one-source-window activate)
  "Always use the same window to show source code."
  (let ((buf (get-file-buffer true-file)))
    (when (and buf gdb-source-window)
      (set-window-buffer gdb-source-window buf))))

I found gud-display-line with the arg true-file in the old source there: http://www.mit.edu/~mkgray/stuff/ath/afs/oldfiles/project/silk/root/afs/athena.mit.edu/contrib/xemacs/OldFiles/share/xemacs-packages/lisp/debug/gdb.el

Furthermore, gdb-source-window can be found in a discussion about 23.1: https://groups.google.com/forum/#!topic/gnu.emacs.bug/KS6bhNeJ9rc

Therefore, it looks like the things I used should be available in 23.1.

To avoid splitting of the window you can try this one:

(defadvice gud-display-line (around one-source-window activate)
  "Always use the same window to show source code."
  (let ((buf (get-file-buffer true-file)))
    (when (and buf gdb-source-window)
      (set-window-buffer gdb-source-window buf)))
  (let (split-width-threshold split-width-threshold)
    ad-do-it
    ))
Tobias
  • 5,038
  • 1
  • 18
  • 39
  • It works only on the first new one, if GDB open an other source file it splits the main window. – Mario Giovinazzo Jul 03 '14 at 17:26
  • 1
    Let's see whether gud splits sensibly. Could you try to set `split-height-threshold` and `split-width-threshold` to `nil`? – Tobias Jul 03 '14 at 17:35
  • 2
    @MarioGiovinazzo I have added a variant where I set `split-width-threshold` and `split-width-threshold` temporarily to nil to prevent the splitting of the main window. Please try. – Tobias Jul 04 '14 at 16:22
  • I found that the defadvice might fix some annoyances with gdb-many-windows and gud loading source files into gdb windows (like comint buffer instead of the mid-left source window). However, it doesn't seem to be reliable, I can still trigger this problem. I suspect its the same bug as here with frames. I wrote down my observations here http://nurpax.github.io/posts/2014-10-12-fixing-gdb-many-windows-source-buffer.html. – Nurpax Oct 12 '14 at 21:42
  • 1
    @Nurpax See http://stackoverflow.com/questions/20226626/emacs-gdb-always-display-source-in-specific-window-with-gdb-many-windows – OLL Apr 10 '15 at 08:17
1

Update for more recent versions of emacs based on Tobias' advice (tested on emacs 27):


  (defun my-set-source-window (wrapped true-file line)
   "Always use the same window to show source code."
   (let ((buf (get-file-buffer true-file)))
     (when (and buf gdb-source-window)
      (set-window-buffer gdb-source-window buf)))
   (let (split-width-threshold split-width-threshold)
    (apply wrapped (list true-file line))))

  (advice-add 'gud-display-line :around #'my-set-source-window)

mzc
  • 3,265
  • 1
  • 20
  • 25