Use VI to view the advanced usage of Linux kernel code VI

Source: Internet
Author: User
Use VI to view the advanced use of Linux kernel code VI-general Linux technology-Linux programming and kernel information. The following is a detailed description. I accidentally read the article "use tags/csloud to view the kernel source code-HOWTO" (http://www.linuxforum.net/forum... llposts & Main = 573982). After trying vim + ctags + taglist, I feel very good. The speed of reading the Code has improved a lot! You can stop using sourceinsight on windows.

This is the article of wheelz, Which is reprinted here:

××××××××××××××××××××××××××××××××××××××××××× ××××××××××××××××××××××××××××××
I wrote a bit about the discussion. Haha

In fact, the Makefile of the original kernel code contains the make tags/TAGS option,
However, the generated tags is too large because it contains drivers and other infrequently used directories.

Therefore, according to the Makefile file of the kernel, A Makefile is written,
Used to generate ctags/csags/etags.

In this way, you can delete and add directories as needed.

I have never used tags/cscope before. I don't know if there is any better way. Thank you for your advice.
Please also add the commonly used and useful commands and skills of tags/cs.pdf.

I. Usage

Find an empty directory and copy the attachment Makefile.
Then, select the following make command in the directory:

Note: SRCDIR is used to specify the kernel source code directory. If not,
The default value is/usr/src/linux/, as shown in figure

$ Make

The source files under/usr/src/linux are processed, and ctags and csags are generated in the current directory.


1) only create ctags

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

2) only create cscope

$ Make SRCDIR =/usr/src/linux-2.6.12/cs.pdf

3) create ctags and csags

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

4) only create etags

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


Ii. kernel source files included during processing:

1) the drivers and sound directories are not included.
2) excluding unrelated architecture Directories
3) The fs directory only includes the top-level directory and the ext2 and proc directories.

For kernel 2.6.12.1, the generated tags is about 12 M, and cscopes is about 19 M.

3. The simplest ctags command

----------------------
1) Enter

After entering vim, use

: Tag func_name

Jump to function func_name

----------------------
2) identifier)

To enter the function where the cursor is located, use

CTRL +]

----------------------
3) rollback

Rollback

CTRL + T

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


I will only use these commands now. Please talk about other commonly used commands.

Search for Identifiers

: Tag write _

Find the identifier starting with write _. If there are multiple identifiers, continue to press Until you find the desired one.


If you want to jump to an identifier that contains a block

: Tag/block

Then use .

Here '/' indicates that vim 'block' is a pattern.

If you want to select an identifier starting with write,

: Tselect/^ write _

Here, '^' indicates the beginning. Similarly, '$' indicates the end.

Multiple identifiers with the same name

If a function has multiple definitions, the ': tag' command jumps to the first one. If the current file has multiple definitions, this is used first.
Then you can jump to the next
: Tnext

Jump to the first
: Tfirst

Jump to the previous count
: [Count] tprevious

Jump to the next count
: [Count] tnext

Jump to the last
: Tlast


You can also choose from all tagnames:
: Tselect tagname
××××××××××××××××××××××××××××××××××××××××××× ××××××××××××××××××××××××××××××
I didn't use the makefile of wheelz. Because I need to read the driver code, I used the make tags command.

Below is the installation of taglist and simple usage, reproduced the http://www.linux.gov.cn/cn/docview? The content of s = 3 & id = 2 is as follows:

××××××××××××××××××××××××××××××××××××××××××× ×××××××××××××××××××××××××××××

Installation instructions:

1. Make sure there is an available Exuberant Ctags version on the machine (you can run the "ctags" command ")

2. Download taglist(false: taglist.zip) on the vimsite );

3. Use "unzip taglist.zip-d ~ /. Vim "unlock;

4. Run ": helptags ~ in Vim ~ /. Vim/doc "installation documentation.

Although the taglist uses ctags, the existence of the tags file is not required.

Function Description:

Use the command ": Tlist" to enable/disable taglist.

Taglist provides the following functions:

Displays macro, function, variable, typedef, class, and struct information;
When opening multiple files, you can view the structure information of these files at the same time;
Double-click the name displayed in the taglist window on the left or press the Enter key. The corresponding defined position is displayed in the main window on the right;
The position of the cursor in the right window is changed, and the left window is highlighted in yellow within 4 seconds (default value, see ": help 'updatetime;
When you enable/disable taglist, the plug-in can automatically change the size of the current Vim window (whether it is text mode Vim or GUI Vim), unless you use ": let Tlist_Inc_Winwidth = 0 "to disable this function (when this function is used to cause compatibility issues ).
For more help information, see ": help taglist ".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.