vim的调试插件——gdbmgr

来源:互联网 发布:mdf文件恢复数据库 编辑:程序博客网 时间:2024/06/06 09:58

转载自:http://www.lainme.com/doku.php/blog/2010/11/vim%E7%9A%84%E8%B0%83%E8%AF%95%E6%8F%92%E4%BB%B6_gdbmgr

在按照安装教程一步步安装时,遇到了gdbmgr代码区空白的问题,搜索了好多未果,幸好看到这篇文章,从而完美解决,故转之,希望以后安装不要在浪费时间


改用VIM后发现编辑文件果然顺手了很多,虽然gedit有些地方确实挺方便。

寻找在VIM里用的调试插件时,看到最多的就是vimgdb和clewn,pyclewn相对较少,gdbmgr就更少了(几乎只有一个人在推荐)。尽管还没有正式发布并且有点小问题,gdbmgr的确是十分强大的。

介绍

相比vimgdb,gdbmgr不需要编译打补丁。相比clewn/pyclewn,它不需要在~/.vim之外装任何东西。

要运行gdbmgr,仅需要以huge参数编译并支持forkpty()函数的vim,也就是下列情况的一个:

  • 编译参数带有 –with-features=huge –enable-perlinterp
  • 编译参数带有 –with-features=huge –enable-pythoninterp
  • 编译参数带有 –with-features=huge,并修改vim的makefile,使包含 EXTRA_LIBS = -lutil

实际上Ubuntu源里的vim就可以了,在Fedora21下直接yum install vim安装好后的vim就可以了,无需上述操作。

PS: 如果需要卸载vim, 可以通过yum remove vim, 不过这样还没有成功,还需要查看which vim, 将该路径文件夹删除,这样才算彻底卸载,要不然都是没有卸载。卸载之后重新安装,需要yum install vim,然后由于上面删除which vim 文件夹,故需要重新hash下,具体参见

http://www.turnkeylinux.org/forum/support/20140108/solved-bash-command-not-found-after-replacing-package

# vim
bash: /usr/local/bin/vim: No such file or directory
Bash is still searching for vim-tiny's symbolic link at /usr/local/bin/vim, but I just uninstalled it.  The PATH environment variable is valid, and which sees vim.

# env | grep -i path
PATH=/usr/lib/git-core:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# which vim
/usr/bin/vim
There is no bash alias for vim, so as a final effort to find some clue I ran:
# type vim
vim is hashed (/usr/local/bin/vim)
According to bash's man page:
Bash uses a hash table to remember the full pathnames of
executable files (see hash under SHELL BUILTIN COMMANDS
below).  A full search of the directories in PATH is
performed only if the command is not found in the hash table.
So because the bash hash remembered the vim-tiny symbolic link, I could not simply run vim from the command line anymore.  The fix is to tell bash hash to either forget about vim, or remember vim's new location.

# hash vim
# vim
success \o/
Hopefully this helps fellow newbs avoid spending too much time trying to figure this out

功能上断点、单步、观察点、变量查看、堆栈什么的都有。虽然没有clewn/pyclewn那样的气泡提示,不过查看起来也挺方面(在expression框中输入“i=“,就会自动显示当前值并随程序执行而变化)

安装

http://vim.sourceforge.net/scripts/script.php?script_id=4104

解压后全部放到~/.vim里,在终端执行

cd ~/.vim/gdbmgr/srcmake

然后编辑~/.bashrc,在最后加入

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/.vim/gdbmgr/src

执行

source ~/.bashrc

使其生效

这样安装就结束了。

问题修正

forkpty没有找到

如果出现错误”undefined symbol: forkpty”的话,将下面这句也添加到.bashrc里

export LD_PRELOAD=$LD_PRELOAD:/usr/lib/libutil.so

DI后源码区空白

这是启动时没能自动file文件。作者是将“.”添加到了PATH中,然后(我估计)用了autochdir,这样当前编辑的文件就总是在PATH里,可以在启动时自动file,不会有问题。

但如果不是这样,就需要手工file,可以略作修改来解决这个问题。编辑autoload/gdbmgr.vim的函数gdbmgr#GdbMgrInit,将

  call s:GdbMgrOptionSave()  if a:0 > 0   let curfile= expand(a:1)  else   let curfile= expand("%")  endif

改为

  call s:GdbMgrOptionSave()  if a:0 > 0   let curfile= getcwd()."/".expand(a:1)  else   let curfile= expand("%:p")  endif

并将

 if executable(substitute(curfile,'\.[^.]\+$','','')) && !isdirectory(curfile)

改为

 if executable(substitute(curfile,'\.[^./]\+$','','')) && !isdirectory(curfile)

以及将

  let gdbcmd= substitute(curfile,'\.[^.]\+$','','')

改为

  let gdbcmd= substitute(curfile,'\.[^./]\+$','','')

使用

看文档就可以了,里面有5个例子可以做一下。


0 0
原创粉丝点击