(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.
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.