cscope 详解
创建数据库
$ cscope -Rbq
- -b:仅构建交叉引用(cross-reference)文件,然后退出,不会进入下面的交互界面:
- -q:通过倒排索引加速符号的查找过程。该选项会导致cscope额外产生cscope.in.out和cscope.po.out两个文件
- -k: 在生成索引文件时,不搜索/usr/include目录
- -u: 扫描所有文件,重新生成交叉索引文件
- -I dir: 在-I选项指出的目录中查找头文件
命令
- :cs add cscope.out 添加一个新的数据库
- :cs find 查询一个模式(Usage: find c|d|e|f|g|i|s|t name)
c: Find functions calling this function 调用本函数的函数
d: Find functions called by this function 本函数调用的函数
e: Find this egrep pattern 查找egrep模式
f: Find this file 查找文件
g: Find this definition 查询定义,类似ctags
i: Find files #including this file 查找include文件
s: Find this C symbol 查询C符合,函数/枚举/宏
t: Find this text string 查找指定字符串 - g 可以跳到函数定义;Ctrl-t可以返回
- :cs find f g do_fork 查找do_fork定义并打开该文件
quickfix窗口配置
- set cscopequickfix=s-,c-,d-,i-,t-,e-
- 搜索结果quickfix窗口显示;s/c/d/i/t/e查找模式有效
- +(将结果追加到quickfix窗口)、-(清空上一次的结果)
- 好处是,可以在搜索结果的多个匹配项间进行跳转,而位置列表的方式则只能选择一个项
- quickfix窗口命令
- :cn 下一个
- :cp 上一个
- :cr 第一个
- :cla 最后一个
- :clist 所有项
其他配置
- set csprg=/usr/bin/cscope
- set csto=1 " tags优先查找,0则反之
- set cst " 同时使用tags
- set nocsverb " 增加数据库时,不会打印成功或失败信息
if filereadable(“cscope.out”)
cs add cscope.out " 自动加载
endif - set csverb
结合ctags
cs find 同时搜索ctags&cscope数据库
ctrl-] & ctrl-t 也共用