I use GDB in Emacs 24 with gdb-many-windows
set to t
, usually in its own frame. I like to have a separate editing frame. It looks like this (apologies for my crude ASCII diagram):
+-------------+-------------+
| gdb | locals |
+-------------+-------------+
| source | I/O |
| | |
+-------------+-------------+
| stack | breakpoints |
+-------------+-------------+
This works pretty well except for one big problem. Whenever gdb needs to display a different source buffer, e.g., after up/down/step, it doesn't always show it in the "source" window. For example, if I have the same buffer open in a window in a different frame, it will raise that frame while keeping keyboard focus in the gdb frame. This is really annoying on a single-monitor setup when the frames cover each other.
I'd like gdb to always use the source window in the gdb-many-windows setup to display source, no matter if the same source buffer is displayed elsewhere. How can I do that?
EDIT: More detailed instructions to reproduce. I'm using Emacs 24.2.1 with GDB 7.5-ubuntu. I've seen this problem on Ubuntu 10.04 and Linux Mint Nadia with Cinnamon.
- Evaluate this expression:
(setq gdb-many-windows t)
- Compile a C program with at least two files.
For example:
// foo.c
void bar(int);
void foo(int c) {
if (c > 0)
bar(c - 1);
}
int main(void) {
foo(100);
return 0;
}
// bar.c
void foo(int c);
void bar(int c) {
if (c > 0)
foo(c - 2);
}
// compile with gcc -g -O0 foo.c bar.c -o test
- Let bar.c be displayed in the main frame. Open a new frame with
M-x 5 2
. In that frame, start gdb withM-x gdb
. There should be six windows in that frame as shown above. Position the gdb frame on top of the source frame. - Set a breakpoint in
main
and step through calls tofoo
andbar
. Whenbar
is called, the main frame will be raised over the gdb frame since bar.c is already visible there, but keyboard focus will stay in the gdb frame.
I think the problem function is gdb-display-source-buffer
in gud.el.gz. I'm planning to try overriding this with defadvice
, but I'm not really familiar with advice. If I figure it out, I'll post an answer here.
emacs -q
to detect potential problems with your configuration. Also try to provide a minimal example. I.e., small source files and step-by-step instructions to reproduce the problem. – Poverty