[emacs] [gdb customization]如何在一个窗口中显示源缓冲区? [英] [emacs][gdb customization] How to display source-buffer in one window?

查看:213
本文介绍了[emacs] [gdb customization]如何在一个窗口中显示源缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在emacs中定制了gdb窗口。在调试之后,新的源代码在不同的窗口中打开。我只想在一个窗口中看到源代码。我的gdb自定义是:

 ; _____________________________________________________________________________________ 
; | | |
; | BREAKPOINTS | |
; | __________________________________________ | |
; | | |
; |堆栈| |
; | __________________________________________ | |
; | | |
; | | |
; | LOCALS | |
; | |来源代码|
; | __________________________________________ | |
; | | |
; | | |
; | | |
; | | |
; | | |
; | | |
; | GDB | |
; | | __________________________________________ |
; | | |
; | | |
; | | I / O |
; | | |
; | __________________________________________ | __________________________________________ |

(require'gud)

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

; GDB布局
(defadvice gdb-setup-windows(激活后)
(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)
($ win $($)$($($) ); source + i / o
(win2(split-window-vertical
(floor(* 0.5(window-body-height))))); gdb
(win3(split-窗口垂直
(floor(* 0.5(window-body-height))))); localals
(win4(split-window-vertical
(floor(* 0.6(window-body ($)$)
(选择窗口win1)
;配置右窗口
(让
((winSrc(selected-window) ); source
(winIO(split-window-vertical(floor(* 0.9(window-body-height))))); I / O

(set-window-buffer winIO(gdb-get-buffer-create'gdb-inferior-io))
(set-window-buffer
winSrc
(if gud-last-last-框架
(gud-find-file(car gud-last-last-frame))
(如果gdb-main-file
(gud-find-file gdb-main-file)
(list-buffers-noselect))))
(setq gdb-source-window winSrc)
(set-window-dedicated-p winIO t)


(set-window-buffer win0(gdb-get-buffer-create'gdb-breakpoints-buffer))
(set-window-buffer win3(gdb-get-buffer-create'gdb-locals -buffer))
(set-window-buffer win4(gdb-get-buffer-create'gdb-stack-buffer))
(select-window win2)



; GDB变量
(setq gdb-many-windows t)
(setq gdb-show-main t)
(setq gdb-show-changed-values t)
(setq gdb -use-colon-colon-notation t)
(setq gdb-use-separate-io-buffer nil)
(setq gdb-delete-out-of-scope t)
(setq gdb-speedbar-auto-raise t)

主屏幕是:
gdb屏幕开始



但是当我开始调试,下一个源文件在另一个窗口中打开。参见下面的示例:
gdb窗口中的新源代码



应用程序的复制示例是:



main.cpp

  #includeclassB.h

int main()
{
B * b = 0 ;
b = new B();
return 0;
}

classA.h

  #ifndef CLASS_A_H 
#define CLASS_A_H

class A
{
public:
A();
};

#endif

classA.cpp / p>

  #includeclassA.h
#include< iostream>

A :: A()
{
std :: cout<<< 构造方法A<的std :: ENDL;
}

classB.h

  #ifndef CLASS_B_H 
#define CLASS_B_H

#includeclassA.h

类B:public A
{
public:
B();
};

#endif

classB.cpp / p>

  #includeclassB.h
#include< iostream>

B :: B():A()
{
std :: cout<< 构造函数B<的std :: ENDL;
}

Makefile

  SOURCES = main.cpp classA.cpp classB.cpp 
TARGET = test
CXX_FLAGS = -g

.PHONY:all

全部:$(TARGET)

$(TARGET):$(SOURCES)
$(CXX)$(CXX_FLAGS)$ ^ - o $ @

.PHONY:clean

clean:
rm -vf $(TARGET)

重现步骤:


  1. 运行emacs


  2. Mx gdb


  3. gdb -i = mi测试


  4. 在gdb命令窗口中运行:start


  5. 运行:next


  6. 运行:step


我的环境是:Ubuntu14.04,gdb - 7.7.1,emacs - 25.1.1。



我尝试使用 set-window-dedicated-p 。但这不是我的问题的解决方案。
我是新的emacs,请帮忙,我的配置有什么问题?

解决方案

display-buffer-alist 允许您控制显示新缓冲区的窗口。你首先在其中注册一个函数指针

 (add-to-list'display-buffer-alist 
cons'cdb-source-code-buffer-p
(cons'display-source-code-buffer nil))

然后实现选择一个窗口的函数,例如

 (defun cdb-source-code -buffer-p(bufName action)
返回BUFNAME是否是源代码缓冲区
(let((buf(get-buffer bufName)))
(和buf
(with-current-buffer buf
(derived-mode-p buf'c ++ - mode'c-mode'csharp-mode'nxml-mode)))))

(defun显示源代码缓冲区(sourceBuf alist)
找到一个包含源代码并在其中设置sourceBuf的窗口
(let *((curbuf(current-buffer))
wincurbuf(get-buffer-window curbuf))
(win(if(和wincurbuf
(derived-mode-p sourceBuf'c ++ - mode'c-mode'nxml-mode)
派生d-mode-p(current-buffer)'c ++ - mode'c-mode'nxml-mode)
wincurbuf
(get-window-with-predicate
(lambda
(let((bufName(buffer-name(window-buffer window)))
(或(cdb-source-code-buffer-p bufName nil)
(assoc bufName display- buffer-alist)
))))))));;派生模式-p在这里不起作用,不知道为什么...
(set-window-buffer win sourceBuf)
win))

cdb-source-code-buffer-p 选择源代码缓冲区,其中 display-source-code-buffer 被调用,它返回你想要的窗口。


I have customized gdb windows in emacs. After it during debugging new source code opens in different windows. I'd like to see source code only in one window. My gdb customization is:

;     _____________________________________________________________________________________
;    |                                          |                                          |
;    |              BREAKPOINTS                 |                                          |
;    |__________________________________________|                                          |
;    |                                          |                                          |
;    |                 STACK                    |                                          |
;    |__________________________________________|                                          |
;    |                                          |                                          |
;    |                                          |                                          |
;    |                 LOCALS                   |                                          |
;    |                                          |                SOURCE CODE               |
;    |__________________________________________|                                          |
;    |                                          |                                          |
;    |                                          |                                          |
;    |                                          |                                          |
;    |                                          |                                          |
;    |                                          |                                          |
;    |                                          |                                          |
;    |                  GDB                     |                                          |
;    |                                          |__________________________________________|
;    |                                          |                                          |
;    |                                          |                                          |
;    |                                          |                    I/O                   |
;    |                                          |                                          |
;    |__________________________________________|__________________________________________|

(require 'gud)

; 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))             ; breakpoints
     (win1 (split-window-horizontally
         (floor (* 0.5 (window-width)))))   ; source + i/o
     (win2 (split-window-vertically
         (floor (* 0.5 (window-body-height))))) ; gdb
     (win3 (split-window-vertically
        (floor (* 0.5 (window-body-height))))) ; locals
     (win4 (split-window-vertically
         (floor (* 0.6 (window-body-height))))) ; stack
    )
    (select-window win1)
    ; configurating right window
    (let
    ((winSrc (selected-window)) ; source
     (winIO (split-window-vertically (floor (* 0.9 (window-body-height))))) ; I/O
     )
      (set-window-buffer winIO (gdb-get-buffer-create 'gdb-inferior-io))
      (set-window-buffer
    winSrc
    (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 winSrc)
      (set-window-dedicated-p winIO t)
   )

    (set-window-buffer win0 (gdb-get-buffer-create 'gdb-breakpoints-buffer))
    (set-window-buffer win3 (gdb-get-buffer-create 'gdb-locals-buffer))
    (set-window-buffer win4 (gdb-get-buffer-create 'gdb-stack-buffer))
    (select-window win2)
  )
)

; GDB variables
(setq gdb-many-windows t)
(setq gdb-show-main t)
(setq gdb-show-changed-values t)
(setq gdb-use-colon-colon-notation t)
(setq gdb-use-separate-io-buffer nil)
(setq gdb-delete-out-of-scope t)
(setq gdb-speedbar-auto-raise t)

The main screen is: gdb screen after start

But when I started debugging then next source file opens in another window. See example bellow: New source code in gdb window

The example of application to reproduce is:

main.cpp

#include "classB.h"

int main()
{
  B *b = 0;
  b = new B();
  return 0;
}

classA.h

#ifndef CLASS_A_H
#define CLASS_A_H

class A
{
public:
  A();
};

#endif

classA.cpp

#include "classA.h"
#include <iostream>

A::A()
{
  std::cout << "Constructor A" << std::endl;
}

classB.h

#ifndef CLASS_B_H
#define CLASS_B_H

#include "classA.h"

class B : public A
{
public:
  B();
};

#endif

classB.cpp

#include "classB.h"
#include <iostream>

B::B() : A()
{
  std::cout << "Constructor B" << std::endl;
}

Makefile

SOURCES=main.cpp classA.cpp classB.cpp
TARGET=test
CXX_FLAGS=-g

.PHONY: all

all: $(TARGET)

$(TARGET): $(SOURCES)
    $(CXX) $(CXX_FLAGS) $^ -o $@

.PHONY: clean

clean:
    rm -vf $(TARGET)

Step to reproduce:

  1. Run emacs

  2. M-x gdb

  3. gdb -i=mi test

  4. In gdb command window run: start

  5. run: next

  6. run: step

My environment is: Ubuntu14.04, gdb - 7.7.1, emacs - 25.1.1.

I tried to use set-window-dedicated-p. But this is not solution for my problem. I'm new in emacs, help me please, what is wrong in my configuration?

解决方案

display-buffer-alist lets you control in which windows new buffers are displayed. You start by registering a function pointer inside it

(add-to-list 'display-buffer-alist
         (cons 'cdb-source-code-buffer-p
           (cons 'display-source-code-buffer nil)))

then implement the function that selects a window, for example

(defun cdb-source-code-buffer-p (bufName action)
  "Return whether BUFNAME is a source code buffer."
  (let ((buf (get-buffer bufName)))
    (and buf
     (with-current-buffer buf
       (derived-mode-p buf 'c++-mode 'c-mode 'csharp-mode 'nxml-mode)))))

(defun display-source-code-buffer (sourceBuf alist)
  "Find a window with source code and set sourceBuf inside it."
  (let* ((curbuf (current-buffer))
     (wincurbuf (get-buffer-window curbuf))
     (win (if (and wincurbuf
               (derived-mode-p sourceBuf 'c++-mode 'c-mode 'nxml-mode)
               (derived-mode-p (current-buffer) 'c++-mode 'c-mode 'nxml-mode))
          wincurbuf
        (get-window-with-predicate
         (lambda (window)
           (let ((bufName (buffer-name (window-buffer window))))
             (or (cdb-source-code-buffer-p bufName nil)
             (assoc bufName display-buffer-alist)
             ))))))) ;; derived-mode-p doesn't work inside this, don't know why...
    (set-window-buffer win sourceBuf)
    win))

cdb-source-code-buffer-p select source code buffers, for which display-source-code-buffer is called, that returns the window you want.

这篇关于[emacs] [gdb customization]如何在一个窗口中显示源缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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