temp

Posted Five100Miles

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了temp相关的知识,希望对你有一定的参考价值。

内核目录下可以使用make cscope快速生成对应架构的数据库, 仅这点就把渣渣si甩了一条街. 其实实现原理很简单, cscope是通过读取cscope.files中文件列表建立的数据库, 因此只要控制cscope.files的输入即可实现不同架构下建立的不同cscope.out.

我们先来看看内核是怎么做的. 主目录Makefile中cscope目标会调用scripts/tags.sh脚本, 后者根据传参会生成tags, cscope等, 我们就看下cscope.

docscope()
{
? ? ? ? (echo \-k; echo \-q; all_target_sources) > cscope.files
? ? ? ? cscope -b -f cscope.out
}

-k是使用kernel mode, 即不包含/usr/include的头文件.
-q是使用反转索引, 开启后会额外生成两个文件, 但可以加快索引效率.
-b是建立交叉引用.
-f是指定文件名.
以上选项均可以通过man cscope获取说明.

all_target_sources是关键, 它通过find命令将所需的源文件名输入cscope.files中. 这里有个地方没看懂记录下: $tree是怎么赋值成内核目录树的.

写个example.

#!/bin/sh

SH_DIR=$PWD
TOP_DIR=$SH_DIR/../../../../
src_dirs=$TOP_DIR/build/drv_pub/
src_dirs+=\ $TOP_DIR/product/compile
src_dirs+=\ $TOP_DIR/product/drv_src/kernel_src
src_dirs+=\ $TOP_DIR/product/drv_src/usr_src

DEBUG_PATH=
if [ -n "$DEBUG_PATH" ]; then
? ? ? ? touch test && chmod +x test && echo > test
? ? ? ? PRINT_FILE="-fprint $SH_DIR/test"
else
? ? ? ? PRINT_FILE="-print"
fi

find_c_sources()
{
? ? ? ? find $src_dirs -name "*.[chS]" -a -not -regex ".*x86_sdk.*" -not -type l $PRINT_FILE
}

find_makefile()
{
? ? ? ? find $src_dirs -name Makefile -not -type l $PRINT_FILE
? ? ? ? find $src_dirs -name *.config -not -type l $PRINT_FILE
? ? ? ? find $src_dirs -name *.mk -not -type l $PRINT_FILE
}

find_sources()
{
? ? ? ? find_c_sources
? ? ? ? find_makefile
}

make_cscope()
{
? ? ? ? if [ -f cscope.out ]; then
? ? ? ? ? ? ? ? rm cscope.*
? ? ? ? fi
? ? ? ? (echo \-k; echo \-q; find_sources) > cscope.files
? ? ? ? if [ ! -n "$DEBUG_PATH" ]; then
? ? ? ? ? ? ? ? cscope -b -f cscope.out -i cscope.files
? ? ? ? fi
}

make_cscope

可以根据不同架构生成不同名字的cscope.out然后在需要时载入对应的cscope.out文件, 这样查看工程远比si等ide方便.
注意反汇编的文件不要以*.S命名, 否则被当做汇编加入数据库会导致cscope.out剧烈膨胀, 曾经一个工程生成上G的文件, 而内核的cscope.out才400M.

 

以上是关于temp的主要内容,如果未能解决你的问题,请参考以下文章

SQL Server进阶表表达式

Python全栈day13(作业讲解字典嵌套实现用户输入添加及查看)