文章目录
- cscope 过滤目录介绍
cscope 过滤目录介绍
第一步创建自己的cscope脚本~/.local/bin/cscope.sh
,如下:
function my_cscope()
{CODE_PATH=`pwd`echo "$CODE_PATH"echo "start cscope...."if [ ! -f "$CODE_PATH/cscope.files" ];thenecho "cscope.files not exist!"elserm -f $CODE_PATH/cscope.*fiif [ ! -d "$CODE_PATH/rt-thread" ];thenfind . \( -path './arch/arc' \-o -path './arch/alpha' \-o -path "./arch/blackfin" \-o -path "./arch/cris" \-o -path "./arch/h8300" \-o -path "./arch/ia64" \-o -path "./arch/m68k" \-o -path "./arch/microblaze" \-o -path "./arch/mn10300" \-o -path "./arch/openrisc" \-o -path "./arch/powerpc" \-o -path "./arch/score" \-o -path "./arch/sparc" \-o -path "./arch/um" \-o -path "./arch/x86" \-o -path "./arch/c6x" \-o -path "./arch/m32r" \-o -path "./arch/microblaze" \-o -path "./arch/nios2" \-o -path "./arch/powerpc" \-o -path "./arch/sh" \-o -path "./arch/um" \-o -path "./arch/xtensa" \-o -path "./arch/cris" \-o -path "./arch/hexagon" \-o -path "./arch/mips" \-o -path "./arch/openrisc" \-o -path "./arch/s390" \-o -path "./arch/sparc" \-o -path "./arch/unicore32" \-o -path "./arch/parisc" \-o -path "./arch/tile" \-o -path "./arch/tile" \-o -path './arch/c6x' \) \-prune -o -name "*.[chxsS]" -print > cscope.fileselsefind . \( -path "./rtos/rt-thread/rt-thread/bsp/mb9*" \-o -path "./rtos/rt-thread/rt-thread/bsp/at91*" \-o -path "./rtos/rt-thread/rt-thread/bsp/ess*" \-o -path "./rtos/rt-thread/rt-thread/bsp/gd3*" \-o -path "./rtos/rt-thread/rt-thread/bsp/lpc*" \-o -path "./rtos/rt-thread/rt-thread/bsp/ls*" \-o -path "./rtos/rt-thread/rt-thread/bsp/mi*" \-o -path "./rtos/rt-thread/rt-thread/bsp/imx*" \-o -path "./rtos/rt-thread/rt-thread/bsp/rasp*" \-o -path "./rtos/rt-thread/packages/packages/iot/*" \-o -path "./rtos/rt-thread/rt-thread/bsp/stm32/stm32f*" \-o -path "./bootrom" \-o -path "./u-boot" \-o -path "./tools" \) \-prune -name "*.cc" -o -name "*.[chxsS]" \-print > cscope.filesfiecho "cscope -Rbkq -i cscope.files"cscope -Rbkq -i $PWD/cscope.files > cscope.log 2>&1echo "cscope finished"
}my_cscope;
我的这个脚本首先去区分当前执行cscope
命令的目录是rt-thread
目录还是linux
目录,因为不同的代码要过滤过目录不一样。
此外,还会通过 重定向 将cscope
在解析文件cscope.files
过程中输出的log
重定向到 cscope.log
方便问题问题。关于 find 命令的使用见 find 命令高效使用文章
第二步在 ~/.bashrc
中添加 mycscope 命令,添加完后,别忘记执行 source ~/.bashrc
。
alias mycscope='source ~/.local/bin/cscope.sh'
第三部测试效果:
(*^~^*) ~/workbase/cix_linux/linux> mycscope
/home/sam/workbase/linux
start cscope....
cscope -Rbkq -i cscope.files
cscope finished
(*^~^*) ~/workbase/cix_linux/linux> ls
arch COPYING cscope.files cscope.out drivers init Kconfig LICENSES mm samples sound virt
block CREDITS cscope.in.out cscope.po.out fs ipc kernel MAINTAINERS net scripts tools
certs crypto cscope.log Documentation include Kbuild lib Makefile README security usr
从下图中可以看到通过cscope命令查找 函数定义定义时只显示了linux/arch 目录下的几个文件,滤除了上文中设置的那些目录: