linux 中使用emacs+cscope 阅读内核源码

1. 先决条件是 emacs 已经安装完成

2. 安装cscope

$ sudo apt-get install cscope

 

3. 在emacs 配置文件 .emacs 中添加 cscope支持

(require 'xcscope)

 

4. 生成内核源码的索引文件

在内核源码的顶层目录下执行下面的命令生成索引文件:

:~/workspace/a9-src/linux-3.0.35$ cscope-indexer -r

其中的 -r 选项代表递归扫面各个子目录。该命令执行完后会在当前目录下生成 cscope-files 和 cscope.out 两个文件,

其中包含着项目中的文件名、变量函数名等信息,供检索时使用。

 

5. 使用方法-快捷键

进行完上述步骤后,在浏览代码时就可以直接用快捷键进行查找等操作了。xcscope 的快捷键都是绑定到 C-c s 前缀上的,

主要快捷键如下:

C-c s s         Find symbol.
C-c s d         Find global definition.
C-c s g         Find global definition (alternate binding).
C-c s G         Find global definition without prompting.
C-c s c         Find functions calling a function.
C-c s C         Find called functions.
C-c s t         Find text string.
C-c s e         Find egrep pattern.
C-c s f         Find a file.
C-c s i         Find files #including a file.

 

6. 示例,查询task_struct 全局定义

posted @ 2015-03-13 15:51  阿青1987  阅读(544)  评论(0编辑  收藏  举报