KGDB source code-level kernel debugging

Source: Internet
Author: User
KGDB source code-level kernel debugging-general Linux technology-Linux programming and kernel information. The following is a detailed description. Kgdb Linux kernel debugging (for the 2.6 kernel)

Http://kgdb.linsyssoft.com/downloads.htm

Download the corresponding KGDB kernel patch.

Download the corresponding kernel version from the Linux kernel official website. Install patches on the kernel. During the patching process, install patches in sequence based on the kgdb readme and series files.

Software and Hardware preparation

Environment:
One developer (192.168.0.1com1) and one testing machine target (192.168.0.2 com1) are pre-installed with redhat 9 and one serial line


Test 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/ttyS0
Cat/dev/ttyS1

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

====================Through the serial port ==================

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: (1) the Serial port number for KGDB option indicates the Serial port to be selected, 1 indicates ttyS1, and 0 indicates ttyS0.

Use scp to copy related files to target (other network tools can also be used)
# Scp arch/i386/boot/bzImage root@192.168.0.2:/boot/vmlinuz-2.4.23-kgdb


* On the target machine

Edit the/etc/grub. conf file and add the following lines:
# Vi/etc/grub. conf
Title Red Hat Linux (2.4.23-kgdb)
Root (hd0, 0)
Kernel/boot/vmlinuz-2.4.23-kgdb ro root =/dev/hda1
#

Restart the machine


Use the gdb command to debug the new kernel under the compiled kernel source code directory on developer.


# Gdb vmlinux
GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)
Copyright 2003 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 "i386-redhat-linux-gnu "...
(Gdb) set remotebaud 115200
(Gdb) target remote/dev/ttyS0

If it succeeds, the following information appears.


====================Through the network ==================

When mutating the kernel, select Network debugging.

Method for KGDB communication (KGDB: On ethernet-in kernel)

Grub settings

Kernel vmlinuz ro root =/dev/hda1 kgdboe = @ 192.168.0.2/, ◎ 192.168.0.1/
You can refer to the README file.

Use the gdb command to debug the new kernel under the compiled kernel source code directory on developer.

# Gdb vmlinux

(Gdb) target remote udp: 192.168.0.2: 6443

If it succeeds, the following information appears.


Postscript:

If only the vmlinux file is copied to another machine, debugging can also be performed, but the code at the breakpoint cannot be seen, because there is no source code in the directory where vmlinux is located. In addition, it uses an absolute path. If the path of vmlinux is changed, the source code cannot be seen.
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.