Build lxr to view Linux kernel source code

Source: Internet
Author: User

Linux Kernel readingSource codeGenerally, VIM + ctags or lxr are used. I personally prefer lxr because lxr provides a good interface and uses hyperlinks to mark functions and definitions, you can easily track the details inside the function or view the definition of the data structure. There are ready-made websites on the Internet that provide such services, if you only occasionally look at the kernel sourceCodeIn fact, it is almost the same to directly log on to some websites that provide such services, such as lxr. The experience provided by this website is quite good. I used to check the source code on this website, after all, the process of establishing a file search in this environment is still quite long.

Using lxr to view the kernel source code is actually to build a local website. on Ubuntu, we can quickly complete these tasks. First, let's take a general look at the required tools, apache2, glimpse, and lxr. Next we will officially start building our own lxr.

1. Install apach2:

Sudo apt-Get install apache2

Ii. Install glimpse:

Download the latest source code glimpse-latest.tar.gz from the website and decompress it to the current directory.

Tar-xvgf glimpse-latest.tar.gz

Then go to the decompressed directory. For example, mine is:

CD glimpse-4.18.6/

Before compiling, first check whether flex has been installed on your machine, because this software is required for compiling glimpse. If not, install:

Sudo apt-Get install flex

Then compile:

./Config

Make

Sudo make install

After completing the preceding steps, copy the generated glimpse glimpseindex to the/bin directory:

CD/bin

Sudo CP glimpse glimpseindex/bin

3. Install lxr

Sudo apt-Get install lxr

Create a/usr/share/lxr/HTTP/. htaccess File

Add the following content to it:

<Files ~ (Search | source | ident | diff | find) $>
Sethandler CGI-script
</Files>

4. Copy the Linux source code

Go to the Linux official website to download the latest kernel code (of course, the previous kernel code can also be used)

Copy the Linux source code to/usr/share/lxr/source.

Sudo CP/home/huangwei/download/linux-2.6.33.2.tar.bz2/usr/share/lxr/source

Decompress:

Tar xvjf linux-2.6.33.2.tar.bz2

Rename the decompressed folder

Sudo MV linux-2.6.33.2 2.6.33

 

5. generate data files

CD/usr/share/lxr/source

Generate a keyword cross-index database

Sudo genxref 2.6.33/

Next, wait for a long time because it needs to scan the file.

Next, generate the freetext cross-index database:

Glimpseindex-H. 2.6.33/

Change permissions so that anyone can read the file

Sudo chmod + R. glimpse *

6. Modify the lxr configuration file

Original article:

Sourceroot:/usr/share/lxr/source/$ V/Linux/

Dbdir:/usr/share/lxr/source/dbdir

Changed:

Sourceroot:/usr/share/lxr/source/2.6.33 # address of the newly generated fileidx and xref

Dbdir:/usr/share/lxr/source # location of the generated. glimpse_filenames files

7. Read Source Code

Restart apache2

Sudo/etc/init. d/apache2 restart

Open your browser and enter http: // localhost/lxr/HTTP/source to view the Local Kernel code.

You can see at the top of the page

~ [Source navigation] ~ [Identifier search] ~ [Freetext search] ~ [File search] ~

Source navigation is the interface for users to view pages.

Identifier search is an interface for searching a variable name, structure name, and function name.

Freetext search is the interface for searching any string

File Search

 

According to nickelzhang's suggestion, paste the one I installed:

 

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.