When using gdb -i=mi to debug a program, I typically split the window into two buffers vertically. But every time my program prints something gud automatically replaces my source code buffer with I/O buffer and pops up a new "frame" that contains my source code, and what's worse is that it creates a "dedicated window" that I can't switch back to source code. This behavior is obviously very very annoying, it should for example, open a new frame for the I/O buffer instead. How can I achieve that or just simply turn off auto replacing buffer for gud? (gud-gdb doesn't seem to have such behaviors but it doesn't show where breakpoints are)
2 Answers
The automatic pop-up of the i/o buffer can be disabled by setting gdb-display-io-nopopup
to t
. In your .emacs
file, add:
;; Prevent gdb from popping i/o window to the foreground on every output op
(setq-default gdb-display-io-nopopup t)
I learned this from ajp's answer here.
-
Can you add a snippet that should be added to the init file to make your answer easier to follow for novices?– user12563Commented May 2, 2019 at 19:29
-
That does work. How come none of us involved in this question didn't know that answer existed! Commented May 3, 2019 at 5:56
-
1
-
@MinghengWang: I wish I knew. I've been struggling with this problem for years before I stumbled on ajp's answer after the nth search. Commented May 10, 2019 at 18:41
A partial answer is to disable gud from making the windows "dedicated", so you can change their buffer. From https://www.emacswiki.org/emacs/GDB-MI:
;; Force gdb-mi to not dedicate any windows
(advice-add 'gdb-display-buffer
:around (lambda (orig-fun &rest r)
(let ((window (apply orig-fun r)))
(set-window-dedicated-p window nil)
window)))
(advice-add 'gdb-set-window-buffer
:around (lambda (orig-fun name &optional ignore-dedicated window)
(funcall orig-fun name ignore-dedicated window)
(set-window-dedicated-p window nil)))
t
, and I removed/replaced the ACTION argument fordisplay-buffer
withingud-display-line
tonil
. I'm sorry that I don't have a fancyadvice
and I realize that is blasphemy to modify the source code. I setgdb-display-buffer-other-frame-action
to my own custom function'(my-custom-function)
, but I'm presently not using that feature. I essentially wanted just two windows -- one window with the gdb debugger, and the other window gets the source-code.gdb-display-buffer
, I commented out(set-window-dedicated-p window t)
. Withingdb-set-window-buffer
, I commented out(set-window-dedicated-p window t)
. Then, I typed:M-x byte-compile-file
. You could also create new functions instead and use things likedefalias
to replace your new function, or you could justrequire
the source-code libraries in yourinit.el
or.emacs
before redefining the functions using the same name. I think the author liked having many windows and frames instead of just 2 windows on the selected frame.M-x eval-expression RET (display-images-p) RET
.