vim的调试插件——gdbmgr

转载自: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/src
make

然后编辑~/.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
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值