Saturday, March 15, 2014

Setting up an environment to look at Linux source code


Just a quick note to remind myself of what to do when I look at Linux source files. In this case, I wanted the glibc source code. First, find the version you need:

[root@localhost rpmbuild]# rpm -q glibc
glibc-2.14.1-6.i686

Download the associated source file and install it. If you get warnings about the mockbuild user, run:

yum install mock
useradd -s /sbin/nologin mockbuild

What frustrated me for a while was where my files were after I ran rpm -ivh RPM_FILE

First, I ran this to see what files I was playing with:

[root@localhost Shared]# rpm -q -filesbypkg -p glibc-2.14.1-6.src.rpm
glibc                     glibc-2.14.1-fedora.tar.xz
glibc                     glibc-2.14.1.tar.xz
glibc                     glibc-fedora.patch
glibc                     glibc-ia64-lib64.patch
glibc                     glibc-ports-2.14.1-1-g3eb1dbf.tar.xz
glibc                     glibc-rh767696.patch
glibc                     glibc-rh794797.patch
glibc                     glibc.spec

But they didn't seem to have installed anywhere. Finally, I worked out that the files get put:

[root@localhost Shared]# ls -ltra ~/rpmbuild/SOURCES/
total 21972
-rw-rw-r--. 1 mockbuild mockbuild 10120512 Oct  7  2011 glibc-2.14.1.tar.xz
-rw-rw-r--. 1 mockbuild mockbuild   407660 Oct 28  2011 glibc-2.14.1-fedora.tar.xz
-rw-rw-r--. 1 mockbuild mockbuild   496968 Oct 28  2011 glibc-ports-2.14.1-1-g3eb1dbf.tar.xz
drwxr-xr-x. 4 root      root          4096 Dec 25  2011 ..
-rw-r--r--. 1 mockbuild mockbuild     8977 Feb 20  2012 glibc-rh794797.patch
-rw-r--r--. 1 mockbuild mockbuild     2789 Feb 20  2012 glibc-rh767696.patch
-rw-r--r--. 1 mockbuild mockbuild     4294 Feb 20  2012 glibc-ia64-lib64.patch
-rw-r--r--. 1 mockbuild mockbuild   143612 Feb 20  2012 glibc-fedora.patch
drwxr-xr-x. 2 root      root          4096 Mar 15 06:50 .

How frustrating. Follow this link to see how to apply the patches.

Update

Forgot to mention: if you want to step into the code using Eclipse, you'll need to add the debug information. This is how I did it for glibc:

First, get the version information:

[henryp@corsair ~]$ rpm -qa glibc
glibc-2.15-59.fc17.i686
glibc-2.15-59.fc17.x86_64

Then download and install it with:

[henryp@corsair ~]$ sudo debuginfo-install glibc-2.15-59.fc17.x86_64

Next time you debug (I'm using Eclipse IDE for C/C++ Developers, Kepler SR, Build id: 20140224-0627), you can step into glibc code!

No comments:

Post a Comment