将VIM打造成一个可视化的调试器,有3个选项,
- vimGDB
- clewn
- pyClewn
第一个方法,太过繁琐,要求重新编译VIM,好处就是支持终端VIM和gVIM。第二个好处是不需要重新安装VIM,缺点是只支持gVIM;第三个继承了前两个的优点,
- 不需要重新编译VIM
- VIM和gVIM均支持
前2个使用c语言,第3个是使用python编写。
下面给一个全面的3方法的比较:
vimGdb | clewn | pyclewn | |
---|---|---|---|
platform | unix | unix |
all unix platforms supported by python – requires GNU gdb from macports on Mac Os X Windows (python 3 only) |
language | C | C |
python 2.4 and above python 3 C language for the pdb-clone python extension module, _bdb |
vim mode | vim in a terminal, gvim | gvim | gvim and vim in a terminal (vim 7.3 or above required) |
vim interface | a vim patch | a standalone program connected to gvim with a netbeans socket |
a standalone program connected to vim with a netbeans socket pyclewn may be started from within vim since vim 7.3 |
vim version | a different patch for each vim version | vim 6.3 and above | vim 7.0 and above |
debuggers | gdb | gdb | gdb, pdb |
gdb features |
|
|
|
pdb features |
|
是英文,大家凑乎着看吧。
接下来下载安装包:
http://sourceforge.net/projects/pyclewn/
然后安装:
tar xzf pyclewn-1.11.py3.tar.gz
cd pyclewn-1.11.py3
python setup.py install --force
第3条命令是有问题的,这就是为什么我把它标红的缘故。上面的三条的命令是官方提供的。
因为上面的安装是默认的编辑器是gVIM而不是VIM,而我们在本文中是要配置VIM的调试环境,因此我们的环境只安装了VIM,而没有安装gVIM,当我们执行第3条命令就会报错。第3条命令应该为:
su root
export EDITOR=/usr/bin/vim
exit
sudo python setup.py install –force
安装成功后,你执行pyclewn,就会打开一个空VIM窗口,表示安装成功。
获取官方的帮助,包括启动和使用pyclewn.
http://pyclewn.sourceforge.net/_static/pyclewn.html
在VIM中可以使用
:help pyclewn
获取pyclewn的帮助。
在VIM调试:
我们以一个main.cpp 这个文件生成console可执行程序:
vim main.cpp
编辑完成后退出vim
g++ -g main.cpp -o console
vim main.cpp
然后执行命令:
:Pyclewn
注意是大写的P,
然后会看到:
Running nbstart, <C-C> to interrupt.
..
Creation of vim script file "/tmp/viMp7ww/0": OK.
The netbeans socket is connected.
Press ENTER or type command to continue
这个表示pyclewn已经和netbeans socket建立了链接,那么netbeans是什么呢?它是VIM自带的gdb的调试接口。
然后按回车,
接着执行
:Cfile console
注意是大写的C
就会发现窗口自动被分成上个2个,上面是调试窗口,下面是代码窗口,pyclewn自定义很多快捷键,可以使用:
:Cmapkeys
还是大写的C,C表示是pyclewn的命令。
使用
:Cbreak 6
来设置断点,这里将断点设置在第6行,然后
shift+R
开始运行,
ctrl+N
单步执行。
:Cdbgvar
答应变量名
还有其他的命令:
*|Ccwindow| opens a vim quickfix window holding the list of the breakpoints with their current state; the quickfix window allows moving directly to any breakpoint (requires the vim|+quickfix|feature) *|Cdbgvar| add a watched variable or expression to the (clewn)_dbgvar buffer *|Cdelvar| delete a watched variable from the (clewn)_dbgvar buffer * Cdumprepr print on the console pyclewn internal structures that may be used for debugging pyclewn *|Cfoldvar| collapse/expand the members of a watched structure or class instance * Chelp print on the console, help on the pyclewn specific commands (those on this list) in addition to the help on the debugger commands *inferiortty* * Cinferiortty spawn the controlling terminal (default xterm) of the debuggee and sets accordingly gdb 'inferior-tty' variable and the TERM environment variable; this command MUST be issued BEFORE starting the inferior. * Cloglevel print or set the log level dynamically from inside Vim *|Cmapkeys| map pyclewn keys *|Cproject| save the current gdb settings to a project file *|Csetfmtvar| set the output format of the value of a watched variable * Csigint send a <C-C> character to the debugger to interrupt the running program that is being debugged; only with gdb, and when pyclewn and gdb communicate over a pseudo terminal, which means on unix but not on Windows; on Windows, to interrupt the debuggee, one must type <C-C> in the console that is popped by gdb on debuggee start up
详情请参考:
http://pyclewn.sourceforge.net/_static/pyclewn.html
这里截个屏
版权所有,禁止转载. 如需转载,请先征得博主的同意,并且表明文章出处,否则按侵权处理.