Chinaunix首页 | 论坛 | 博客
  • 博客访问: 666757
  • 博文数量: 156
  • 博客积分: 6010
  • 博客等级: 准将
  • 技术积分: 1201
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-05 20:08
文章分类

全部博文(156)

文章存档

2010年(13)

2008年(39)

2007年(104)

我的朋友

分类: LINUX

2007-05-19 19:03:00

用tags/cscope看内核源代码-HOWTO  

看大家讨论得热烈,我也写点。呵呵

其实内核原代码的Makefile就包含了make tags/TAGS的选项,
但是生成的tags太大,因为包含了drivers等不常用的目录。

因此参照内核的Makefile文件,写了一个Makefile,
用来生成ctags/cscope/etags。

这样,可以根据自己的需要,删除和添加目录。

我以前没有用过tags/cscope,不知道有没有更好的方法。欢迎指教。
也请大家补充tags/cscope的常用的和好用的命令,技巧。

一、用法

找一个空目录,把附件Makefile拷贝进去。
然后在该目录中选择性地运行如下make命令:

注:SRCDIR用来指定内核源代码目录,如果没有指定,
则缺省为/usr/src/linux/,如

$ make

将处理/usr/src/linux下的源文件,在当前目录生成ctags, cscope


1) 只创建ctags

$ make SRCDIR=/usr/src/linux-2.6.12/ tags

2) 只创建cscope

$ make SRCDIR=/usr/src/linux-2.6.12/ cscope

3) 创建ctags和cscope

$ make SRCDIR=/usr/src/linux-2.6.12/

4) 只创建etags

$ make SRCDIR=/usr/src/linux-2.6.12/ TAGS


二、处理时包括的内核源文件:

1) 不包括drivers,sound目录
2) 不包括无关的体系结构目录
3) fs目录只包括顶层目录和ext2,proc目录

对2.6.12.1内核,这样生成的tags大约12M,cscopes大约19M

三、最简单的ctags命令

----------------------
1) 进入

进入vim后,用

:tag func_name

跳到函数func_name

----------------------
2) 看函数(identifier)

想进入光标所在的函数,用

CTRL + ]

----------------------
3) 回退

回退用

CTRL + T

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


我现在只会用这几个命令,请大家说说其他常用的命令。


#


debug=

ifeq ($(debug),)
  quiet=quiet_
else
  quiet=
endif

ifdef SRCDIR
  srctree = $(SRCDIR)/
else
  srctree = /usr/src/linux/
endif

SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
                 -e s/arm.*/arm/ -e s/sa110/arm/ \
                 -e s/s390x/s390/ -e s/parisc64/parisc/ )
 
ARCH ?= $(SUBARCH)

RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS -o -name .pc \) -prune -o

ifeq ($(debug),)

define all-sources
    ( find $(srctree) $(RCS_FIND_IGNORE) \
     \( -name include \
         -o -name arch \
         -o -name drivers \
         -o -name sound \
         -o -name fs \) -prune -o \
     -name '*.[chS]' -print; \
     find $(srctree)arch/$(ARCH) $(RCS_FIND_IGNORE) \
     -name '*.[chS]' -print; \
     find $(srctree)include $(RCS_FIND_IGNORE) \
     \( -name config -o -name 'asm-*' \) -prune \
     -o -name '*.[chS]' -print; \
     find $(srctree)include/asm-$(ARCH) $(RCS_FIND_IGNORE) \
     -name '*.[chS]' -print; \
     find $(srctree)include/asm-generic $(RCS_FIND_IGNORE) \
     -name '*.[chS]' -print; \
     find $(srctree)fs -maxdepth 1 $(RCS_FIND_IGNORE) \
     -name '*.[chS]' -print; \
     find $(srctree)fs/ext2 $(RCS_FIND_IGNORE) \
     -name '*.[chS]' -print; \
     find $(srctree)fs/proc $(RCS_FIND_IGNORE) \
     -name '*.[chS]' -print )
endef

else
# in debug mode only process net/ipv4/*

define all-sources
    ( find $(srctree)net/ipv4 $(RCS_FIND_IGNORE) \
     -name '*.[chS]' -print )
endef

endif

.PHONY: all
all: tags cscope

# If quiet is set, only print short version of command

cmd = @$(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))' &&) $(cmd_$(1))

quiet_cmd_cscope-file = FILELST cscope.files
      cmd_cscope-file = $(all-sources) > cscope.files

quiet_cmd_cscope = MAKE cscope.out
      cmd_cscope = cscope -k -b -q

cscope: FORCE
    $(call cmd,cscope-file)
    $(call cmd,cscope)

quiet_cmd_TAGS = MAKE $@
cmd_TAGS = $(all-sources) | etags -

# Exuberant ctags works better with -I

quiet_cmd_tags = MAKE $@
define cmd_tags
    rm -f $@; \
    CTAGSF=`ctags --version | grep -i exuberant >/dev/null && echo "-I __initdata,__exitdata,EXPORT_SYMBOL,EXPORT_SYMBOL_GPL --extra=+f"`; \
    $(all-sources) | xargs ctags $$CTAGSF -a
endef

TAGS: FORCE
    $(call cmd,TAGS)

tags: FORCE
    $(call cmd,tags)

clean:
    rm -rf tags TAGS cscope*

FORCE:

阅读(2214) | 评论(0) | 转发(0) |
0

上一篇:Emacs 下处理中文

下一篇:开源的领导人

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