自定义Emacs GDB

时间:2010-10-05 00:00:22

标签: configuration emacs gdb

我喜欢使用GDB和emacs。我最喜欢使用“gdb-many-windows”获得的配置,如下所示:

gdb-many-windows

那就是说,它并不完美。我想添加一个框架来显示当前正在运行的线程。有谁知道是否可以自定义“gdb-many-windows”给你的配置?或者,如果我不能这样做,他们是否可以在我的.emacs中自动出现gdb后创建自己的帧?我理想的设置将包含线程,堆栈跟踪,局部变量和一个大的源窗口。

2 个答案:

答案 0 :(得分:9)

gdb-many-windows使用的窗口布局显然是在gdb-setup-windows中实现的。您可以建议该功能在设置窗口时执行其他操作,例如

(defadvice gdb-setup-windows (around setup-more-gdb-windows activate)
  ad-do-it
  (split-window-horizontally)
  (other-window 1)
  (gdb-set-window-buffer
    (gdb-get-buffer-create 'gdb-some-buffer-type)))

答案 1 :(得分:4)

这是一个非常古老的帖子,但是以下解决方案可以帮助某人。

以下代码捕获gdb接口的开始和退出,改变其行为。

在gdb start(defadvice gdb)中,它首先保存当前布局,然后运行gdb并最终准备一个新的自定义布局(根据您的喜好很容易编辑它)

在gdb exit(defadvice gdb-reset),它首先执行原始退出函数,然后重新加载保存的布局。

结果包含gdb-many-windows的同一窗口,当前运行的线程位于图像的右上角

enter image description here

(setq gdb-many-windows nil)

(defun set-gdb-layout(&optional c-buffer)
  (if (not c-buffer)
      (setq c-buffer (window-buffer (selected-window)))) ;; save current buffer

  ;; from http://stackoverflow.com/q/39762833/846686
  (set-window-dedicated-p (selected-window) nil) ;; unset dedicate state if needed
  (switch-to-buffer gud-comint-buffer)
  (delete-other-windows) ;; clean all

  (let* (
         (w-source (selected-window)) ;; left top
         (w-gdb (split-window w-source nil 'right)) ;; right bottom
         (w-locals (split-window w-gdb nil 'above)) ;; right middle bottom
         (w-stack (split-window w-locals nil 'above)) ;; right middle top
         (w-breakpoints (split-window w-stack nil 'above)) ;; right top
         (w-io (split-window w-source (floor(* 0.9 (window-body-height)))
                             'below)) ;; left bottom
         )
    (set-window-buffer w-io (gdb-get-buffer-create 'gdb-inferior-io))
    (set-window-dedicated-p w-io t)
    (set-window-buffer w-breakpoints (gdb-get-buffer-create 'gdb-breakpoints-buffer))
    (set-window-dedicated-p w-breakpoints t)
    (set-window-buffer w-locals (gdb-get-buffer-create 'gdb-locals-buffer))
    (set-window-dedicated-p w-locals t)
    (set-window-buffer w-stack (gdb-get-buffer-create 'gdb-stack-buffer))
    (set-window-dedicated-p w-stack t)

    (set-window-buffer w-gdb gud-comint-buffer)

    (select-window w-source)
    (set-window-buffer w-source c-buffer)
    ))
(defadvice gdb (around args activate)
  "Change the way to gdb works."
  (setq global-config-editing (current-window-configuration)) ;; to restore: (set-window-configuration c-editing)
  (let (
        (c-buffer (window-buffer (selected-window))) ;; save current buffer
        )
    ad-do-it
    (set-gdb-layout c-buffer))
  )
(defadvice gdb-reset (around args activate)
  "Change the way to gdb exit."
  ad-do-it
  (set-window-configuration global-config-editing))