vim
符号查找和跳转
gtags
gtags加载数据库,先找当前目录,若没有则找上层目录,所以当写模块程序需要内核GTAGS时,可以如下整理,
把kernel目录和module目录分开放,为避免gtags把其他无关文件扫描,使用find命令找到需要扫描的kernel源文件放到 linux-file-list
然后在项目根目录运行gtags -f ./linux-file-list,生成linux相关GTAGS文件,
.
├── others
├── modules
├── linux
├── GPATH
├── GRTAGS
├── GTAGS
└── linux-file-list
cscope
建立数据库
常用
cscope -Rqb
Usage: cscope [-bcCdehklLqRTuUvV] [-f file] [-F file] [-i file] [-I dir] [-s dir]
              [-p number] [-P path] [-[0-8] pattern] [source files]
-b            Build the cross-reference only.
              只构建数据库,不进入cscope会话
-I incdir     Look in incdir for any #include files.
-k            Kernel Mode - don't use /usr/include for #include files.
-q            Build an inverted index for quick symbol searching.
              生成cscope.in.out和cscope.po.out文件,加快cscope的索引速度
-R            Recurse directories for files.
              包含子目录
-s dir        Look in dir for additional source  files.
查找
cscope commands:
add  : Add a new database             (Usage: add file|dir [pre-path] [flags])
find : Query for a pattern            (Usage: find a|c|d|e|f|g|i|s|t name)
       a: Find assignments to this symbol ( 查找对符号的赋值 )
如 :cs find a main
Cscope tag: main
   #   line  filename / context / line
   1    395  src/http/modules/ngx_http_rewrite_module.c <<ngx_http_rewrite>>
             sc.main = regex;
   2   2419  src/http/ngx_http_core_module.c <<ngx_http_subrequest>>
             sr->main = r->main;
   3    615  src/http/ngx_http_request.c <<ngx_http_alloc_request>>
             r->main = r;
       c: Find functions calling this function 查找某函数或宏被调用的位置
Cscope tag: ngx_align_ptr
   #   line  filename / context / line
   1    122  src/core/ngx_crc32.c <<ngx_crc32_table_init>>
             p = ngx_align_ptr(p, ngx_cacheline_size);
   2     43  src/core/ngx_hash.c <<ngx_msec_t>>
             elt = (ngx_hash_elt_t *) ngx_align_ptr(&elt->name[0] + elt->len,
       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 this text string
ctrl+d 退出 cscope
vim 中使用cscope,
vim 实现了回调cscope的函数,所以不需要插件。
增加配置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" cscope setting
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("cscope")
  set csto=0 " 0:优先使用cscope.file查找,1:优先使用tags查找
  set cst    " 把cscope.file当tags文件使用,即可以用 <C-]>找定义
  set nocsverb
  " add any database in current directory
  if filereadable("cscope.out")
      cs add cscope.out
  endif
  set csverb
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("<cfile>")<CR><CR>
endif
大项目中使用cscope
http://cscope.sourceforge.net/large_projects.html
 
                    
                     
                    
                 
                    
                 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号