一直有 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)
04 | c:找到调用这个函数的函数 |
05 | d:找到被这个函数调用的函数 |
06 | e:找到这个 egrep 模式 |
07 | f:找到此文件夹 |
08 | g:找到这个定义 |
09 | i:找文件 #包括这个文件 |
10 | s:找到这个 C 符号 |
11 | t:找到对其的赋值 |
建立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
本文详细介绍了如何解决Cscope在使用过程中遇到的问题,并提供了快速上手教程,包括如何配置快捷键避免冲突、解决重复数据库加载错误、理解并使用searchkind参数进行高效搜索、建立数据库的方法等。同时,提供了Cscope命令查询技巧,帮助开发者快速定位代码调用点。

被折叠的 条评论
为什么被折叠?



