kgdb调试环境搭建

来源:百度文库 编辑:神马文学网 时间:2024/04/28 17:04:40
vmware + kgdb + linux2.6.15内核调试配置
一、安装linux系统:
首先安装一个linux系统,然后Clone一个和预装环境一样的系统,选则"Create a full clone",命名为"rehl5-kgdb-server"。
分别为两个系统增加一个串口,以"use named pipe"方式,其中:
client端选择"this end is the client", "the other end is a virtual machine"
Server端选择"this end is the server", "the other end is a virtual machine"
二、下载所需的包:
linux kernel
http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.15.tar.gz
kgdb patch
http://kgdb.linsyssoft.com/downloads/kgdb-2/linux-2.6.15.5-kgdb-2.4.tar.bz2
将包放到/usr/src/kernels/目录下,并且解压:
tar zxvf linux-2.6.15.tar.gz
tar jxvf linux-2.6.15.5-kgdb-2.4.tar.bz2
cd linux-2.6.15-kgdb-2.4
对内核打好kgdb补丁
patch -p1 < ../linux-2.6.15.5-kgdb-2.4/core-lite.patch
patch -p1 < ../linux-2.6.15.5-kgdb-2.4/i386-lite.patch
patch -p1 < ../linux-2.6.15.5-kgdb-2.4/8250.patch
patch -p1 < ../linux-2.6.15.5-kgdb-2.4/eth.patch
patch -p1 < ../linux-2.6.15.5-kgdb-2.4/i386.patch
patch -p1 < ../linux-2.6.15.5-kgdb-2.4/core.patch
patch -p1 < ../linux-2.6.15.5-kgdb-2.4/module.patch
patch -p1 < ../linux-2.6.15.5-kgdb-2.4/sysrq_bugfix.patch
三、编译内核:
make menuconfig //配置内核选项
在这一步,因为是在VmWare中编译内核,有几个选项必须选择:
Device Drivers --->SCSI device support ---><*> SCSI disk support
Device Drivers --->SCSI device support --->SCSI low-level drivers ---> <*> BusLogic SCSI support
Device Drivers ---> Fusion MPT device support ---> Fusion MPT (base + ScsiHost) drivers
Device Drivers ---> Fusion MPT device support ---> Fusion MPT misc device (ioctl) driver
Device Drivers ---> USB support ---><*> USB Mass Storage support
为了支持kgdb,必须选上:
Kernel hacking:下面的
[*] kernel debugging
[*] compile the kernel with debug info
[*] kgdb,  kernel debugging with remote kgdb
[*] console messages through gdb
[*] simple selection of KGDB Serial Port
(115200) debug serial baud rate
[0] serial port number for kgdb
保存后,直接 make bzImage
四、移到server上面:
将/usr/src/linux/arch/i386/boot/bzImage和/usr/src/linux/System.map复制到server上,然后复制到/boot下:
cp bzImage /boot/vmlinuz-2.6.15-kgdb
cp System.map /boot/System.map-2.6.15-kgdb
创建symbolic链接(为什么是symbolic,参考俺关于文件系统的文章吧),这里可能先要执行 rm –rf vmlinuz System.map
ln -s /boot/vmlinuz-2.6.15.5-kgdb /boot/vmlinuz
ln -s /boot/System.map-2.6.15.5-kgdb /boot/System.map
下面就该修改启动项啦:
gedit  /boot/grub/menu.lst
添加下面的:
title rehl5 (2.6.15-kgdb)
root (hd0,0)
kernel /vmlinuz-2.6.15-kgdb ro root=/dev/VolGroup00/LogVol00 kgdb8250=0,115200 kgdbwait
然后reboot
系统引导到
"Uncompressing Linux... OK, booting the kernel."
所有的资料上都说看到
"Waiting for connection from remote gdb..."
第二句不一定有。
五、启动客户端进行调试:
就可以用client去连接了。在client上:
cd /usr/src/kernels/linux-2.6.15
gdb ./vmlinux
GNU gdb Red Hat Linux (6.0post-0.20040223.17rh)
Copyright 2004 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"...Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) set remotebaud 115200
(gdb) target remote /dev/ttyS0
Remote debugging using /dev/ttyS0
breakpoint () at kernel/kgdb.c:1212
1876            atomic_set(&kgdb_setting_breakpoint, 0);
上面“1876 atomic_set(&kgdb_setting_breakpoint, 0);”这一行表明已经连接上了。
(gdb)可以继续设置断点:break console_init  就是在console_init 设置断点
(gdb)输入c,也就是继续运行内核,然后跑到这个地方就可以停住。