Using GDB/GUD within Emacs

As an emacs user i try to fit all my activities within Emacs. This works perfectly well when programming but show some imperfections when debugging programs under Emacs.

The default settings of GUD are not well defined. This applies particularly to projects with numerous source files. GUD will jump between different buffers to show those source-files even if you step through your code. The respective layout is completely destroyed here and it’s hard to follow some focus in here.

The following function will restore a destroyed layout, it’s not a perfect solution but it will work for me.

(defun my-debug-layout ()
  (interactive)
  (if (fboundp 'project-debug-layout)
      (project-debug-layout)
    (gdb-restore-windows)
    (split-window-right)
    (gdb-display-disassembly-buffer)
    (windmove-down)
    (split-window-right)
    (gdb-display-io-buffer)
    (windmove-up)
    (balance-windows)
    (end-of-buffer)
    (message "Default layout")))

So i can reset the layout quickly using the F8 key:

(global-set-key (kbd "<f8>") 'my-debug-layout)

While debugging buffers get still destroyed but using F8 you can easily restore those.