Read Linux source code tools-lxr and glimpse Introduction

Source: Internet
Author: User
Tags perl script
When reading the Linux source code, we have the following experience: the Core organization is relatively loose, and other header files and source code files are often involved when looking at a file. It is very inconvenient to jump back and forth to find the definitions of variables, constants, and functions, so that the mood of reading code is reduced to a low point by several times.

  Lxr (Linux cross reference) is a tool to solve this problem:He creates an index database for the source code file you specified, and uses the Perl script CGI to dynamically generate a Web page containing the source code. You can view it in any browser. On this web page, all variables, constants, and functions are provided in the form of hyper-connections, which is very convenient for reference. For example, you are reading/usr/src/Linux/NET/socket. c source code, found that the function get_empty_inode does not know how and where to define, at this time you just need to click get_empty_inode, lxr returns the definition and implementation of this function and the row of each Referenced File. Note that this information is also hyper-connection. Clicking it will directly jump to the corresponding row of the corresponding file. In addition, lxr also provides identifier search and file search. Combined with the glimpse program, lxr also provides full-text search for all source code files, even including comments!

Next we will introduce the basic installation and use of lxr and glimpse in combination with examples. Since glimpse is relatively simple, we will start from it:

First visit the site: http://glimpse.cs.arizona.edu/get to glimpsesource code, such as what I get is glimpse-4.12.5.tar.gz. log On with root, uncompress the package with tar zxvf glimpse-4.12.5.tar.gz in any directory, and a new directory glimpse-4.12.5 appears under the current directory. enter the directory and execute make. Go to the bin directory and copy the glimpse and glimpseindex files to/bin or/usr/bin. If glimpse is used separately, you only need to execute glimpseindex Foo. foo is the directory you want to index, for example,/usr/src/Linux. the execution result of glimpseindex is generated in your initial directory. the index file of glimpse.

Then, you only need to execute glimpse yourstring to find all the files containing yourstring in/usr/src/Linux.

For lxr, you can access lxr. Linux. No to obtain its source code, and then follow the steps below:
/* The following text comes from the lxr help document and my installation experience */

1) modify the perlbin and installprefix variables in makefile so that they are respectively the location of the Perl program and the location where you want to install lxr. on my machine, the perlbin value is/usr/bin/Perl. as for installprefix, the following principles apply: the installation path of lxr must be accessible by the Web server. Therefore, the value can be simply/home/httpd/html/lxr (for Apache Web Server ).

2) execute make install

3) Modify $ installprefix/HTTP/lxr. conf:
Baseurl: http: // yourip/lxr/HTTP/
Htmlhead:/home/httpd/html/lxr/HTTP/template-head
Htmltail:/home/httpd/html/lxr/HTTP/template-tail
Htmldir:/home/httpd/html/lxr/HTTP/template-Dir
Sourceroot:/usr/src/Linux # If you index the Linux core code
Dbdir:/home/httpd/html/lxr/dbdir/# dbdirk can be named randomly and the location of glimpsebin:/usr/bin/glimpse # location of the executable program glimpse

4) Add a file. htaccess content under $ installprefix/HTTP:
<Files ~ (Source | search | ident | diff | find) $> ***
Sethandler CGI-script
</Files>

The above file ensures that Apache server uses several Perl files as CGI-script.

5) follow the settings in lxr. conf to create dbdir and create a directory based on the preceding example.
/Home/httpd/html/lxr/dbdir
Run $ installprefix/bin/genxref yourdir in this directory.

Yourdir is the source code directory, such as/usr/src/Linux

If you want to combine glimpse, execute glimpseindex-H. yourdir

6) Modify/etc/httpd/CONF/access. conf and add

<Directory/home/httpd/html/lxr/HTTP>

Options all

AllowOverride all

Order allow, deny

Allow from all

</Directory>

7) enter/etc/rc. d/init. d/and execute

Killall httpd

./Httpd start

Go to X and use the browser http: // yourip/lxr/HTTP/blurb.html

You can easily read the source code.

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.