基于 qemu 的低级调试
我必须在 ARM 架构上测试一些低级代码。通常,在真实的板上进行实验是相当复杂的,所以我正在考虑 QEMU。
我想要得到的是某种调试信息,例如 printfs 或 gdb。我知道这对于 Linux 来说很简单,因为它实现了 QEMU Integrator 的设备驱动程序和 gdb 功能,但我不使用 Linux。我还怀疑从 Linux 内核源代码中提取这种功能会很复杂。
我正在从一些已经实现其中一项功能的简单操作系统中进行搜索。你有什么建议吗?
I've to test some low level code on an ARM architecture. Typically experimentation is quite complicated on the real board, so I was thinking about QEMU.
What I'd like to get is some kind of debugging information like printfs or gdb. I know that this is simple with linux since it implements both the device driver for the QEMU Integrator and the gdb feature, but I'm not working with Linux. Also I suspect that extracting this kind of functionality from the Linux kernel source code would be complicated.
I'm searching from some simple operating system that already implements one of those features. Do you have some advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不需要目标操作系统来调试 QEMU 内运行的代码——QEMU 已经为您做到了这一点。
具体来说,QEMU 支持从 GDB 进行远程调试——您可以使用适当的命令行选项运行 QEMU,它将导出 GDB 副本(在主机上运行)可以连接的接口。此时,您可以在 GDB 中调试该程序,就像在主机上运行它一样。
http://wiki.osdev.org/GDB 似乎有更多基本信息;可能不足以让您完全入门,但至少为您提供了基本概念以及一些在 QEMU 和 GDB 文档中查找的术语。跳过有关“实现 GDB 存根”的部分(该内容不适用于此处,因为 QEMU 已经有一个),并从“使用仿真器存根”部分开始。简而言之,您使用
-s
选项(在 localhost:1234 上导出 GDB 连接)和-S
选项(等待 GDB“继续”来启动 QEMU)。开始执行之前的命令),然后在主机上的 GDB 中输入target remote :1234
而不是run
。当然,您还需要使用 ARM 版本的 GDB,而不是本机 x86 版本。(此外,如果您愿意付费购买商业解决方案,CodeSourcery 的 ARM 工具链具有 IDE 集成,可以自动设置所有这些,包括支持“printf”打印到调试器控制台。这在物理板上工作同样,如果您有一个硬件调试器,关于我作为 CodeSourcery 员工的通常免责声明也适用 - 但我确实发现它非常容易使用。)
更新,2012: CodeSourcery 的工具链现在被称为Mentor Graphics Sourcery CodeBench,但以上所有内容仍然适用。
You don't need a target OS to debug code that's running inside QEMU -- QEMU already does that for you.
Specifically, QEMU supports remote debugging from GDB -- you can run QEMU with the appropriate command-line options and it will export an interface that a copy of GDB (running on the host machine) can connect to. At that point, you can debug the program in GDB pretty much just as if you were running it on the host machine.
http://wiki.osdev.org/GDB appears to have a bit more basic information; possibly not enough to completely get you started, but at least give you the basic idea and some terms to look for in the QEMU and GDB documentation. Skip over the bit about "Implementing GDB Stubs", which doesn't apply here since QEMU has one already, and start at the section on "Using Emulator Stubs". The short form is simply that you start QEMU with the
-s
option (export a GDB connection on localhost:1234) and the-S
option (wait for a GDB "continue" command before starting execution), and then in GDB on your host you saytarget remote :1234
instead ofrun
. Also, of course, you need to be using an ARM version of GDB rather than a native-x86 one.(In addition, if you're willing to pay for a commercial solution, CodeSourcery's ARM toolchain has the IDE integration to set all of this up automatically, including support for "printf" to print into the debugger console. That works on a physical board, too, if you've got a hardware debugger. Usual disclaimer about me being a CodeSourcery employee applies -- but I do find it very easy to use.)
Update, 2012: CodeSourcery's toolchain is now called Mentor Graphics Sourcery CodeBench, but all the above still applies.
我意识到我在这里解决的是您原来的问题,而不是您提出的解决方案(也许这更好?),但是要直接在目标上使用 GDB(或 Insight/GDB),请使用低成本的 JTAG 工具和 OpenOCD。可以在此处找到此类设置的示例以及如何实现它。
如果您有更大的预算,功能更齐全的 JTAG 调试器可能会很有用,例如 带有 bdiGDB 固件的 Abatron BDI3000,允许使用 GDB 通过以太网进行远程调试和设备编程,无需特殊驱动程序或目标调试代理。
I realise that I am addressing your original problem here rather than your proposed solution (perhaps that's better?), but to use GDB (or Insight/GDB) directly on the target, use a low-cost JTAG tool and OpenOCD. An example of such a set-up and how to implement it can be found here.
If you have a larger budget, a more fully featured JTAG debugger may be useful, such as the Abatron BDI3000 with bdiGDB firmware which allows remote debugging and device programming over Ethernet with GDB and no special drivers or target debug agent.
也许像 OKL4 这样的微内核可以满足您的需求?
Maybe a microkernel like OKL4 would suit your needs?