0

below are my set up for launching gdb in Emacs.

(defun debug-gdb-advanced ()
  (interactive)
  (delete-other-windows)         ; close all other panes
  (split-window-horizontally)    ; split pane left right
  (other-window 1)               ; switch to right pane
  (split-window-vertically)      ; split pane top down
  (debug-gdb)                    ; open
  (set-window-dedicated-p (selected-window) t) ; anchor the gdb window, never let it switch buffer
  (other-window 2)               ; switch to left pane
  (gdb-display-stack-buffer)     ; open stack buffer
  (other-window 1))              ; switch to gdb pane

but I also want to run the following after gdb has initialized

(defun closeUnnecessaryBuffers ()
  (interactive)
  (setq kill-buffer-query-functions nil)
  (kill-buffer (shell "*breakpoints of *"))
  (kill-buffer (shell "*threads of *"))
  (kill-buffer (shell "input/output of*")))

is there a way to fold the second function into the first one without mannually waiting gdb fully initialized.

  • (1st) The global (setq kill-buffer-query-functions nil). is rather drastic in a function that just closes some buffers. Maybe, you should use (let (kill-buffer-query-functions) ...close the buffers you want...) instead. It restrics the nil-binding of kill-buffer-query-functions to the body of the let-form. (2nd) (shell "*breakpoints of *") looks very strange to me. Maybe, you actually want something like (let ((buf (get-buffer "*breakpoints of *")) (when buf (kill-buffer buf)) instead. – Tobias May 2 '19 at 7:32
1

The hook variable gdb-mode-hook is probably what you are looking for.

Citation from the GUD-manual

On startup, GUD runs one of the following hooks: gdb-mode-hook, if you are using GDB; dbx-mode-hook, if you are using DBX; sdb-mode-hook, if you are using SDB; xdb-mode-hook, if you are using XDB; guiler-mode-hook for Guile REPL debugging; perldb-mode-hook, for Perl debugging mode; pdb-mode-hook, for PDB; jdb-mode-hook, for JDB. See Hooks.

Maybe, it should be added that (run-hooks 'gdb-mode-hook) is the last action in gdb.

You can add the function closeUnnecessaryBuffers to the hook variable in the following way:

(add-hook 'gdb-mode-hook #'closeUnnecessaryBuffers)

Note that you can avoid opening many windows for gdb by switching gdb-many-windows off. You can do that via M-x customize-option gdb-many-windows. You do not get rid of the additional buffers like "* breakpoints of *" by that. I am not sure whether those buffers are essential for gdb and whether you shouldn't kill them.

| improve this answer | |
  • These buffers actually shouldn't be closed, otherwise gdb doesn't function properly. My intention is to speed up gdb-mi by closing these buffers (the code base I'm working on is huge, gdb-mi can be very sluggish sometimes). classic gdb without many windows is fast and smooth, but it does not provide the perks like clickable stack frames. – Dennis May 2 '19 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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