kgdb over ethernet

王者归来 posted @ 2010年1月17日 04:57 in kgdb with tags kernel debug kgdb , 4821 阅读

最近项目需要用到kgdb,而目标机没有串口,唯一能用的就是网口。

linux 2.6.31 中默认已添加对kgdb通过串口调试的支持,但是不支持通过ethernet调试。

求助于google,得patch和文档,特将过程记录如下,以供后来者参考。

 

1. 下载patch

patch 下载地址:

http://kernel.org/pub/linux/kernel/people/jwessel/branches/

要调试内核的版本为 2.6.31.4, 上面提供的patch最新也只到 2.6.30

但因为kgdb在设计之初,就特意保持的与内核其它部分尽可能的独立。

所以,试试运气,下载2.6.30的patch。

http://kernel.org/pub/linux/kernel/people/jwessel/branches/kgdb_2.6.30.tar.bz2

结果也证明可以用。

 

2. 打patch

patch包里共有16个patch, 具体用途可参考patch开头的注释。

这里需要打上3个patch

0009-kgdb-Add-the-ability-to-schedule-a-breakpoint-via-a-.patch
0010-NET_POLL-Pass-skb-via-NET_POLL-rx-routine.patch
0011-kgdb-Implement-kgdb-over-ethernet-with-NET_POLL.patch
后两个是为添加kgdb over ethernet 的支持,但是用到了0009 patch中定义的函数。

$ patch -p1 < ~/kgdb/kgdb_2.6.30/0009-kgdb-Add-the-ability-to-schedule-a-breakpoint-via-a-.patch

$ patch -p1 < ~/kgdb/kgdb_2.6.30/0010-NET_POLL-Pass-skb-via-NET_POLL-rx-routine.patch

$ patch -p1 < ~/kgdb/kgdb_2.6.30/0011-kgdb-Implement-kgdb-over-ethernet-with-NET_POLL.patch

 

 

3. 修改内核选项

要将以下选项编译进内核:

 

CONFIG_FRAME_POINTER
CONFIG_KGDB
CONFIG_KGDB_SERIAL_CONSOLE
CONFIG_KGDBOE
CONFIG_DEBUG_INFO

 

 同时需要将被调试机上的网卡驱动编译进内核,不能编为模块。

 

4. 修改内核启动参数

设置,

被调试的机器 ip 为 192.168.0.2,默认使用的端口为6443

主机 ip 为 192.168.0.1 ,默认使用的端口为6442

添加以下内容到内核启动参数:

kgdboe=@192.168.0.2/,@192.168.0.1/ kgdbwait

kgdbwait 使用内核在启动时停止,等待主机的连接。

详细参数的含义,参考官方文档:

http://kernel.org/pub/linux/kernel/people/jwessel/kgdb/ch03s04.html

 

5. 连接

首先将两台机器直接用网线连接起来,启动被调试的机器。

如果一切正常,它会在启动时候暂停。

这时,在主机用gdb去连接。

 

$ (gdb) target remote udp:192.168.0.2:6443
warning: The remote protocol may be unreliable over UDP.
Some events may be lost, rendering further debugging impossible.
Remote debugging using udp:192.168.0.2:6443
kgdb_breakpoint (new_kgdb_io_ops=<value optimized out>) at kernel/kgdb.c:1747
1747		wmb(); /* Sync point after breakpoint */
(gdb) c
Continuing.

 

 

6.  调试注意事项

(1)  如果两台机器是在局域网内,会出现下面提示,

(gdb) target remote udp:192.168.0.2:6443
warning: The remote protocol may be unreliable over UDP.
Some events may be lost, rendering further debugging impossible.
Remote debugging using udp:10.99.22.254:6443
warning: Invalid remote reply:
Remote failure reply: E22
表现为连接成功,但不能调试。

这是因为kgdb使用的是非常简单的网络栈,局域网中各种各样的包会扰乱kgdb。

所以最好是将两台机器直接用网线连接,以避免不必要的干扰。

 

参考资料:

http://kernel.org/pub/linux/kernel/people/jwessel/branches/

http://kernel.org/pub/linux/kernel/people/jwessel/kgdb/index.html

http://blog.csdn.net/xianfengdesign/archive/2008/06/19/2564222.aspx

 

 

 

 

Annita 说:
2011年12月28日 14:36

你手頭還有這個patch嗎?我在網上已經找不到這個patch了。如果有請發到我郵箱裏,annita.zhang@gmail.com。多謝多謝!

maid agency dubai 说:
2021年9月19日 19:28

A number of cleaning services exist that will help to accomplish the task. But prior to that, since the workplace belongs for you, you want to get a short idea about how exactly you could setup the environment. In addition to that particular, you may also go via various guidelines of cleansing. This will lower your stress concerning the matter.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter