GTAGS
使用Gtags辅助查看kernel源码
使用make gtags
在kernel根目录下生成索引文件。
1 | gtags - Generate GNU GLOBAL index |
kernel已对该命令进行封装,不必手动生成索引文件。在生成索引文件时还可以指定架构,这可以有效减少干扰项。
1 | make gtags ARCH=arm |
kernel根目录下会生成三个新文件
1 | $ ls G* |
gtags.vim
General form of Gtags command is as follows:
1 | :Gtags [option] pattern |
To go to ‘func’, you can say
1 | :Gtags func |
Input completion is available. If you forgot the name of a function but recall only some characters of the head, please input them and press
1 | :Gtags fu<TAB> |
To go to the referenced point of ‘func’, add -r
option.
1 | :Gtags -r func |
To go to any symbols which are not defined in GTAGS, try this.
1 | :Gtags -s func |
To go to any string other than symbol, try this.
1 | :Gtags -g ^[sg]et_ |
This command accomplishes the same function as grep(1) but is more convenient because it retrieves an entire directory structure.
To get list of objects in a file ‘main.c’, use -f command.
1 | :Gtags -f main.c |
If you are editing main.c itself, you can use ‘%’ instead.
1 | :Gtags -f % |
You can get a list of files whose path include specified pattern.
For example:
1 | :Gtags -P /vm/ <- all files under 'vm' directory. |
If you omitted an argument and input only
Since all short options are sent to global(1) as is, you can use the -i, -o, -O, and so on.
For example, if you want to ignore case distinctions in pattern.
1 | :Gtags -gi paTtern |
It will match to both of ‘PATTERN’ and ‘pattern’.
If you want to search a pattern which starts with a hyphen like ‘-C’
then you can use the -e option like grep(1).
1 | :Gtags -ge -C |
By default, Gtags command search only in source files. If you want to
search in both source files and text files, or only in text files then
1 | :Gtags -go pattern # both source and text |
gtags-cscope
1 | Find symbol :cs find 0 or s |
总结
一般情况下,Gtags
已能满足需求。