From: http://www.zeuux.org/blog/user/leedy.chen/ (Chen Lijun)
When there is a network, it is nice to use lxr (the Linux cross referencer) to read the source code online. In the absence of a network, it seems a little reluctant to search for the kernel source code only through vim. Next, this article will introduce a tool to quickly locate the source code: ctags and csags. The Vim editor can be used together with the above two tools to quickly locate the source code you want to view. Okay. Let's get started!
1. download the latest kernel source code package and decompress it to the main directory.
The subsequent steps can certainly be performed under the current system kernel source code directory, but it is best to create a directory under the main directory to store the source code during the warranty period. The Source Code Directories mentioned below refer to the source code directories under the main directory.
2. Install ctags
Run sudo apt-Get install ctags.
3. Install cssag
Run sudo apt-Get install cscope
4. Generate a Tag file
Generate a Tag file by running make tags in the source code directory.
5. generate an index file
In the source code directory, run the make cscope command to generate the index file.
6. Import the index file to vim.
Run the following command to open the vim configuration file: sudo gedit/etc/Vim/vimrc. Then add the following code to the file:
1 |
if filereadable(
"cscope.out" ) |
In this way, you can directly use cscope every time you open vim.
After completing the preceding steps, you can use Vim to quickly locate the source code. The ctags and csags installed above are both source code indexing tools. Therefore, only one of them can be installed. Yes. Although ctags can quickly locate the entered tag, csags are more flexible to use. Therefore, it is easier to install and use both of them. The following are some simple usage methods for your reference only.
1. Use ctags
Ctags is easy to use. First, go to the source code directory, open the vim editor, and enter tag tag_name in command mode and press Enter. Generally, tag_name can be the struct name, function name, macro variable name, etc. Generally, after the preceding command is entered, the tag found is not unique, so you need to use the following command:
Tfirst: Jump to the first one
Tnext: jump to the next
Tlast: Jump to the last one
2. Use cscope
Although ctags are convenient and convenient to use, csags are sometimes more flexible. First, you can view the Help File of cssag:
02 |
Add: Add a new database (usage: Add file | dir [pre-path] [flags]) |
03 |
Find: query a mode (usage: Find c | d | E | f | G | I | S | T name) |
04 |
C: Find the function that calls this function. |
05 |
D: Find the function called by this function. |
06 |
E: Find the egrep mode. |
08 |
G: Find the definition. |
09 |
I: Find a file # include this file |
11 |
T: Find the value assigned to it. |
12 |
Help: display this information (usage: Help) |
13 |
Kill: end a connection (usage: Kill #) |
14 |
Reset: reset all connections (usage: reset) |
15 |
Show: Display connections (usage: Show) |
The Help File above shows that if you want to find the code in the definition of the request_irq function, you can use this command: CS find G request_irq for search. In most cases, the search results are not unique because you need to use the header file to view multiple results.
Generally, the header file is first located through csflood, and then detailed in the header file through ctags. In fact, these two tools are not limited to the above usage. They can be further explored in the process of further use, and the effects will be better with regular expressions.
From: http://www.zeuux.org/blog/user/leedy.chen/ (Chen Lijun)
When there is a network, it is nice to use lxr (the Linux cross referencer) to read the source code online. In the absence of a network, it seems a little reluctant to search for the kernel source code only through vim. Next, this article will introduce a tool to quickly locate the source code: ctags and csags. The Vim editor can be used together with the above two tools to quickly locate the source code you want to view. Okay. Let's get started!
1. download the latest kernel source code package and decompress it to the main directory.
The subsequent steps can certainly be performed under the current system kernel source code directory, but it is best to create a directory under the main directory to store the source code during the warranty period. The Source Code Directories mentioned below refer to the source code directories under the main directory.
2. Install ctags
Run sudo apt-Get install ctags.
3. Install cssag
Run sudo apt-Get install cscope
4. Generate a Tag file
Generate a Tag file by running make tags in the source code directory.
5. generate an index file
In the source code directory, run the make cscope command to generate the index file.
6. Import the index file to vim.
Run the following command to open the vim configuration file: sudo gedit/etc/Vim/vimrc. Then add the following code to the file:
1 |
if filereadable(
"cscope.out" ) |
In this way, you can directly use cscope every time you open vim.
After completing the preceding steps, you can use Vim to quickly locate the source code. The ctags and csags installed above are both source code indexing tools. Therefore, only one of them can be installed. Yes. Although ctags can quickly locate the entered tag, csags are more flexible to use. Therefore, it is easier to install and use both of them. The following are some simple usage methods for your reference only.
1. Use ctags
Ctags is easy to use. First, go to the source code directory, open the vim editor, and enter tag tag_name in command mode and press Enter. Generally, tag_name can be the struct name, function name, macro variable name, etc. Generally, after the preceding command is entered, the tag found is not unique, so you need to use the following command:
Tfirst: Jump to the first one
Tnext: jump to the next
Tlast: Jump to the last one
2. Use cscope
Although ctags are convenient and convenient to use, csags are sometimes more flexible. First, you can view the Help File of cssag:
02 |
Add: Add a new database (usage: Add file | dir [pre-path] [flags]) |
03 |
Find: query a mode (usage: Find c | d | E | f | G | I | S | T name) |
04 |
C: Find the function that calls this function. |
05 |
D: Find the function called by this function. |
06 |
E: Find the egrep mode. |
08 |
G: Find the definition. |
09 |
I: Find a file # include this file |
11 |
T: Find the value assigned to it. |
12 |
Help: display this information (usage: Help) |
13 |
Kill: end a connection (usage: Kill #) |
14 |
Reset: reset all connections (usage: reset) |
15 |
Show: Display connections (usage: Show) |
The Help File above shows that if you want to find the code in the definition of the request_irq function, you can use this command: CS find G request_irq for search. In most cases, the search results are not unique because you need to use the header file to view multiple results.
Generally, the header file is first located through csflood, and then detailed in the header file through ctags. In fact, these two tools are not limited to the above usage. They can be further explored in the process of further use, and the effects will be better with regular expressions.