如何手动插入 Bochs 内置调试​​器将停止的断点? INT3 不起作用

How to manually insert a breakpoint that Bochs's built-in debugger will stop at? INT3 doesn't work

我正在使用 bochs 增强型调试器(bochs 带有 gui 的调试器),但它也在调试 BIOS 代码,这对我来说太复杂了。那么如何在代码的开头手动设置断点呢?

我尝试了 int3 但它并没有停止。

The osdev wiki 描述了关键特性:

Magic Breakpoint

When you're using Bochs with the internal debugger, you can trigger the debugger via a facility called magic breakpoints. To trigger a breakpoint, you can insert xchg bx, bx (in GAS syntax, xchgw %bx, %bx) anywhere in the code and Bochs will trap into the debugger as soon as it executes it. On real hardware this has no effect as it merely replaces the BX register with itself.

You should put the following line in your Bochs configuration file to have it listen to magic breakpoints:

magic_break: enabled=1

大概 Bochs 不会捕获 int3 因为正常的访客代码可能正在使用它。 (例如,如果您使用 Bochs 来调试调试器或具有调试功能的内核,您需要了解 int3 在来宾中的处理方式,而不是让 Bochs 吃掉它。)


显然还有一个 I/O debug-breakpoint 机制使用 out 指令将两个字输出到一个特殊的端口号 0x8A00,所以你可以让 Bochs 打破这种方式而不用做它在 xchg bx,bx 上中断。 xchg 方式绝对更易于使用(侵入性较小;drop-in NOP,无需寄存器设置)并且更紧凑。 OSdev.org 使用 C 来描述要输出的内容:

 //outputs a character to the debug console
 #define BochsConsolePrintChar(c) outportb(0xe9, c)
 //stops simulation and breaks into the debug console
 #define BochsBreak() outportw(0x8A00,0x8A00); outportw(0x8A00,0x08AE0);