Browse the Linux Kernel Source with LXR

LXR (stands for Linux Cross-Reference), is a great tool which indexes the source code of the Linux Kernel and allows you browse the source in your favorite browser (Firefox), with quick references for all functions/files referenced in that code. (it’s not limited to use in Linux Kernel though, and can be used to index any large project’s source code).

Whenever I need to touch the Linux Kernel code, I first open a new tab with LXR, another with Google ready to work, and a shell terminal ready for grep queries.

This post will deal with installing LXR on Ubuntu and making it work.


1. First we need to install Apache (http server) and related stuff:

sudo apt-get install apache2 libapache2-mod-perl2

sudo apt-get install libcgi-simple-perl libcgi-ajax-perl libhtml-parser-perl libtemplate-perl

2. Install LXR

sudo apt-get install lxr

3. Now we need to install Glimpse, which is a powerful indexing tool used by LXR:

First we need to download the latest version from Glimpse’s homepage. Click here to download.

Extract the tarball:

tar xzf glimpse-latest.tar.gz

Now we need to install flex (needed for installing glimpse)

sudo apt-get install flex

In the top directory of glimpse run these:

./configure

make

sudo make install

4. Open /etc/apache2/httpd.conf with your favorite text editor (vim) as root, and add these:

# Linux Cross Reference Stuff
Alias /lxr /usr/share/lxr
<Directory /usr/share/lxr>
Options All
AllowOverride All
</Directory>

5. Open the file /usr/share/lxr/http/.htaccess with your favorite text editor and add these:

<Files ~ (search|source|ident|diff|find)$>
SetHandler cgi-script
</Files>

6. Go to /usr/share/lxr/source/

7. Create a directory with the Kernel version number. For example:

mkdir 2.6.22

8. Download the Kernel Source from kernel.org into /usr/share/lxr/source/2.6.22

9. untar the source tarball inside the 2.6.22 directory

10. Add the version number to /usr/share/lxr/source/versions:

echo 2.6.22 > /usr/share/lxr/source/versions

11. Create a symbolic link to 2.6.22 to make also the default version displayed:

ln -s /usr/share/lxr/source/2.6.22 /usr/share/lxr/source/defversion

12. Generate the cross-reference (This might take a few minutes):

cd /usr/share/lxr/source/2.6.22/

genxref

glimpseindex -H . .

13. Give permissions to http server to read the files:

chown www-data.www-data .glimpse_*

chown -R www-data.www-data /usr/share/lxr/

chown www-data.www-data fileidx

14. restart apache

/etc/init.d/apache2 restart

15. Open /usr/share/lxr/http/lxr.conf with a text editor.

Change this line:

sourceroot: /usr/share/lxr/source/$v/linux/

into:

sourceroot: /usr/share/lxr/source/$v/

16. That’s it, now open firefox, and go to:

http://localhost/lxr/http/blurb.html


- Note: It’s possible to cross-reference multiple source code projects (or multiple kernel versions). See more information in the sites linked below.

You should be able to browse the Kernel source files like the screenshot below:


LXR Screenshot

LXR Screenshot


Enjoy :)


Credits:

Orandespike Blog

Glimpse

Eclectic’s Blog

If you enjoyed this post, make sure you subscribe to my RSS feed!

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

No related posts.

Tags: , ,

Tuesday, May 12th, 2009 Linux Kernel

6 Comments to Browse the Linux Kernel Source with LXR

  • Karthik Jayaprakash says:

    Hi buddy,
    One correction, before doing

    chown www-data.www-data .glimpse_*

    we need to do cd /root

    and also

    in /usr/share/lxr/http/lxr.conf

    the value of glimpsebin have to be changed to

    glimpsebin: <Directory glimpse has been installed/glimpse/bin

    It works fine for everything…………….Great work Buddy very helpful

  • Amir Watad says:

    @Karthik, thank you for you comment, and for the corrections. Pleased that you found it helpfull :)

  • ortseamo says:

    Thank You, good work. For me works perfectly, but I had to add: chmod a+rwx .glimpse_*

  • Amir Watad says:

    Happy to help :-)

  • Mike says:

    I’m looking for a little help with installing LXR as per your instructions. Everything fine until I click on “Browse the code”. Get a 404 error “URL /lxr/http/source/ not found. No directory called “source” under “/lxr/http” Any advice would be welcomed. Regards, Mike

  • jun yao says:

    Firstly,thank you for sharing it!But I have a problem: when I open a file of .c,it shows: warning:Cannot open the xref database.What should I do?

  • Leave a Reply

    my email
    my photo
    Hi,
    My name is Amir Watad. I have a BSc. in biomedical engineering from The Biomedical Engineering school , Technion , Israel, and a BSc. in electrical engineering from The Electrical Engineering school , Technion , Israel.
    I'm a Verification Engineer in Mellanox Technologies Ltd.
    I love Linux, the Command Line and the OpenSource Community.
    I used to write Poems (Arabic) when I was able to find time for this.
    May 2009
    S M T W T F S
    « Mar   Jun »
     12
    3456789
    10111213141516
    17181920212223
    24252627282930
    31  
    SEO Powered by Platinum SEO from Techblissonline

    Twitter links powered by Tweet This v1.7.4, a WordPress plugin for Twitter.