cscope
安裝
原諒我的懶惰
sudo apt-get install cscope
使用
1. 先建立數(shù)據(jù)庫
相當(dāng)于source insight(之后簡稱為SI)的同步
轉(zhuǎn)到目錄里面 cscope -Rbq
參數(shù)解釋:
R recursively
b 只建立數(shù)據(jù)庫(cscope.out),不進(jìn)入cscope
q 建立數(shù)據(jù)庫的同時,同時建立加速文件,使用這個選項紊扬,會在當(dāng)前目錄下產(chǎn)生多個cscope的文件
k 不分析/usr/include下面的文件,用戶態(tài)程序一定不要加上這個符號叼屠,否則沒法知道這個函數(shù)到底是不是一個系統(tǒng)庫函數(shù)
-b Build the cross-reference only.
-C Ignore letter case when searching.
-c Use only ASCII characters in the cross-ref file (don't compress).
-d Do not update the cross-reference.
-e Suppress the <Ctrl>-e command prompt between files.
-F symfile Read symbol reference lines from symfile.
-f reffile Use reffile as cross-ref file name instead of cscope.out.
-h This help screen.
-I incdir Look in incdir for any #include files.
-i namefile Browse through files listed in namefile, instead of cscope.files
-k Kernel Mode - don't use /usr/include for #include files.
-L Do a single search with line-oriented output.
-l Line-oriented interface.
-num pattern Go to input field num (counting from 0) and find pattern.
-P path Prepend path to relative file names in pre-built cross-ref file.
-p n Display the last n file path components.
-q Build an inverted index for quick symbol searching.
-R Recurse directories for files.
-s dir Look in dir for additional source files.
-T Use only the first eight characters to match against C symbols.
-U Check file time stamps.
-u Unconditionally build the cross-reference file.
-v Be more verbose in line mode.
-V Print the version number.
TIPS:
建立完畢數(shù)據(jù)庫之后捕透,如果在當(dāng)前目錄再次執(zhí)行cscope唠梨,會使得重新建立數(shù)據(jù)庫,除非兩次執(zhí)行cscope的參數(shù)一致柒昏!
2. 直接使用使用cscope
當(dāng)前目錄下執(zhí)行cscope -Rq(k) 不加-b 參數(shù)即可進(jìn)入cscope
3. vim下使用cscope
3.1 vim中添加cscope數(shù)據(jù)庫文件
cs add /path/to/cscope.out [prepend path ] -C
-C 指的是查找的時候忽略大消息
[prepend path] 作用不確定
cs show
可以查看已經(jīng)加入的數(shù)據(jù)庫文件
cs kill
刪除一個數(shù)據(jù)庫
3.2 vim中搜索符號
cs find * symbol
等同于 cs f g symbol
查找symbol凳宙,
其中 * 可以是一下選項之一:
c: Find functions calling this function
d: Find functions called by this function
e: Find this egrep pattern
f: Find this file
g: Find this definition
i: Find files #including this file
s: Find this C symbol
t: Find assignments to
3.3 vim中使用快捷鍵
如果每次我沒都輸入"cs f g symbol",豈不是會累死昙楚?
cscope能不能像SI那樣 ctrl + 鼠標(biāo)左鍵 直接到達(dá)符號定義的地方近速?
cscope提供了一組快捷鍵,將下面的配置寫入~/.vimrc文件下就可以了
nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>f :cs find f <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>i :cs find i ^<C-R>=expand("<cword>")<CR>$<CR>
nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>
使用上面的快捷鍵的方法是堪旧,將光標(biāo)定位到你要查找的變量削葱,函數(shù)名或者宏定義名處。先按下Ctrl+@
淳梦,松開后快速按下相應(yīng)的鍵析砸,比如按下g,表示查找該函數(shù)或者變量的定義爆袍;按下c表示查找本函數(shù)被調(diào)用的地方首繁。功能很強大。
3.4 vim中的跳轉(zhuǎn)
ctrl+]
:在函數(shù)調(diào)用的地方跳轉(zhuǎn)到函數(shù)定義的地方
ctrl+t
:返回上一個查找的地方
3.5 cscope的vim建議配置
if has("cscope")
set csprg=/usr/local/bin/cscope
set csto=0
"find cscope db prior
set cst
" use cstags
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
endif
這里面有很多vim的技巧
http://easwy.com/blog/archives/automatically_update_ctags_tag_cscope_database/
在 vim 中使用 cscope 時陨囊, : cs f s symbol-name 或相應(yīng)的快捷鍵執(zhí)行后當(dāng)前窗口就跳轉(zhuǎn)到引用該符號的位置弦疮。
如果想跳轉(zhuǎn)的同時打開一個新的窗口,可以使用如下命令:
: scs f s symbol-name
這里的 scs 應(yīng)該是 split 的意思蜘醋。
另外胁塞,上面這個命令是將窗口橫向分割,如果要縱向分割的話压语,可以使用如下命令:
: vert scs f s symbol-name
另外可以在 .vimrc 里追加對應(yīng)的快捷鍵:
參考 help cscope: