|
KGDB is a source level debugger for Linux kernel. It allows kernel developers to use GDB to debug the kernel in a similar way to the way application programs can be debugged. This kernel Debugger version is not distributed as a kernel patches but it is already included in the last kernel tree released. For more information concerning KGDB please click here Index
Major KGDB 2 features
KGDB documentationThe KGDB documentation is included in the kernel sources too. So you can have the KGDB internal documentation in different formats: sgmldocs (SGML), psdocs (Postscript), pdfdocs (PDF), htmldocs (HTML), mandocs (man pages) For example executing the make pdfdocs command in the Documentation/DocBook directory will be created the kgdb.pfd file. RequirementsHardware requirementsTwo machines are required for using KGDB. The machine that runs the kernel to be debugged is called test machine (or simply target); the machine that runs GDB is called the development machine (or host). Platforms supportedCurrently KGDB 2 has been tested on the following STM platforms:
Software requirementsThe development machine requires RedHat Enterprise Linux version 3 or later. For the GDB front end, please see the section written in this page. Preparing the kernelConfiguring the kernelUse the following command: make ARCH=sh CROSS_COMPILE=sh4-linux- gconfig To enable CONFIG_KGDB, enter under the "Kernel debugging" section and then select "KGDB: kernel debugging with remote gdb". The following picture shows an example of KGDB configuration, in this case the debug port selected is the ttyAS1.
FIG 1: example of KGDB configuration NOTE: while configuring, the help on line will give you more information concerning all KGDB options. Compiling the kernelUse the following command: make ARCH=sh CROSS_COMPILE=sh4-linux- clean vmlinux Configuring KGDB via command line arguments
Using GDB on the development machineYou must use the cross GDB installed with the EAR 2.0 distribution. You will find it in at following path /opt/STM/STLinux-2.0/devkit/sh4/bin/ Connecting GDB to the kernel debuggerOn your development machine simply execute the following:
GDB front endsGDB 6.3 provides a simple graphical interface. It may be useful to look at the source code during a debug section (doesn't allow you to set breakpoint etc.). You can enable it using the "-" GDB command.
FIG 2: GDB 6.3 session ddd (Data Display Debugger)GNU ddd is a graphical front-end for GDB; for more information about it please click here. To run the sh4-linux-gdb with ddd use the following command: ddd --debugger sh4-linux-gdb vmlinux Note: ddd must be used with --debugger sh4-linux-gdb option, infact, by default, it runs the host gdb while in this case it must run the cross gdb.
FIG 3: example: using ddd ECLIPSE for ST40You can debug the kernel by Eclipse, to do it you have to install the ST40 Linux Eclipse plugins. For more information concerning Eclipse for Linux ST40 (and to download the plugin) see the following link. Controlling the kernel executionStopping the kernel executionMagic SysRq supportIt enables console device to interpret special characters as commands to dump state information or to invoke the kernel debugger. To add this support in the kernel, enable the CONFIG_MAGIC_SYSRQ option during the configuration phase. On your target you can break the kernel, starting a debug section, simply writing the letter 'g' in the /proc/sysrq-trigger file as shown below.
Note: in the previous KGDB version 1 you could stop the kernel execution sending a break command ("Control-A F" using the minicom tool) and then the letter 'g' (within 5 seconds) in the system serial console. In the KGDB 2 this functionality has been removed. Using Ctrl+CTo stop kernel execution, press Ctrl+C on the GDB terminal. So KGDB will take control of the kernel and contact GDB. Note: if the GDB terminal doesn't respond to user input, you can close it sending an ASCII 3 character into the serial line as shown below. echo -e "\003" > /dev/ttyS1 If the kernel was controlled by KGDB when GDB was killed, a new GDB can be started but all your breakpoints, before setting, will be lost. Continuing the kernel executionTo continue kernel execution, use continue GDB command. GDB will tell the KGDB stub to continue kernel execution. Debugging the kernelUsing KGDB you can debug a kernel as a normal user application, for example you can place breakpoints, look at the stack and have information about the kernel threads. BreakpointsUse GDB break command to stop the kernel execution at a function or a source code line. The break command can be accepted as argument:
Stepping through codeThe GDB step command allows you to step a code statement. This command runs the kernel for one statement (entering into function calls too) and again hands over the control to GDB. If you want to skip stepping into function calls use GDB next command. Thread AnalysisGDB provides a listing of the kernel threads. So you can specify a particular thread to be analyzed and, using some GDB commands (like bt or info regi) get some information in context of the specified thread. Useful GDB commands for debugging thread:
Examining the StackYou can look at the stack trace using the following GDB commands:
Debugging the modulesIn this release GDB automatically is able to detect when a module has been loaded on the target machine so it can load the module object file into its memory for getting debugging information. To let GDB know where module files are located, set the variable solib-search-path.
Note: in order to understand where the lodable module symbols are located, GDB needs to be connected first to the target (where your modules have been loaded). This means that the command set solib-search-path /user/my_module_2.6/ must be run after the GDB has connected; otherwise it collects the symbols but it doesn't know where they are located. Similar issue may rise when you are debugging the module_exit function while threads, created by your module, are still runnig. Configuring GDB to debug a moduleTo make easier your debugging activity, we suggest you to define your personal set of GDB commands in the .gdbinit file; this is done with the define GDB command. Below a trivial example of .gdbinit file:
As soon as GDB connects and you get the prompt just type the name of your command:
Known limits
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||