如何使用QEMU和KGDB调试Linux内核?

如何使用QEMU和KGDB调试Linux内核?,第1张

概述我已经能够使用以下方式启动基于powerpc的系统(MPC8544DS具体)来调用qemu(v1.7.0) qemu-system-ppc -M mpc8544ds -m 512 -kernel zImage -s -nographic -initrd busyboxfs.img -append "root=/dev/ram rdinit=/bin/sh kgdboc=ttyS0,115200 k 我已经能够使用以下方式启动基于powerpc的系统(MPC8544DS具体)来调用qemu(v1.7.0)

qemu-system-ppc -M mpc8544ds -m 512 -kernel zImage -s -nographic -initrd busyBoxfs.img -append "root=/dev/ram rdinit=/bin/sh kgdboc=ttyS0,115200 kgdbwait"

其中zImage是一个自定义交叉编译的linux内核(v2.6.32),它启用并编译了KGDB(用于启动代码调试),busyBoxfs.img是基于busyBox的rootfs.

因为我正在使用-s标志到Qemu,所以我可以使用交叉gdb进入内核,如下所示:

(gdb) target remote localhost:1234Remote deBUGging using localhost:1234mem_serial_in (p=<value optimized out>,offset=5) at drivers/serial/8250.c:405405  }

但是,如果我删除-s标志并尝试通过/ dev / ttyS0闯入内核,它会给我一个权限被拒绝错误:

(gdb) set remotebaud 115200(gdb) target remote /dev/ttyS0permission denIEd

是因为它被Qemu控制了吗?另外在互联网上的示例中,kgdboc已经设置为ttyAMA0,我已经理解这是针对基于ARM的系统特定的AMBAbus.我们有类似PowerPC的东西吗?我在这里做错了吗?

解决方法 您似乎混淆了guest虚拟机的主机串行设备/ dev / ttyS0,以及客户机内核中QEMU自己的KGDB gdbserver.

QEMU通常没有理由触摸主机的串口.这样做的唯一原因是,如果您想拥有一台物理机主机QEMU,并有效地将其物理串口提供给客户机,那么您就可以使用通过实际串行电缆连接的不同物理机来调试客人.

当您使用-s标志时,您告诉QEMU运行自己的GDB服务器(默认情况下侦听主机环回TCP端口1234),允许您进入客户端上运行的任何程序,无论是内核还是引导程序或其他内容.这与guest虚拟机内核本身配合通过KGDB进行调试不同.

如果你想使用KGDB,你需要在内核版本中配置KGDB以使用模拟串行端口的客户端,然后告诉主机上的GDB使用该模拟端口的主机端.
QEMU command line documenation详细介绍了这一点:

DeBUG/Expert options:

‘-serial dev’
Redirect the virtual serial port to host character device dev. The default device is vc in graphical mode and stdio in non graphical mode.

This option can be used several times to simulate up to 4 serial ports.

一些更有趣的选项的缩略列表:

‘pty’
[linux only] Pseudo TTY (a new PTY is automatically allocated)

‘/dev/XXX’
[linux only] Use host tty,e.g. ‘/dev/ttyS0’. The host serial port parameters are set according to the emulated ones.

这是您不想要的 – 除非您想将串行电缆用于运行GDB的其他物理机器.

‘tcp:[host]:port[,server][,Nowait][,nodelay]’
The TCP Net Console has two modes of operation. It can send the serial I/O to a location or wait for a connection from a location. By default the TCP Net Console is sent to host at the port. If you use the server option QEMU will wait for a clIEnt socket application to connect to the port before continuing,unless the Nowait option was specifIEd. The nodelay option disables the Nagle buffering algorithm. If host is omitted,0.0.0.0 is assumed. Only one TCP connection at a time is accepted. You can use telnet to connect to the corresponding character device.

Example to send tcp console to 192.168.0.2 port 4444
-serial tcp:192.168.0.2:4444

Example to Listen and wait on port 4444 for connection
-serial tcp::4444,server

Example to not wait and Listen on ip 192.168.0.100 port 4444
-serial tcp:192.168.0.100:4444,server,Nowait

这是一个很好的常见选择.您可以使用基本相同的GDB语法,例如,如果指定环回接口地址127.0.0.1和端口1234,则可以使用与以前完全相同的GDB命令.

‘unix:path[,Nowait]’
A unix domain socket is used instead of a tcp socket. The option works the same as if you >had specifIEd -serial tcp except the unix domain socket path is used for connections.

假设您的GDB支持它,这也是一个不错的选择.

您可能需要首先配置其中一个选项,在没有KGDB的情况下运行并获取shell并确定调用模拟设备的客户端的内容,然后使用配置为使用它的KGDB重新启动.

总结

以上是内存溢出为你收集整理的如何使用QEMU和KGDB调试Linux内核?全部内容,希望文章能够帮你解决如何使用QEMU和KGDB调试Linux内核?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1025169.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存