KDB Getting Started Guide
When debugging kernel issues, it is useful to be able to track kernel execution and see its memory and data structures. This functionality is provided by the built-in kernel debugger KDB in Linux. In this article you know how to &http://www.aliyun.com/zixun/aggregation/37954.html ">NBSP;"
Use the features provided by KDB and how to install and set up KDB on a Linux machine. You also familiarize yourself with the commands you can use in KDB and the settings and display options.
The Linux kernel Debugger (KDB) allows you to debug the Linux kernel. This aptly named tool is essentially a patch of kernel code that allows the master to access kernel memory and data structures. One of the main advantages of KDB is that it does not need to be debugged with another machine: You can debug a running kernel.
It takes some work to set up a machine for KDB, because the kernel needs to be patched and recompiled. KDB users should be familiar with the Linux kernel's compilation (and to some extent familiar with the kernel internals), but if you need help compiling the kernel, see the Resources section at the end of this article.
In this article, we start with information about downloading KDB patches, patching, (re) compiling the kernel, and starting KDB. Then we take a look at the KDB command and study some of the more commonly used commands. Finally, let's look at some details about setting and displaying options.
Started
The KDB project is maintained by Silicon Graphics (see Resources for a link) and you will need to download the kernel version of the patch from its FTP site. The latest KDB version available (at the time of writing this article) is 4.2. You need to download and apply two patches.
One is a "public" patch that contains changes to the common kernel code, and the other is an architecture-specific patch. Patches can be obtained as bz2 files. For example, on a x86 machine running the 2.4.20 kernel, you will need kdb-v4.2-2.4.20-common-1.bz2 and kdb-v4.2-2.4.20-i386-1.bz2.
All of the examples provided here are for the i386 architecture and the 2.4.20 kernel. You will need to make the appropriate changes according to your machine and kernel version. You also need to have root permissions to perform these operations.
Copy the file to the/usr/src/linux directory and extract the patch file from a file compressed with bzip2:
#bzip2-D kdb-v4.2-2.4.20-common-1.bz2
#bzip2-D kdb-v4.2-2.4.20-i386-1.bz2
You get kdb-v4.2-2.4.20-common-1 and kdb-v4.2-2.4-i386-1 files.
Now, apply these patches:
#patch-P1
#patch-P1
These patches should be applied cleanly. Find any files that end with. Rej. This extension indicates that these are failed patches. If the kernel tree is not a problem, then the application of the patch will not have any problems.
Next, you need to build the kernel to support KDB. The first step is to set the CONFIG_KDB option. Use your preferred configuration mechanism (xconfig and menuconfig, etc.) to complete this step. Go to the Kernel hacking section at the end and select the built-in Kernel Debugger support option.
You can also choose the other two options according to your preferences. Select the Compile the kernel with frame pointers option (if any) to set the Config_frame_pointer flag. This yields better stack backtracking because the frame pointer registers are used as frame pointers rather than universal registers.
You can also select the KDB off by default option. This sets the Config_kdb_off flag and, by default, closes the KDB. We'll explain this in more detail in the following section.
Save the configuration and exit. Recompile the kernel. It is recommended that you perform "make clean" before building the kernel. Install the kernel in a common way and boot it.