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

我已经能够使用以下方式启动基于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:1234
Remote debugging using localhost:1234
mem_serial_in (p=<value optimized out>,offset=5) at drivers/serial/8250.c:405
405  }

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

(gdb) set remotebaud 115200
(gdb) target remote /dev/ttyS0
permission 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重新启动.

相关文章

/etc/sysctl.conf这个目录主要是配置一些系统信息,/etc/sys...
1.作用 useradd或adduser命令用来建立用户帐号和创建用户的起...
它们都是多模式编辑器,不同的是vim 是vi的升级版本,它不仅...
不管是我们在安装软件还是监测软件的使用性能,我们都要随时...
装好Tomcat7后,发现除了本机能访问外界访问不了,岂有此理。...
修改防火墙配置需要修改 /etc/sysconfig/iptables 这个文件,...