Chinaunix首页 | 论坛 | 博客
  • 博客访问: 900636
  • 博文数量: 119
  • 博客积分: 2493
  • 博客等级: 大尉
  • 技术积分: 2363
  • 用 户 组: 普通用户
  • 注册时间: 2012-06-03 14:00
文章分类

全部博文(119)

文章存档

2013年(19)

2012年(100)

分类: LINUX

2012-06-03 14:06:00

   学习内核,避免不了要在代码的茫茫大海中找要自己想要看的部分代码,那首先要学会

如何找代码。现在有很多工具可以用来找代码。那哪一款是最好的呢?经过一些人的经验出,

vimgrep然后混合cscopectagstaglist是比较好的。俗话说:“工欲善其事,必先利其器”。

所以kernelnewbies还是把这好好学习学习。

-----------------------------------------------------------------------------------

一,搭建cscope,ctags,taglist的使用环境。

1,先以阅读内核源代码为例吧。

1.0先安装相应的工具软件。这个比较容易。(ubuntu下面)

sudo apt-get install ctags
sudo apt-get install cscope

1.1在内核源代码中搭建cscope环境。(如果不是内核代码而是别的代码,cscope -Rkbq)


 wanny@wanny-C-Notebook-XXXX:~/linux-2.6.34.2$ pwd
/home/wanny/linux-2.6.34.2
wanny@wanny-C-Notebook-XXXX:~/linux-2.6.34.2$ make cscope
GEN cscope
wanny@wanny-C-Notebook-XXXX:~/linux-2.6.34.2$ ls -al cscope*
-rw-r--r-- 1 wanny wanny 923873 2012-05-24 11:05 cscope.files
-rw-r--r-- 1 wanny wanny 211284156 2012-05-24 11:07 cscope.out
-rw-r--r-- 1 wanny wanny 27729920 2012-05-24 11:07 cscope.out.in
-rw-r--r-- 1 wanny wanny 153125340 2012-05-24 11:07 cscope.out.po

进入cscope

 wanny@wanny-C-Notebook-XXXX:~/linux-2.6.34.2$ pwd 
/home/wanny/linux-2.6.34.2 
wanny@wanny-C-Notebook-XXXX:~/linux-2.6.34.2$ cscope -d  
Find this C symbol: 
Find this global definition: 
Find functions called by this function: 
Find functions calling this function: 
Find this text string: 
Change this text string: 
Find this egrep pattern: 
Find this file: 
Find files #including this file: 
 退出cscope
 ctrl + z
   
1.2在内核源代码中搭建ctags环境.
 wanny@wanny-C-Notebook-XXXX:~/linux-2.6.34.2$ pwd 
/home/wanny/linux-2.6.34.2 
wanny@wanny-C-Notebook-XXXX:~/linux-2.6.34.2$ make tags 
  GEN     tags 
wanny@wanny-C-Notebook-XXXX:~/linux-2.6.34.2$ ls -al tags 
-rw-r--r-- 1 wanny wanny 98613918 2012-05-24 11:10 tags
   1.3,配置taglist.
 taglist是vim的一个插件。不需要安装。只需要加入两个配置文件和在.vimrc中添加相应的
配置即可。
可以到上下载最新的taglist
插件。插件中有两个
文件,一个taglist.vim,另一个是taglist.txt。
1.3.1 将taglist.vim添加到/usr/share/vim/vim73/plugin/下。
1.3.2 将taglist.txt添加到/usr/share/vim/vim73/doc下。
1.3.3  在~/.vimrc配置文件的最后添加如下配置:
  1. map <F8> : TlistToggle <CR>

-------------------------------------------------------------------------

二,工具的使用方法。

1,使用taglist的方法

1,press  F8 进入。将vim打开的屏幕分为两个屏幕,可以使用,ctrl +w + w实现两个
       屏幕之间的切换。

2,退出就是使用vim的退出即可,光标在taglist栏(左屏幕)时wq退出。

3,在左栏可以通过对指定的function,macro,struct快速定位。

------------------------------------------------------------------------------------

2,使用cscope。(常用的几个快捷键)

 1,将光标停留在函数或结构体名上,press ctrl+[ 将会跳转到该函数或结构体定义的位置。

 2,press ctrl + t 将会返回。

 3,:cs find g *** 使用cscope查找某函数,某结构体等定义的位置。

------------------------------------------------------------------------------------------

参考资料:


http://hi.baidu.com/fiber212121/blog/item/79d03834e606cc375ab5f5c1.html
-------------------------------------------------------------------------------------------
阅读(2117) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:how to compile a kernel

给主人留下些什么吧!~~