Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer runapp02.tex V2 - 09/04/2008 6:09pm Page 1173

Appendix B: Working with the Source Code


short stub code in the kernel to provide an interface to a debugger running on a second system. Because
GDBsupports remote debugging, the kernel can make use of this form of debugging, which features
breakpoints, single-step processing, and the like.

KGDB is not included in kernel 2.6.24, but after long years of struggle, it will have been included in kernel
2.6.26 by the time you are reading this. Patches are also available for older kernel versions in case you
need KGDB support for them.

Once you have obtained a kernel with KGDB support, the configuration includes the new menu item
Kernel hacking->KGDB: kernel debugging with remote gdbthat must be enabled. If the serial interface
is used for data transfer, the correct settings must be made for the particular hardware. Debug symbols
should, of course, also be included in the kernel binary.

Because KGDB is evolving rather dynamically at the time of this writing, you should refer to
Documentation/DocBook/kgdb.html(which can be generated withmake htmldocs) for information on
how to connectgdbto a running kernel.

B.6 User-Mode Linux


UML (User-Mode Linux) is a port of Linux to Linux itself. The kernel runs on a Linux box as a userspace
process — a setup that is not without a certain beauty.

This facilitates many applications that would be difficult or impossible to implement with a classic Linux
kernel on genuine hardware, above all the ability to successively test new kernel features without the
need for dozens of time-consuming restarts.

UML also supports the use of debuggers, either of thebuilt-in, console-based type or as external pro-
grams. This section briefly describes howDDDcan be used in conjunction with UML to provide versatile
options for analyzing the kernel and its data structures. As with KGDB, breakpoints can be set and
variables can be changed in memory; however, only a single system is needed.

ARCH=ummust be specified in the command line to indicate that the kernel is to be generated for UML and
not for the local processor (CROSS_COMPILEneed not be set as would otherwise be necessary for genuine
cross-compilation.) For example:

wolfgang@meitner>make menuconfig ARCH=um
wolfgang@meitner>make linux ARCH=um

To compile UML on an AMD64 architecture, you also need to addSUBARCH=i386. The default configura-
tion of UML is a reasonable setup for most purposes and need not be modified.

The compilation result is an executable file calledlinuxthat is located in the main directory of the kernel
sources. This file contains Linux as a user process.

You can debug UML in the same way as a normal Linux process. As Figure B-9 shows, it is also possible
to set breakpoints.

UML offers many other options; for example, shared use of a filesystem with the host for ease of data
exchange, or a setup of network connections between the host and UML (and even between several UML
Free download pdf