From: http://blog.sina.com.cn/s/blog_498a6eeb0100v05m.html
1. 下载cscope-15.7
http://dldx.csdn.net/fd.php?i=878111800792509&s=924cf0d6a0f63bb6ca24f900
解压所里面有三个文件, 放到vim的安装目录下即可。
2.建索引
- -b
- Build the cross-reference only.
- -C
- Ignore letter case when searching. -k
- ``Kernel Mode'', turns off the use of the default include dir(usually /usr/include) when building the database, since kernelsource trees generally do not use it. -R
- Recurse subdirectories for source files. -i namefile
- Browse through all source files whose names are listed innamefile (file names separated by spaces, tabs, or new-lines)instead of the default (cscope.files). If this option is specified,cscope ignores any files appearing on the command line. Theargument namefile can be set to ``-'' to accept a list of filesfrom stdio. Filenames in the namefile that contain whitespace haveto be enclosed in "double quotes". Inside such quoted filenames,any double-quote and backslash characters have to be escaped bybackslashes.
http://cscope.sourceforge.net/cscope_man_page.html
执行结束后你可以在当前目录下发现cscope.out文件,这就是cscope建立的符号数据库。上面这个命令中,-b参数使得cscope不启动自带的用户界面,而仅仅建立符号数据库
3. 在vim命令行下执行:
:cs help cscope commands: add : Add a new database (Usage: add file|dir [pre-path] [flags])find : Query for a pattern (Usage: find c|d|e|f|g|i|s|t name)c: Find functions calling this functiond: Find functions called by this functione: Find this egrep patternf: Find this fileg: Find this definitioni: Find files #including this files: Find this C symbolt: Find assignments tohelp : Show this message (Usage: help)kill : Kill a connection (Usage: kill #)reset: Reinit all connections (Usage: reset)show : Show connections (Usage: show)
s: 查找C语言符号,即查找函数名、宏、枚举值等出现的地方
g: 查找函数、宏、枚举等定义的位置,类似ctags所提供的功能
d: 查找本函数调用的函数
c: 查找调用本函数的函数
t: 查找指定的字符串
e: 查找egrep模式,相当于egrep功能,但查找速度快多了
f: 查找并打开文件,类似vim的find功能
i: 查找包含本文件的文
使用cscope查找do_fork函数的定义:
在vim命令行下执行:
:cs f g do_fork每次输入这样挺麻烦, 下载一个插件cscope_quickfix.vim 。http://www.vim.org/scripts/download_script.php?src_id=2635在_vimrc中增加:"cscope"If you want to use Popup menu for :Cscope command, put a line in .vimrc like:let Cscope_PopupMenu = 1这样可以在右键中弹出菜单。这样就可以不用记命令。