7
votes

I love using GDB withing emacs. And I most like the configuration that I get with "gdb-many-windows", as seen here:

gdb-many-windows

That said, it's not perfect. I'd like to add a frame for showing the currently running threads. Does anyone know if it's possible to customize the configuration that "gdb-many-windows" gives you? Or, if I can't do that, is their a way to create my own frames AFTER gdb comes up automatically in my .emacs? My ideal setup would have threads, stack trace, local variables and a big source window.

2

2 Answers

9
votes

The window layout used by gdb-many-windows is apparently implemented in gdb-setup-windows. You can advise that function to do additional work in setting up windows, like

(defadvice gdb-setup-windows (around setup-more-gdb-windows activate)
  ad-do-it
  (split-window-horizontally)
  (other-window 1)
  (gdb-set-window-buffer
    (gdb-get-buffer-create 'gdb-some-buffer-type)))
6
votes

It is a very old post, however the follow solution can help someone.

The follow code capture the start and the exit of the gdb interface, changing its behavior.

At gdb start (defadvice gdb), it first save the current layout, then run the gdb and finaly prepare a new custom layout (it easy to edit it for your preferences)

At gdb exit (defadvice gdb-reset), it first execute the original exit function and then reload the saved layout.

The result contains the same window of the gdb-many-windows, the current running thread are in the top-right of the image

enter image description here

(setq gdb-many-windows nil)

(defun set-gdb-layout(&optional c-buffer)
  (if (not c-buffer)
      (setq c-buffer (window-buffer (selected-window)))) ;; save current buffer

  ;; from http://stackoverflow.com/q/39762833/846686
  (set-window-dedicated-p (selected-window) nil) ;; unset dedicate state if needed
  (switch-to-buffer gud-comint-buffer)
  (delete-other-windows) ;; clean all

  (let* (
         (w-source (selected-window)) ;; left top
         (w-gdb (split-window w-source nil 'right)) ;; right bottom
         (w-locals (split-window w-gdb nil 'above)) ;; right middle bottom
         (w-stack (split-window w-locals nil 'above)) ;; right middle top
         (w-breakpoints (split-window w-stack nil 'above)) ;; right top
         (w-io (split-window w-source (floor(* 0.9 (window-body-height)))
                             'below)) ;; left bottom
         )
    (set-window-buffer w-io (gdb-get-buffer-create 'gdb-inferior-io))
    (set-window-dedicated-p w-io t)
    (set-window-buffer w-breakpoints (gdb-get-buffer-create 'gdb-breakpoints-buffer))
    (set-window-dedicated-p w-breakpoints t)
    (set-window-buffer w-locals (gdb-get-buffer-create 'gdb-locals-buffer))
    (set-window-dedicated-p w-locals t)
    (set-window-buffer w-stack (gdb-get-buffer-create 'gdb-stack-buffer))
    (set-window-dedicated-p w-stack t)

    (set-window-buffer w-gdb gud-comint-buffer)

    (select-window w-source)
    (set-window-buffer w-source c-buffer)
    ))
(defadvice gdb (around args activate)
  "Change the way to gdb works."
  (setq global-config-editing (current-window-configuration)) ;; to restore: (set-window-configuration c-editing)
  (let (
        (c-buffer (window-buffer (selected-window))) ;; save current buffer
        )
    ad-do-it
    (set-gdb-layout c-buffer))
  )
(defadvice gdb-reset (around args activate)
  "Change the way to gdb exit."
  ad-do-it
  (set-window-configuration global-config-editing))