2016年3月27日 星期日

ctags 與 cscope 使用筆記

ctags 和 cscope 是兩款相當強大的原始碼追蹤工具

ctags:
主要功能有兩個,從函式呼叫處跳回函式實做的地方,還有跳出視窗補完結構中的成員(ex: struct. 或 struct->)

    install: $sudo apt-get install exuberant-ctags

使用:
    建立tag檔案:ctags <指令> <指定的檔案>
                     ex: ctags -R ./folder/*.[ch]
    接下來就可以在vim中使用它了
    常用指令(在vim command mode下)
                  [移動游標到指定位置] [CTRL] + ]  移動到定義處
                  [移動游標到指定位置] [CTRL] +t   返回上一個位置


cscope:
主要功能是可以跳到任何一個有呼叫這個函式的位置,是個很強大的原碼追蹤工具

    install: $apt-get install cscope

使用:
    使用前要先設定vim plugin:把 cscope_maps.vim 加到 ~/.vim/plugin中
                                               (沒有的話可以自行建立)
    需要建立ctag檔案:cscope <指令> <檔案位置>
                           ex: cscope -Rbqk ./folder/*.[ch]
    接下來就可以在vim中使用plugin提供的功能(ref. [4])



Reference:
[1]http://stackoverflow.com/questions/934233/cscope-or-ctags-why-choose-one-over-the-other
[2]http://rickey-nctu.blogspot.tw/2009/02/vim-srcexpl.html
[3]http://cscope.sourceforge.net/cscope_vim_tutorial.html
[4]http://softsmith.blogspot.tw/2009/01/vim-cscope-trace.html
[5]http://easwy.com/blog/archives/advanced-vim-skills-cscope/

沒有留言:

張貼留言