Linux Software Installation Use (6) Source View tool __linux

Source: Internet
Author: User

When there is a network, the use of LXR (the Linux Cross referencer) Online reading the source is a very cool thing. In the absence of a network, only through Vim to enter the core source code that looks a little reluctant. Next, this article will introduce a quick location Source tool: Ctags and Cscope. With the Vim editor, you can quickly locate the source code you want to see by using both of these tools. All right, let's go.

1. Download the latest kernel source package, extract to the main directory

The next steps, of course, can be done under the current system kernel source directory, but it is best to create a source-specific directory in the home directory for the duration of the insurance. The source directory mentioned below refers to the source directory under the home directory.

2. Install Ctags

Using command: sudo apt-get install ctags

3. Install Cscope

Using command: sudo apt-get install Cscope

4. into the label file

In the source directory through the command make tags to generate tag files

5. Generate Index File

Generate index files in the source directory by using the command make cscope.

6. Import index files into vim

Use the command to open the Vim profile: sudo gedit/etc/vim/vimrc; then add the following code under the file: View source print?

1 If Filereadable ("Cscope.out")
2 CS Add Cscope.out
3 endif

This way, each time you open vim, you can use Cscope directly.

After completing the above steps, you can use VIM to quickly locate the source code. The ctags and cscope that are installed above all belong to the source indexing tool, so it is also possible to install only one of the two. Yes, although ctags can quickly locate the labels entered, the Cscope is more flexible to use. So it is more convenient to install both at the same time. Here are some simple ways to use, just for reference.

1. Use of Ctags

Ctags use is particularly simple, first into the source directory, open the Vim editor, in the command mode input: Tag tag_name press ENTER. Usually tag_name can be struct name, function name, macro variable name, and so on. Usually after you enter the above command, because the label you find is not unique, you also need to work with the following command:

TFirst: Jump to the first

Tnext: Skip to Next

Tlast: Skip to the last

2. Use of Cscope

Although Ctags is easy to use, but sometimes more flexible to use cscope, you can first look at the Cscope Help file: View source print?

01 Cscope command:
02 Add: Adding a new Database (usage: add file|dir [Pre-path] [flags])
03 Find: Query a pattern (usage: Discovery c|d|e|f|g|i|s|t name)
04 C: Find the function that called the function
05 D: Find the function that was called by this function
06 E: Find this egrep mode
07 F: Locate this folder
08 G: Find this definition
09 I: Find a file #包括这个文件
10 S: Find the C symbol
11 T: Find an assignment 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 Connection (usage: shows)

Using the Help file above, you can find that if you want to find the definition of REQUEST_IRQ function code, you can use this command: CS find g Request_irq to search. In most cases, the results of a lookup are not unique, because you need to continue to view them through a header file in multiple results.

Usually, the header file is roughly positioned through the cscope, and then the ctags is positioned in detail. In fact, these two tools are not limited to the above usage, more use can be further used in the process of slowly groping, and with regular expressions and other effects will be better.

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.