使用cscope

一直有 ctags,但它有一点缺点,就是不能查一个函数在哪里有过调用。于是学习cscope。

官网的 vim/cscope tutorial 是特别好的学习材料, 读一遍下来,就会用了:

http://cscope.sourceforge.net/cscope_vim_tutorial.html


我在用的过程中遇到了这样几个问题:

1,cscope_maps.vim 中定义的快捷键 Ctrl-space 与系统切换输入法的快捷键冲突,需要自己编辑这个cscope_maps.vim 文件,把快捷键重新映射一下。

2, 出现“ E568: 重复的 cscope 数据库未被加入” 这样的错误。

原来是 /etc/vimrc 中已经载入了 cscope.out , 在 cscope_maps.vim 又一次载入的话,就会有这个错误。

解决方法是在cscope_maps.vim 中添一行:

    " add any cscope database in current directory
    set nocsverb         // 这一行是新加入的。
    if filereadable("cscope.out")
        cs add cscope.out  
    " else add the database pointed to by environment variable
    elseif $CSCOPE_DB != ""
        cs add $CSCOPE_DB
    endif

    " show msg when any other cscope db added
    set cscopeverbose  



再记一下“search kind":

's', for 'find all uses of symbol X'

'g' finds the global definition(s) of a symbol

'c' finds all calls to a function

'f' opens the filename under the cursor


find :查询一个模式                   (用法: find c|d|e|f|g|i|s|t name)

04c:找到调用这个函数的函数
05d:找到被这个函数调用的函数
06e:找到这个 egrep 模式
07f:找到此文件夹
08g:找到这个定义
09i:找文件 #包括这个文件
10s:找到这个 C 符号
11t:找到对其的赋值


建立cscope.out数据库

1,Generate cscope.files with a list of files to be scanned

使用find命令即可:

    find /my/project/dir -name '*.java' >/my/cscope/dir/cscope.files
find . -name "*.h" -o -name "*.c" -o -name "*.cpp" > cscope.files

2,Generate the Cscope database.  
  cscope -b -q -k 
-b flag tells Cscope to just build the database, and not launch the Cscope GUI.
The -q causes an additional, 'inverted index' file to be created, which makes searches run much faster for large databases
-k sets Cscope's 'kernel' mode--it will not look in /usr/include for any header files that are #included in your source files

-R






  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值