Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stepping through Linux kernel source code?

My aim is to learn how Linux works. I know there are smaller kernels out there- I have the Minix book but the problem is that whilst teaching the concepts is ok- I really want to learn the specifics of the linux kernel.

I have a copy of linux kernel source code. Is there any technique so that I could "launch" this source code and somehow step-through the code so I can see what is happening?

If not, what is the next best technique to learn exactly what is happening (including recommended books, blogs, tech docs etc)?

EDIT

Does the source code have good documentation for particular OS areas?

like image 442
user997112 Avatar asked Dec 12 '22 18:12

user997112


2 Answers

You can build the kernel in the "User Mode Linux" architecture, and run it as a normal process within another (Linux) OS. (Hint: RTFM, "make ARCH=um" )

Then you can run it under the debugger, set breakpoints anywhere or anything, it is just as a normal userspace task.

like image 142
MarkR Avatar answered Dec 14 '22 09:12

MarkR


http://www.amazon.com/Professional-Linux-Kernel-Architecture-Programmer/dp/0470343435/ref=sr_1_1?ie=UTF8&qid=1358373427&sr=8-1&keywords=professional+linux+kernel+architecture

I recommend this book over any other. This will explain pretty much how everything works and is still quite accurate.

The concepts are really what's important and this book will point you to the key functions inside the kernel so that you can get the details yourself. Simple things to read are some system calls, or just open up some core files and read through the functions and try and figure out what they do or just manually trace stuff.

If you want to single step a kernel you can use a virtualization software like QEMU and load up the kernel inside under debugging mode (QEMU has remote GDB support) and you can load the symbol table for the kernel kernel.syms (IIRC) into GDB and you can see exactly what is executing. This can be very slow though for the kernel running inside and is really only useful for debugging a development kernel but if you're willing to accept the slowdown then go for it.

As mentioned the best is to read the source, at least that's how I learned. Find the key functions for whatever functionality you want to see and it's not hard to step through the code and just see what happens (use something like TAGS or CSCOPE to make this easier).

like image 28
Jesus Ramos Avatar answered Dec 14 '22 09:12

Jesus Ramos