Use kgdb to debug Linux kernel and Kernel Modules

Source: Internet
Author: User
Article Title: Use kgdb to debug Linux kernel and kernel modules. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

  1. Comparison of several kernel debugging tools

Kdb: Debugging can only be performed at the compilation code level;
The advantage is that two machines are not required for debugging.

Gdb: it lacks some essential functions when debugging A module. It can be used to view the running status of the kernel, including disassembly of kernel functions.

Kgdb: it is convenient to debug the kernel at the source code level. The disadvantage is that kgdb can only perform remote debugging, it requires a serial line and two machines to debug the kernel (you can also use vmware software to run two operating systems on the same host for debugging)

The method for using kdb and gdb to debug the kernel is relatively simple. Here we only describe how to use kgdb to debug the kernel.

  2. Software and Hardware preparation

Environment:

Elasticsearch (192.168.16.5 com1), a test machine target (192.168.16.30 com2), all pre-installed redhat 9; A Serial Line

Download the following software package:
Linux Kernel 2.4.23 linux-2.4.23.tar.bz2
Kgdb kernel patch 1.9 linux-2.4.23-kgdb-1.9.patch
Gdb gdbmod-1.9.bz2 for debuggable Kernel Modules

  3. OK, start

3.1 testing string line

After the serial port is physically connected, run the following command for testing. stty can set the serial port parameters.

Run the following command on developer:
Stty ispeed 115200 ospeed 115200-F/dev/ttyS0
Echo hello>/dev/ttyS0
Run the following command on target:
Stty ispeed 115200 ospeed 115200-F/dev/ttyS1
Cat/dev/ttyS1

If there is no problem with the serial line, it will display hello on the target screen.

3.2 installation and configuration

3.2.1 Installation

Download the linux-2.4.23.tar.bz2,linux-2.4.23-kgdb-1.9.patch,gdbmod-1.9.bz2 to the/home/liangjian directory of the developer.

* On the developer Machine

# Cd/home/liangjian
# Bunzip2 linux-2.4.23.tar.bz2
# Tar-xvf linux-2.4.23.tar
# Bunzip2 gdbmod-1.9.bz2
# Cp gdbmod-1.9/usr/local/bin
# Cd linux-2.4.23
# Patch-p1 <../linux-2.4.23-kgdb-1.9.patch
# Make menuconfig

Compile the following three items into the Kernel in the Kernel hacking configuration item

KGDB: Remote (serial) kernel debugging with gdb
KGDB: Thread analysis
KGDB: Console messages through gdb

Note that you must add the-g option when compiling the kernel.

# Make dep; make bzImage

Use scp to copy related files to target (other network tools can also be used)

# Scp arch/i386/boot/bzImage root@192.168.16.30:/boot/vmlinuz-2.4.23-kgdb
# Scp System. map root@192.168.16.30:/boot/System. map-2.4.23-kgdb
# Scp arch/i386/kernel/gdbstart root@192.168.16.30:/sbin
Gdbstart is a tool provided by kgdb to activate the kernel hook and make the kernel in the debugging status.

 

[1] [2] [3] [4] Next page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.