Kernel learning Step 1: view the source code VIM + cs.pdf

Source: Internet
Author: User

This article is based on the Linux kernel practice. The author is Ren qiaowei.

We don't need to say much about Vim. We are all using it. Cssag knows C + scope by looking at the software name. It is designed to browse C code. Through cscope, you can know the definition of a function, the functions that call it, and the functions that it calls. It is an indispensable and powerful tool to learn Linux source code on the console. You can read the Vim Help manual for help if_cscop.txt.

1. Install cssag

Download from http://cscope.sourceforge.net and then compile the installation

2. Generate a cssag Database

Enter the root directory of the source code you want to view. For example, if you want to view the Linux kernel source code in/usr/src/Linux, run the following command to generate a cssag database file:

cd /usr/src/linuxcscope –Rbq

R indicates that all files in the subdirectories are indexed. B indicates that cssag does not start its own user interface, but only creates a symbolic database. Q indicates that cssag is generated. in. out and cscope. po. out file to accelerate the index speed of cssag.

The preceding command generates three files: csmetadata. In. Out csmetadata. Out csmetadata. Po. Out.

3. Import the cssag database file to VIM

vim:cs add /usr/src/linux/cscope.out /usr/src/linux

4. Usage of csflood

You can read the vim online documentation for details: Help if_cscop.txt. The most common find command is as follows:

:cs find c|d|e|f|g|i|s|t name

S: Find the symbols of the C code

G: search for this definition

D: Find the function called by this function.

C: Find the function that calls this function.

T: search for this string

E: Find the current egrep mode.

F: Find this file

I: Find the file that contains this file

For example, find the definition of the main function.

:cs find g main

We all know that Vim supports the abbreviated command format. You can use cs f g main instead.

Note: cssag has a shortcut similar to ctags. Press Ctrl + J to jump to the variable or function definition where the cursor is located, and press Ctrl + T to return.

5. Configure Vim to accelerate the use of cssag

First, you need to have a preliminary understanding of VIM configuration. Please refer to this article.Create your own vim-how to configure Vim

Use Vim to open the vim configuration file under your personal root directory

username@ubuntu:~$ vim /home/username/.vimrc

Add the following content:

if filereadable("cscope.out")    cs add cscope.outelseif $CSCOPE_DB != ""    cs add $CSCOPE_DBendifset nusyntax onset tabstop=4set autoindentset matchtime=1set hlsearchset cindentset shiftwidth=4set rulerset showmode

Related Article

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.