【问题标题】:problems to connect GDB over an serial port to an KGDB build Kernel通过串行端口将 GDB 连接到 KGDB 构建内核的问题
【发布时间】:2013-01-13 02:49:38
【问题描述】:


我想通过串行 ttyS0 从我的 64 位 suse 机器上调试 MIPS linux 驱动程序。使用的 gdb 在 LAN 上可以更好地用于调试应用程序,但不能通过串行方式使用 kgdb。我用这个page 和其他几个开始调试,但没有最终结果。

我的内核是使用以下设置编译的:

CONFIG_MAGIC_SYSRQ=y
CONFIG_HAVE_ARCH_KGDB=y
CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y
# CONFIG_KGDB_TESTS is not set
CONFIG_CMDLINE="kgdboc=ttyS0,115200"

如果我运行 gdb:

gdb vmlinux
(gdb) set remotebaud 115200
(gdb) set debug remote 1
(gdb) target remote /dev/ttyS0

我可以观察到以下输出:

输出(GDB_TERMINAL):

(gdb) target remote /dev/ttyS0
Remote debugging using /dev/ttyS0
Sending packet: $qSupported:qRelocInsn+#9a...Ack
Timeout in mid-packet, retrying
Timed out.
Timed out.
Ignoring packet error, continuing...
Packet qSupported (supported-packets) is supported
warning: unrecognized item "qSupported:qRelocIns" in "qSupported" response
Sending packet: $Hg0#df...Nak
Sending packet: $Hg0#df...Ack
Packet received: Hg0
Sending packet: $?#3f...Packet instead of Ack, ignoring it
Ack
Timed out.
Timed out.
Timed out.
Ignoring packet error, continuing...
Sending packet: $Hc-1#09...Nak
Sending packet: $Hc-1#09...Ack
Reply contains invalid hex digit 36

输出(REMOTE_TARGET):

+$?#3f09n+#9a$Hg0#df+09

什么都没有发生!!!

我也测试了 sysrq,但提到的 sysrq-option 'g' 似乎不适合!

echo b > /proc/sysrq-trigger 
#successfully reboot

echo g > /proc/sysrq-trigger 
#prints only the help message (SysRq : HELP : loglevel(0-9) reBoot Crash termin .....)

sysrq 是否正常运行?
有什么我错过的吗?
有没有办法在我的远程设备上测试正在运行的 kgdb?

【问题讨论】:

标签: c linux linux-kernel kernel kgdb


【解决方案1】:

我在通过串行链接使用 kgdb 运行 gdb 时遇到了很多问题。我的主机是 Intel x86 Linux 机器,目标是 ARM 32 位 Raspberry Pi 2。目标与 USB to TTL Serial Cable 连接。以下是关键问题及其解决方案。

1) 不要同时使用gdbscreenminicom

在 tty 上连接minicom 时,GDB 挂起然后崩溃:

(gdb) target remote /dev/ttyUSB0
Ignoring packet error, continuing...
Ignoring packet error, continuing...
Ignoring packet error, continuing...
Ignoring packet error, continuing...
/build/gdb-cXfXJ3/gdb-7.11.1/gdb/thread.c:89: internal-error: inferior_thread: Assertion `tp' failed.
A problem internal to GDB has been detected, further debugging may prove unreliable.```

screen连接时,GDB连接失败:

(gdb) tar rem /dev/ttyUSB0
/dev/ttyUSB0: Device or resource busy.

2) 损坏的数据包和超时

无效数据包,错误校验和,看到新数据包在旧数据包中间开始,超时

使用支持目标架构的 GDB。 x86 上的默认 GDB(至少在 Ubuntu 上)不支持 arm 目标。请改用gdb-multiarch 或与交叉编译工具集对应的GDB,即arm-linux-gnueabihf-gdb。使用(gdb) set architecture 命令列出可用架构。在我的例子中,auto 架构正确地检测到了手臂目标。

3) 连接前必须在目标上触发 KGDB

远程意外回复“vMustReplyEmpty”:vMustReplyEmpty

对偏移量查询的错误响应,qOffsets

GDB 尝试连接,但目标未处于调试模式。在连接 GDB 之前必须触发调试 sysrq。键盘快捷键对我不起作用。以 root 身份通过 SSH 运行命令 echo g > /proc/sysrq-trigger

4) 配置波特率

警告:无效的波特率 115200。最大值为 38400。 /dev/ttyUSB0: 参数无效。

配置的波特率必须在kgdboc 内核参数和 GDB 之间匹配。就我而言,不支持波特率 115200。按照建议将波特率设置为 38400 是必要的。使用内核命令行重启目标:kgdboc=ttyAMA0,38400,然后:

(gdb) set remotebaud 38400
(gdb) target remote /dev/ttyUSB0
Remote debugging using /dev/ttyUSB0
0x800b4730 in kgdb_breakpoint ()

一旦解决了这些问题,内核调试就会按预期工作。

【讨论】:

    【解决方案2】:

    我知道这是 2 年前的事,但我只想说我的主板也有同样的问题,很遗憾它没有 LAN 接口来通过 TCP 连接使用 gdbserver。我不知道你是否能解决这个问题,但如果你的主板确实有一个 LAN 接口(或者你可以使用 USB 到以太网适配器构建一个),那么似乎可以通过它进行调试!

    【讨论】:

      猜你喜欢
      • 2014-05-02
      • 2018-07-10
      • 2023-03-21
      • 2023-04-04
      • 2019-09-30
      • 2020-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多