Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2246720
  • 博文数量: 395
  • 博客积分: 10994
  • 博客等级: 上将
  • 技术积分: 5586
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-17 19:49
文章存档

2014年(1)

2013年(10)

2012年(74)

2011年(303)

2010年(7)

分类: LINUX

2011-07-18 17:50:28

cscope的安装:

[root@localhost ruanjian]# ll cscope-15.6.tar.gz

-rw-r--r-- 1 root root 391223 12  9 2006 cscope-15.6.tar.gz

[root@localhost ruanjian]# tar zxvf cscope-15.6.tar.gz

[root@localhost ruanjian]# cd cscope-15.6

[root@localhost cscope-15.6]# ls

aclocal.m4    config.h.in   COPYING     Makefile.am    packages

AUTHORS       config.sub    depcomp     Makefile.in    README

ChangeLog     configure     doc         missing        src

compile       configure.in  INSTALL     mkinstalldirs  TODO

config.guess  contrib       install-sh  NEWS           ylwrap

[root@localhost cscope-15.6]# ./configure

[root@localhost cscope-15.6]# make && make install

[root@localhost cscope-15.6]# cscope

Cscope version 15.6                                    Press the ? key for help

 

 

 

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:

按下ctrl+z退出

[root@localhost cscope-15.6]# cd ../vim_Taglisht_Ctags/zebra-0.95a

[root@localhost zebra-0.95a]# pwd

/home/ruanjian/vim_Taglisht_Ctags/zebra-0.95a

[root@localhost zebra-0.95a]# vim tag.sh

  1 #!/bin/sh

  2 find $1 -name "*.h" -o -name "*.c" -o -name "*.cc" >cscope.list

  3 cscope -bkq -i cscope.list

  4 ctags -R

[root@localhost zebra-0.95a]# chmod 777 tag.sh

[root@localhost zebra-0.95a]# ./tag.sh .

[root@localhost zebra-0.95a]# ls cscope.*

cscope.in.out  cscope.list  cscope.out  cscope.po.out

[root@localhost zebra-0.95a]# ls tags

tags

 

~

~

~                              VIM - Vi IMproved

~

~                                 版本 7.3.29

~                           维护人 Bram Moolenaar

~                         修改者

~                       Vim 是可自由分发的开放源代码软件

~

~                            帮助乌干达的可怜儿童!

~                输入  :help iccf       查看说明

~

~                输入  :q               退出

~                输入  :help      查看在线帮助

~                输入  :help version7   查看版本信息

~

~

~

~

:cs show

 # pid    数据库名                            prepend path   

 0 4484   cscope.out                         

 

~

~                              VIM - Vi IMproved

~

~                                 版本 7.3.29

~                           维护人 Bram Moolenaar

~                         修改者

~                       Vim 是可自由分发的开放源代码软件

~

~                              赞助 Vim 的开发!

~                输入  :help sponsor    查看说明

~

~                输入  :q               退出

~                输入  :help      查看在线帮助

~                输入  :help version7   查看版本信息

~

~

~

~

~

:cs add cscope.out

E568: 重复的 cscope 数据库未被加入  

[root@localhost zebra-0.95a]# vim bgpd/bgp_main.c

154

155   ret = sigaction (signo, &sig, &osig);

156

157   if (ret < 0)

158     return (SIG_ERR);

159   else

160     return (osig.sa_handler);

161 }

162

163 /* Initialization of signal handles. */

164 void

165 signal_init ()

166 {

167   signal_set (SIGHUP, sighup);

168   signal_set (SIGINT, sigint);

169   signal_set (SIGTERM, sigint);

170   signal_set (SIGPIPE, SIG_IGN);

171   signal_set (SIGUSR1, sigusr1);

172 }

173 ^L

174 /* Main routine of bgpd. Treatment of argument and start bgp finite

175    state machine is handled at here. */

176 int

:cs find g signal_init

170   signal_set (SIGPIPE, SIG_IGN);

171   signal_set (SIGUSR1, sigusr1);

172 }

173 ^L

174 /* Main routine of bgpd. Treatment of argument and start bgp finite

175    state machine is handled at here. */

176 int

Cscope tag: signal_init

   #       文件名 / 上下文 /

   1    165  bgpd/bgp_main.c <>

             signal_init ()

   2    154  ospf6d/ospf6_main.c <>

             signal_init ()

   3    149  ospfd/ospf_main.c <>

             signal_init ()

   4    159  ripd/rip_main.c <>

             signal_init ()

   5    143  ripngd/ripng_main.c <>

             signal_init ()

   6    131  vtysh/vtysh_main.c <>

             signal_init ()

   7    165  zebra/main.c <>

             signal_init ()

Type number and (empty cancels): 1

164 void

165 signal_init ()

166 {

167   signal_set (SIGHUP, sighup);

168   signal_set (SIGINT, sigint);

169   signal_set (SIGTERM, sigint);

170   signal_set (SIGPIPE, SIG_IGN);

171   signal_set (SIGUSR1, sigusr1);

172 }

 

如果想要退回原来的地方:ctrl+t

 

但有时候使用cscope更灵活,首先可以看cscope的帮助文件:
01 cscope 命令:
02 add  :添加一个新的数据库             (用法: add file|dir [pre-path] [flags])
03 find :查询一个模式                   (用法: find c|d|e|f|g|i|s|t name)
04 c:找到调用这个函数的函数
05 d:找到被这个函数调用的函数
06 e:找到这个 egrep 模式
07 f:找到此文件夹
08 g:找到这个定义
09 i:找文件 #包括这个文件
10 s:找到这个 C 符号
11 t:找到对其的赋值
12 help :显示此信息                     (用法: help)
13 kill :结束一个连接                   (用法: kill #)
14 reset:重置所有连接                   (用法: reset)
15 show :显示连接                       (用法: show)

通过上面的帮助文件可以发现如果想找到request_irq函数的定义处代码,即可使用这个命令:cs find g request_irq来进行查找。大多数情况下查找的结果并不唯一,因为需要在多个结果中通过头文件来继续查看。

通常是先通过cscope大致定位到头文件,再通过ctags在该头文件中详细定位。其实这两种工具并不局限于上述用法,更多用法可以再深入使用的过程中慢慢摸索,而且配合正则表达式等效果会更好。

阅读(2230) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~