前言
最近一直在搞内核, 没有对各位
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 查找本文件
8 或 i 查找包含本文件的文件
Tip
- 我们每回必须在源代码的根目录下打开, 这样才不会出现
cs not connection
bashrc
中的配置已经解决了File not exist
的问题, 就是一个绝对路径, 相对路径的问题.