linux系统下用vim+ctags+cscope查看源码

来源:互联网 发布:apm飞控源码 编辑:程序博客网 时间:2024/06/05 16:34
ctags 用于把关键字生成一个索引表,在vim里可直接使用"ta 关键字"在索引表里查找并定位.cscope 也是生成索引表,在vim里使用"cs xx xx xx "来查找如查看ffmpeg-3.0的源码:    1). 在终端进入源码目录,输入"ctags -R *" // 会在当前目录下生成索引表文件, 文件名为tags    2). 在终端使用,需确保终端当前工作目录是在索引表文件tags的所在目录(注意需确保/etc/vimrc里没有"set tags=xx"的语句).        如查看"av_register_all"函数, 则打开vim后,输入":ta av_register_all", 按回键后可以直接定位到函数体的所在源文件。        当查看的内容出现多个选择时,输入前面的序号即可跳转到相应的源码文件。        在vim里,按"ctrl+g"可查看当前的源文件名, "ctrl+o"可跳回上次浏览的位置.            当标移动到要查看的关键字后,按"ctrl+]"直接查看.    // vim+ctags 只适合查看类型的定义,函数体等。并不适合如需查看一个函数在哪些地方被调用了,又被哪些函数调用,所以还需要用cscope命令    3). 使用cscope命令生成索引表        终端命令:             find ./ -name "*.h" -o -name "*.c"   >  cscope.files   //在当前目录下查找*.h, *.c文件,并把相应的文件及路径输出到cscope.file文件里           cscope -bkq   // 让cscope根据 cscope.file文件里的文件列表生成索引表(cscope.in.out  cscope.out     cscope.po.out)    4). cscope在vim里的用法        打开vim后, 输入":cs"确认后会弹出帮助说明:        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 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 this text string        help : Show this message              (Usage: help)        kill : Kill a connection              (Usage: kill #)        reset: Reinit all connections         (Usage: reset)        show : Show connections               (Usage: show)        Press ENTER or type command to continue    常用cs命令:       "cs add  ./"是用于增加当前目录下的索引表       "cs  find  c 函数名" 查看哪些函数调用指定的函数名       "cs  find  d 函数名" 查看指定的函数名调用了哪些函数       "cs find g 类型/函数" 查看类型的定义或函数体       "cs find t 字符串"   按字符串内容来查找相应的关键字//////////////////////////////////////////////////////////在一些源码工程里,如uboot, linux kernel里:    直接执行下面命令即可产生相应的索引表:           make tags           make cscope

查看linux内核源码还可以通过”man 9 内核里的函数”来查看说明.
需要在linux内核源码目录下:

make mandocs ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-make installmandocs ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
原创粉丝点击