使用vim+cscope,我们可以很方便的查看代码。

安装cscope后,执行以下命令:

 
  
  1. # cd /usr/src/linux 
  2. # find . -name '*.h' -o -name '*.c' > cscope.files 
  3. # cscope -b -k -q 
  4. # ctags -R 
  5. # echo 'cs add .' >> /etc/vimrc 

此后进入/usr/src/linux,使用vim就支持代码跟踪了。

执行 :cs help 可以显示cscope帮助信息:

 
  
  1. cscope commands: 
  2. add  : Add a new database           (Usage: add file|dir [pre-path] [flags]) 
  3. find : Query for a pattern          (Usage: find c|d|e|f|g|i|s|t name
  4.        c: Find functions calling this function 
  5.        d: Find functions called by this function 
  6.        e: Find this egrep pattern 
  7.        f: Find this file 
  8.        g: Find this definition 
  9.        i: Find files #including this file 
  10.        s: Find this C symbol 
  11.        t: Find assignments to 
  12. help : Show this message              (Usage: help) 
  13. kill : Kill a connection              (Usage: kill #) 
  14. reset: Reinit all connections         (Usage: reset) 
  15. show : Show connections               (Usage: show) 

常用命令:

:cs find g hash    #查找hash函数或变量的定义

:cs find e hash    #查找包含hash字段的代码行

常用快捷键:

:ctrl + ]       #跳转到光标所在符号的定义位置

:ctrl +T       #回到上一次的位置

 

Have fun!