Vim Cscope/Ctags Browser Linux Kernel Source Code

前言

    最近一直在搞内核, 没有对各位PWN好友的信息进行回复, 在此表示抱歉. 今天给大家带来一个阅读Linux Kernel源代码工具的配置方法.

Step One

sudo apt-get install cscope ctags

Step Two

~/.bashrc中添加如下代码:

function ta ()
{
    #clean older info
    rm -rf tags
    rm -rf cscope.*
    # generate new info
    find $PWD | egrep -i "\.(c|h|cpp)$" > cscope.files
    cscope -bkq -i cscope.files
    ctags -R . *.c *.h *.cpp --tag-relative=yes ./
}

在源代码根目录执行ta,会生成四个文件cscope.files, cscope.in.out, cscope.out, cscope.po.out.

Step Three

/etc/vim/vimrc中添加

if filereadable("cscope.out")
   cs add cscope.out
endif

Usage

cscope find c|d|e|f|g|i|s|t keyword
0 或 s 查找本 C 符号(可以跳过注释)
1 或 g 查找本定义
2 或 d 查找本函数调用的函数
3 或 c 查找调用本函数的函数
4 或 t 查找本字符串
6 或 e 查找本 egrep 模式
7 或 f 查找本文件
8i 查找包含本文件的文件

Tip

  1. 我们每回必须在源代码的根目录下打开, 这样才不会出现cs not connection
  2. bashrc中的配置已经解决了File not exist的问题, 就是一个绝对路径, 相对路径的问题.

Tuxdiary

猜你喜欢

转载自blog.csdn.net/qq_33528164/article/details/80412349