在emacs中使用gdb调试

我在emacs中使用gdb调试操作系统内核代码, 我重新组织了gdb many window的layout如下图:

我发现在stack frames(win4)和win6中的函数文件位置是完整的绝对路径,这占用了宝贵的窗口空间 我想能不能修改成相对于该工程根目录的路径, 想看看有大佬知道吗?谢谢!

C-h f gdb-frame-location

他对应的是stack-frames中的路径 这个函数很小 应该很容易改

你修改完这一个

另一个自动就好了

记得给解决方案

我给你个例子吧

但是他有个问题就是 如果使用library的话就会显示不全

这个问题留给你去解决吧

(defcustom gdb-frame-location-substring
  10
  "去掉文件的前几个字符")

(defun gdb-frame-location (frame)
  "Return \" of file:line\" or \" of library\" for structure FRAME.

FRAME must have either \"file\" and \"line\" members or \"from\"
member."
  (let ((file (bindat-get-field frame 'file))
        (line (bindat-get-field frame 'line))
        (from (bindat-get-field frame 'from)))
    (let ((res (or (and file line (concat file ":" line))
                   from)))
      (if res (concat " of " (substring res gdb-frame-location-substring)) ""))))

2 个赞

你是怎么重新组织窗口布局的?

c-h f gdb-setup-windows

你想要怎么样的布局 是八个窗口 还是六个

那只是默认布局,楼主是自己改的

重新定义一个函数就好了

;; invoke
(global-set-key [f8] 'gdb)

;; GDB layout
(defadvice gdb-setup-windows (after activate)
  (gdb-setup-my-windows)
)

(defun gdb-setup-my-windows ()
  (set-window-dedicated-p (selected-window) nil)
  (switch-to-buffer gud-comint-buffer)
  (delete-other-windows)
  (let
    ((win0 (selected-window))             ; source
     (win1 (split-window-horizontally
             (floor (* 0.5 (window-width)))))   ; gdb
     (win2 (split-window-vertically
             (floor (* 0.7 (window-body-height))))) ; bp
    )
    ;; set source buffer
    (set-window-buffer
     win0
     (if gud-last-last-frame
         (gud-find-file (car gud-last-last-frame))
       (if gdb-main-file
           (gud-find-file gdb-main-file)
         (list-buffers-noselect))))
    (setq gdb-source-window win0)

    (select-window win1)
    (split-window-vertically (floor (* 0.7 (window-body-height))))
    (split-window-horizontally (floor (* 0.7 (window-body-width))))
    (split-window-vertically (floor (* 0.4 (window-body-height))))

    ;; set locals window
    (gdb-set-window-buffer (gdb-get-buffer-create 'gdb-locals-buffer))
    ;; set assembly window
    (other-window 1)
    (gdb-set-window-buffer (gdb-stack-buffer-name))
    (other-window 1)
    (gdb-set-window-buffer (gdb-get-buffer-create 'gdb-registers-buffer))
    ;; set breakpoint buffer
    (other-window 1)
    (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
    ;; set focus on gdb buffer
    (select-window win2)
  )
)

你这个方法我还没有实验, 但是感觉这种去除前几个文字有点暴力.

**set**  filename-display relative
**set**  filename-display absolute
**set**  filename-display basename
**show**  filename-display

这是gdb包含的方法, 但是因为我的项目是cmake 工程,cmake都是用的绝对路径造成设置这个只会吧/home/jon替换为~/ 我想把后面的工程名字前面的所有的都不要

我只是告诉你修改的点

至于怎么改 我不告诉你

shourenyuyuburushourenyuyu

可能可以用project.el找到项目根目录然后从每个文件里减去。我有时间看看

好的, 我现在暂时的做法就是用gdb的set filename_display basename隐藏所有的目录部分, 需要看的时候再打开使用absolute.