How to tell emacs gdb to show current code line in the center of buffer?

Using the debugger in emacs is nice: You can step through the code with the next command, and emacs will always show the code line that is currently executed, like this:

  int x;
  int y;
=>int z;

But unfortunately, if your file is long, that pointer => will eventually move to the bottom and always show the current line at the bottom of the buffer.

It would be nicer if the pointer => always stayed in the middle of the buffer (vertically centered), so that I can see what's coming up right after the current line, before I say next again, like here:

  int y;
=>int z;
  std::cout << z;

Is that possible? Can I set that somewhere?


There's no built-in mechanism to keep the line centered, however this advice does the trick for me:

(defadvice gud-display-line (after gud-display-line-centered activate)
  "Center the line in the window"
  (when (and gud-overlay-arrow-position gdb-source-window)
    (with-selected-window gdb-source-window
      ; (marker-buffer gud-overlay-arrow-position)
      (save-restriction
        (goto-line (ad-get-arg 1))
        (recenter)))))