kgdb linux内核,KGDB源码级的内核调试

KGDB源码级的内核调试

发布时间:2006-07-24 09:04:31来源:红联作者:tongxiaokun

kgdb调试linux内核(针对2.6内核)

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

下载相应的KGDB内核补丁。

从linux内核官方网站上下载对应的版本内核。对内核打补丁,打补丁时要根据KGDB的README和series文件说明,按顺序打。

软硬件准备

环境:

一台开发机developer(192.168.0.1com1),一台测试机target(192.168.0.2 com1),都预装redhat 9;一根串口线

测试串口线

物理连接好串口线后,使用一下命令进行测试,stty可以对串口参数进行设置

在developer上执行:

stty ispeed 115200 ospeed 115200 -F /dev/ttyS0

echo hello > /dev/ttyS0

在target上执行:

stty ispeed 115200 ospeed 115200 -F /dev/ttyS0

cat /dev/ttyS1

串口线没问题的话在target的屏幕上显示hello

=========== 通过串口 =============

在Kernel hacking配置项中将以下三项编译进内核

KGDB: Remote (serial) kernel debugging with gdb

KGDB: Thread analysis

KGDB: Console messages through gdb

*注意(1) Serial port number for KGDB 这个选项表示选择哪个串口,1表示ttyS1,0表示ttyS0。

使用scp进行将相关文件拷贝到target上(当然也可以使用其它的网络工具)

#scp arch/i386/boot/bzImage root@192.168.0.2:/boot/vmlinuz-2.4.23-kgdb

*在target机器上

编辑/etc/grub.conf文件,加入以下行:

#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

#

重起机器

在developer上的刚编译的内核源代码目录下,使用gdb命令调试新的内核。

# 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

如果成功的话,下面会出现进入断点的信息。

============ 通过网络 ============

变异内核的时候选择通过网络调试。

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

grub的设置

kernel vmlinuz ro root=/dev/hda1 kgdboe=@192.168.0.2/,◎192.168.0.1/

可以参考README文件。

在developer上的刚编译的内核源代码目录下,使用gdb命令调试新的内核。

# gdb vmlinux

(gdb) target remote udp:192.168.0.2:6443

如果成功的话,下面会出现进入断点的信息。

后记:

如果只vmlinux文件拷贝到其他机器上,也可以调试,但看不到断点处的代码,因为vmlinux所在的目录下面没有源代码。而且它使用的是绝对路径,vmlinux所在的路径改变了,也会看不到源代码。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值