Using gdb in emacs, gdb shows the source code to the right of the gdb prompt.

According to the documentation, I can do M-x gdb-display-locals-buffer which displays the local variables. However, when I do that, the locals buffer replaces the source buffer. Is there a way for to tell gdb to open the locals buffer somewhere else? So that it doesn't overwrite the source buffer?

Thanks in advance!

PS: Bonus question, what is the difference between gdb and gud-gdb? Can I get the locals buffer using gud?

1 Answer 1


If you want to customize your default GDB window layout, you can do the following :

  1. Enter GDB mode manually, and craft your layout using the regular window-* commands and the gdb-display-* commands.

  2. Invoke gdb-save-window-configuration to save it to a file.

  3. Set it as your default layout :

(setq gdb-many-windows t)
(setq gdb-default-window-configuration-file "/path/to/file")

If you want to keep the default layout and be able to quickly pull up the GDB locals buffer, you can write your own command like so :

(defun gdb-add-locals-buffer ()
  "Display the GDB locals buffer."

I tested this with the interactive GDB buffer on the left-hand side, and the source buffer on the right-hand side. It worked, but it is not reliable. You can also use gdb-load-window-configuration to manually load a premade configuration.

Your Answer

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

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