Connecting to Debug Kernel
  Home
  Introduction
  Getting KGDB
  Documentation
  Using KGDB
  Credits
  Miscellaneous
  Troubleshooting
  FAQ
  Support
  About KGDB
  KGDB Pronew

 

Set the speed of the serial line on development machine to the value you have given to KGDB kernel on the test machine. Start GDB from the kernel source directory giving it the vmlinux file on command line as the object file. Run the KGDB kernel on the test machine and wait till it prints a message:
Waiting for connection from remote gdb...

If you are using KGDB for Linux 2.6.8-rc1 onwards then you would not see the above message as the KGDB uses early_param(). You will see a the following line after you choose the boot option in GRUB:
Uncompressing Linux... Ok, booting the kernel.

Then connect to the target machine from GDB using target remote command. This command needs the serial line path to be specified as an argument. At this point GDB and the KGDB stub will be connected and GDB will have a control of the target kernel. You can now use GDB commands for inserting breakpoints, printing values of variables, breaking and continuing execution.

An example of above procedure is given below:
On development machine:

1. Set appropriate speed for serial line.

$ stty ispeed 115200 ospeed 115200 < /dev/ttyS1

2. Start GDB. It will take some time because vmlinux contains a lot of debugging information. If you want to debug modules also, you'll need to download a GDB from this site. Please refer to module debugging setup for details. I have placed it at the path /usr/local/bin/gdbmod on my machine. I change the name so that I don't use that gdb accidentally for application debugging also. You can use the default gdb that comes with redhat installation provided you don't want module debugging.

[amit@askii-pc amit]$ cd /mnt/work/build/old-pc/linux-2.4.6-kgdb
[amit@askii-pc linux-2.4.6-kgdb]$ gdbmod vmlinux
GNU gdb 20000204
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb)

On test machine:

3. Select kgdb kernel from lilo prompt The kernel will start and after doing some initializations, wait for gdb to connect. It will write following prompt on the console:
Waiting for connection from remote gdb...

On development machine:

4. Connect to the test machine using gdb command "target"

(gdb) target remote /dev/ttyS1
Remote debugging using /dev/ttyS1
breakpoint () at gdbstub.c:1153
1153    }
(gdb)

5. Now gdb is connected to the kernel. It is waiting for a command. Use the continue command to let the test kernel proceed.

(gdb) c
Continuing.

The test kernel continues here and the system boots as usual. If console messages through gdb was selected while configuring the kernel, console log will appear here from gdb as follows:
PCI: PCI BIOS revision 2.10 entry at 0xfb230, last bus=0
PCI: Using configuration type 1
PCI: Probing PCI hardware
Limiting direct PCI/PCI transfers.
Activating ISA DMA hang workarounds.
isapnp: Scanning for PnP cards...
isapnp: No Plug & Play device found
Linux NET4.0 for Linux 2.4
Based upon Swansea University Computer Society NET3.039
Starting kswapd v1.8

Now gdb is connected to the test kernel. If a kernel panic situation occurs, instead of declaring a panic, the kernel will first give control to gdb so that it the situation can be analyzed.