vmware + kgdb + linux2.6.15内核调试配置

来源:百度文库 编辑:神马文学网 时间:2024/04/28 07:04:06

vmware + kgdb + linux2.6.15内核调试配置

===================================================

作者:ietf AT doit.com.cn

引用请注明出处。

===================================================

从早到晚,整整一天啊,总算成功了。
首先看看配置吧:

系统配置:
vmware workstation 5.5.3
FC-5,内核2.6.15
具体可以参考《在VmWare Workstation中编译Linux2.6.20内核》(以下简称《2.6.20》)中“VmWare虚拟硬件环境:”和“VmWare原始系统内核环境”,完成系统的安装,命名系统为"FC-5-kgdb-client"。

Clone一个和预装环境一样的系统,选则"Create a full clone",命名为"FC-5-kgdb-server"。

分别为两个系统增加一个串口,以"use named pipe"方式,其中:
client端选择"this end is theclient", "the other end is a virtual machine"
Server端选择"this end isthe server", "the other end is a virtual machine"

文件下载:
进入client系统,从网上下载如下源文件。(之所以算泽2.6.15版本内核,是因为kgdb的patch目前最高只能支持到这个版本

linux kernel
http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.15.tar.gz
module-init-tools
http://www.kernel.org/pub/linux/utils/kernel/module-init-tools/module-init-tools-3.2.tar.gz
kgdbpatch
http://kgdb.linsyssoft.com/downloads/kgdb-2/linux-2.6.15.5-kgdb-2.4.tar.bz2

按照《2.6.20》所介绍方式,解压缩各个包。假设最终kernel和patch的路径如下:
/usr/src/linux
/usr/src/linux-2.6.15.5-kgdb-2.4

为内核打上kgdb的支持补丁(俺的过程如下,具体可以参考patch中README,选择需要得patch):

cd/usr/src/linux
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

按正常编译内核流程,进入makemenuxonfig阶段,除了《2.6.20》文中为了支持vmware中内核编译必须的选项,还需要加上如下内容:
http://kgdb.linsyssoft.com/images/xconfig-selection.jpg

但是这张图片有点老,仅供参考。最关键的一条,上面没有,就是:
Serial portnumber for KGDB,默认选项是1,需要改为零。(正是这一点,折磨了我一个晚上)

接着该干吗就干吗,直到make bzImage完成。

下面要做的工作就相对简单一点:
将/usr/src/linux/arch/i386/boot/bzImage和/usr/src/linux/System.map复制到server上,进入这两个文件所在目录,

cpbzImage /boot/vmlinuz-2.6.15.5-kgdb
cp System.map/boot/System.map-2.6.15.5-kgdb

创建symbolic链接(为什么是symbolic,参考俺关于文件系统的文章吧)

ln -s /boot/vmlinuz-2.6.15.5-kgdb /boot/vmlinuz
ln -s/boot/System.map-2.6.15.5-kgdb /boot/System.map

下面就该修改启动项啦:

vim/boot/grub/grub.conf

我的给大家做个参考吧:

default=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
titleFedora Core (2.6.15.5-kgdb)
 root (hd0,0)
 kernel/vmlinuz-2.6.15.5-kgdb ro root=/dev/VolGroup00/LogVol00kgdb8250=0,115200 kgdbwait
title Fedora Core(2.6.15-1.2054_FC5)
 root (hd0,0)
 kernel/vmlinuz-2.6.15-1.2054_FC5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
 initrd/initrd-2.6.15-1.2054_FC5.img

OK, reboot就等着重启吧。

系统引导到

"Uncompressing Linux... OK, booting the kernel."

所有的资料上都说看到

"Waiting for connection fromremote gdb..."

才是等待调试状态,可我看到的只是前面一句。再加上默认得串口选项没有看到资料提醒需要修改,所以总是无法连接。这两个综合起来,就一直折腾了整整一天。好在最后耐心的看patch的README才有所启发。


就可以用client去连接了。在client上:

cd /usr/src/linux
gdb ./vmlinux

GNUgdb Red Hat Linux (6.0post-0.20040223.17rh)
Copyright 2004 FreeSoftware Foundation, Inc.
GDB is free software, covered by the GNUGeneral Public License, and you are
welcome to change it and/ordistribute 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
1212           atomic_set(&kgdb_setting_breakpoint, 0);
warning: shared libraryhandler failed to enable breakpoint
(gdb)

下面就随心所欲,去折腾你的内核吧。

参考文档:
http://kgdb.linsyssoft.com/quickstart.htm
patch源码中README
《在VmWare Workstation中编译Linux 2.6.20内核》