【问题标题】:How to debug Linux dom0 kernel in Xen如何在 Xen 中调试 Linux dom0 内核
【发布时间】:2012-06-05 21:41:45
【问题描述】:

我一直在破解 Xen 块驱动程序后端,并且在通过串行方式使用 kgdb 进行调试时遇到了一些困难。这是我的设置。我将 MacOS X 作为主机操作系统运行。我有两个 VirtualBox 虚拟机,称它们为开发和测试。 VirtualBox 被配置为给他们每个人一个连接到命名主机管道的 COM1 端口。然后我使用socat -d -d ./test-com1 ./dev-com1 连接两个端口。执行此操作后,我已验证我可以通过 echo hi > /dev/[ttyS0|hvc0] 或使用 socat 将文本纯文本从一个 VM 发送到另一个 VM。我还可以通过在 dev 上使用 socat 在启动期间从测试中获得控制台输出。

这是我的测试内核的 grub 条目:

menuentry 'Debian GNU/Linux, with Linux 3.3.6-xen-ljx-g6304e82 and XEN 4.1.2' --class debian --class gnu-linux --class gnu --class os --class xen {
        insmod part_msdos
        insmod ext2
        set root='(hd0,msdos1)'
        search --no-floppy --fs-uuid --set 0c98efb4-f40e-4f0e-a2d3-2ed39b0a5070
        echo    'Loading Linux 3.3.6-xen-ljx-g6304e82 ...'
        multiboot       /boot/xen-4.1.2.gz placeholder loglvl=all guest_loglvl=all com1=115200,8n1,0x3f8,4 console=com1,vga 
        module  /boot/vmlinuz-3.3.6-xen-ljx-g6304e82 placeholder root=UUID=0c98efb4-f40e-4f0e-a2d3-2ed39b0a5070 ro console=hvc0 console=tty0 earlyprintk=xen nopat quiet
        echo    'Loading initial ramdisk ...'
        module  /boot/initrd.img-3.3.6-xen-ljx-g6304e82
}

这是来自开发者:

user@jimmy:~/workspace/linux-3.3.6$ stty -F /dev/ttyS0 -a
speed 38400 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 0; time = 10;
-parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt -echoctl -echoke

这是来自测试:

root@sqtest:~# stty -F /dev/tty0  -a
speed 38400 baud; rows 25; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
ignbrk -brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt -echoctl -echoke
root@sqtest:~# stty -F /dev/hvc0  -a
speed 38400 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

一个示例开发会话(在进行echo hvc0,38400 &gt; /sys/module/kgdboc/parameters/kgdboc; echo g &gt; /proc/sysrq-trigger 测试之后):

user@jimmy:~/workspace/linux-3.3.6$ gdb vmlinux 
GNU gdb (GDB) 7.0.1-debian
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/paton/workspace/linux-3.3.6/vmlinux...done.
(gdb) set remotebaud 38400
(gdb) target remote /dev/ttyS0
Remote debugging using /dev/ttyS0
Ignoring packet error, continuing...
warning: unrecognized item "timeout" in "qSupported" response
Ignoring packet error, continuing...

当我使用 tty0 而不是上面的 hvc0 时,也会发生同样的事情。

在没有 Xen 的情况下使用我的内核时,我已经能够成功连接调试器,尽管串行 TTY 设置不同。我感觉这与 STTY 报告的选项有关,但我希望对这些事情了解更多的人能指出问题,以便我理解。

谢谢!

【问题讨论】:

  • 我非常困惑哪些部分是通过 Xen 完成的,哪些部分是通过 VirtualBox 完成的。能不能用原生的OS X串口工具直接和Xen盒子通信,以后再打VirtualBox端的问题?
  • 我不确定。我是内核调试的新手。您是否建议有一种方法可以在不使用 gdb 的情况下连接到内核并仅通过串行发送命令?
  • Hrm,也许这是另一个令人困惑的部分;我主要使用串行作为 console 来获取恐慌消息,而不是试图在正在运行的内核上使用 gdb。我只是想提出一些方法来减少移动部件的数量——VB、Xen、GDB,在多台机器和多个操作系统上,尝试一次调试很多。
  • 是的,这是真的。我正在探索的其他选项是尝试在 MacOS 上获取兼容的 gdb 版本并从主机进行调试,或者仅从开发 VM 内部运行测试 VM。我找到的教程处理的是后一种设置(即,从主机 Linux 机器中调试在来宾 VM 上运行的内核)。

标签: remote-debugging kernel xen


【解决方案1】:

事实证明你做不到。但是,这里有一个 Linux 补丁:

http://lists.xen.org/archives/html/xen-devel/2012-06/msg00326.html

这适用于 3.2 内核。我在同一个线程中发布了 3.3 的一个。此补丁支持通过 hvc 进行 kgdb 调试。

【讨论】:

    猜你喜欢
    • 2021-09-23
    • 1970-01-01
    • 2013-10-09
    • 2011-08-23
    • 1970-01-01
    • 1970-01-01
    • 2012-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多