Emacs / GDB:总是在gdb-many-windows的特定窗口中显示源代码 [英] Emacs/GDB: always display source in specific window with gdb-many-windows

查看:210
本文介绍了Emacs / GDB:总是在gdb-many-windows的特定窗口中显示源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Emacs 24中使用GDB,其中 gdb-many-windows 设置为 t ,通常在自己的框架。我喜欢有一个单独的编辑框架。看起来像这样(对于粗略的ASCII图表,道歉):

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 |
+-------------+-------------+

除了一个大问题,这个功能很好。每当gdb需要显示不同的源缓冲区时,例如在up / down / step之后,它不总是在源窗口中显示。例如,如果我在不同的框架中的窗口中打开相同的缓冲区,那么它会引发该框架,同时保持键盘聚焦在gdb框架中。当框架相互覆盖时,这是一个非常烦人的单监视器设置。

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.

我希望gdb始终使用源窗口在gdb-many-windows设置中显示源代码,无论在其他地方显示相同的源缓冲区。如何做到这一点?

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?

编辑:我正在使用Emacs 24.2.1与GDB 7.5-ubuntu。我在Ubuntu 10.04和Linux Mint Nadia with Cinnamon上看到这个问题。

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.


  • 评估这个表达式:(setq gdb-many-windows t)

  • 使用至少两个文件编译C程序。

例如:

// 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




  • 让bar.c显示在主框架中。用 M-x 5 2 打开一个新的框架。在该框架中,使用 M-x gdb 启动gdb。该框架应该有六个窗口,如上所示。将gdb框架放在源框架的顶部。

  • main 中设置断点,并逐步调用 foo bar 。当调用 bar 时,主框架将在gdb框架上升高,因为bar.c已经可见,但是键盘焦点将停留在gdb框架中。 >

    • Let bar.c be displayed in the main frame. Open a new frame with M-x 5 2. In that frame, start gdb with M-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 to foo and bar. When bar 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.
    • 我认为问题功能是gud.el中的 gdb-display-source-buffer 。广州。我打算尝试用 defadvice 覆盖它,但我不太熟悉建议。如果我想出来,我会在这里发布一个答案。

      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.

      推荐答案

      我有24.3。而且我无法重现此版本的问题。
      gud-display-line 如下所示:

      I have 24.3. And I cannot reproduce the problem with this version. There gud-display-line looks as follows:

      (defun gud-display-line (true-file line)
        (let* ((last-nonmenu-event t)  ; Prevent use of dialog box for questions.
           (buffer
            (with-current-buffer gud-comint-buffer
              (gud-find-file true-file)))
           (window (and buffer
                    (or (get-buffer-window buffer)
                    (display-buffer buffer))))
           (pos))
          (when buffer
            (with-current-buffer buffer
          (unless (or (verify-visited-file-modtime buffer) gud-keep-buffer)
            (if (yes-or-no-p
                 (format "File %s changed on disk.  Reread from disk? "
                     (buffer-name)))
                (revert-buffer t t)
              (setq gud-keep-buffer t)))
          (save-restriction
            (widen)
            (goto-char (point-min))
            (forward-line (1- line))
            (setq pos (point))
            (or gud-overlay-arrow-position
                (setq gud-overlay-arrow-position (make-marker)))
            (set-marker gud-overlay-arrow-position (point) (current-buffer))
            ;; If they turned on hl-line, move the hl-line highlight to
            ;; the arrow's line.
            (when (featurep 'hl-line)
              (cond
               (global-hl-line-mode
                (global-hl-line-highlight))
               ((and hl-line-mode hl-line-sticky-flag)
                (hl-line-highlight)))))
          (cond ((or (< pos (point-min)) (> pos (point-max)))
                 (widen)
                 (goto-char pos))))
            (when window
          (set-window-point window gud-overlay-arrow-position)
          (if (eq gud-minor-mode 'gdbmi)
              (setq gdb-source-window window))))))
      

      窗口设置与您完全不同。或许你应该升级到新的gud / gdb的东西。

      The window setting is completely different from yours. Maybe, the above code is helpful or maybe you should upgrade to the new gud/gdb stuff.

      这篇关于Emacs / GDB:总是在gdb-many-windows的特定窗口中显示源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆