Linux Kernel Architecture

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

Appendix B: Working with the Source Code


by line (or, if desired, assembler statement by assembler statement) to view and modify data structures,
and to halt program flow at any point. This can only be done using special features made available by
the kernel in the guise of theptracesystem call described in Chapter 13.

In contrast to normal C programs, the kernel has no runtime environment provided by an external
instance — the kernel itself is responsible for ensuring that this environment exists for user-space pro-
grams. Consequently, it is impossible to debug the kernel with classical means.

Nevertheless, there are various ways of applying debuggers to the kernel, as this section describes. Even
though debugging the kernel is slightly more complicated than debugging normal programs, the valu-
able results make the extra effort worthwhile.

B.5.1 GDB and DDD


GDB stands forGNU debugger, the default Linux debugger. It is included with every distribution as
a ready-made binary that can be loaded using the appropriate packet mechanism. Of course, you are
also free to compile the sources available atwww.gnu.org(or on one of the many mirrors), although this
appendix does not discuss how this is done.

The debugger features very extensive options, and this appendix provides only a brief overview of their
use. A detailed description ofGDBis available in the guide (in makeinfo format) that comes with the tool;
it can be viewed usinginfo gdb, for example.

To debug a program (and in this respect, the kernelis no exception), the compiler must incorporate
special debug information in the binary file to yield all the necessary information on the relationship
between the binary file and the sourcecode. The-goption must be selected forgcc, as follows:

wolfgang@meitner>gcc -g test.c -o test

The size of the executable file grows considerably as a result of the debug symbols it contains.

-gmust also be activated during compilation. In earlier versions the option had to be entered under
CFLAGS_KERNELin the mainMakefile. However, during development of 2.5, a separate option,Kernel
hacking->Compile the kernel with debug info,was built into the kernel configuration to do this auto-
matically. TheCompile the kernel with frame pointersoption included in the same menu should
also be selected at the same time because it enables the limit for activation records or stack frames (see
Appendix C) and therefore supplies thedebugger with useful information.

GDBis able to do the following:

❑ Trace program execution line by line, in procedures and functions steps or in individual assem-
bler statements.
❑ Determine the type of all symbols used in the program.
❑ Display or manipulate the current values of symbols.
❑ De-reference pointers or access random memory locations of the program and read or modify
their values.
Free download pdf