I use (setq gdb-many-windows t)
and (setq gdb-show-main t)
configurations in my init.el
, so after executing M-x gdb
, there will be six windows in the frame, after typing q
in the main gdb cli window to finish debugging, how can I quit/delete all the gdb related windows/buffers (including the current gdb CLI, locals, breakpoints, stack frames...) and just leave the source code buffer open at the same time.
Asked
Active
Viewed 816 times
2

CodyChan
- 2,599
- 1
- 19
- 33
1 Answers
2
After googling around and tweaking the code snippets from the internet, I got this solution and it works as expected:
(defvar all-gud-modes
'(gud-mode comint-mode gdb-locals-mode gdb-frames-mode gdb-breakpoints-mode)
"A list of modes when using gdb")
(defun kill-all-gud-buffers ()
"Kill all gud buffers including Debugger, Locals, Frames, Breakpoints.
Do this after `q` in Debugger buffer."
(interactive)
(save-excursion
(let ((count 0))
(dolist (buffer (buffer-list))
(set-buffer buffer)
(when (member major-mode all-gud-modes)
(setq count (1+ count))
(kill-buffer buffer)
(delete-other-windows))) ;; fix the remaining two windows issue
(message "Killed %i buffer(s)." count))))
You can bind the kill-all-gud-buffers
to a key or defalias
it to a short name or even change the function name so you can type it easily.

CodyChan
- 2,599
- 1
- 19
- 33
-
In realgud, the situation is both more complicated and simpler. There can be many debug sessions going on. But the command buffer for a single debug session has a list of the source code buffers associated with it. If you want to write the corresponding function for realgud, you would use field srcbuf-list of the buffer-local variable realgud-cmdbuf-info, I'd consider adding this to the code base. – rocky Jun 29 '15 at 16:06