2

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.

1 Answer 1

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.

1
  • 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, 2015 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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