简体   繁体   English

如何调试 x86 程序集

[英]how to debug x86 assembly

I am writing a VMM for intel x86 architecture.我正在为英特尔 x86 架构编写 VMM。 Most of the code contains x86 platform specific assembly and c code.大部分代码包含 x86 平台特定的程序集和 c 代码。 Can some one help me how to debug the assembly code please including hardware data structures.有人可以帮助我如何调试汇编代码,请包括硬件数据结构。

Using GDB for debugging works well for x86, and if you want, you can turn on the TUI by using the -tui switch if it makes things easier.使用 GDB 进行调试在 x86 上效果很好,如果需要,可以使用 -tui 开关打开 TUI,如果它使事情变得更容易的话。 (Or use layout reg / layout next ). (或使用layout reg / layout next )。

The registers pane in TUI mode will highlight which registers changed in the last single-step (or since the last breakpoint). TUI 模式下的寄存器窗格将突出显示在最后一个单步中(或自上一个断点以来)更改的寄存器。

I find the documentation on this topic to be fairly tedious to search through, so here is the quick and dirty to get you started:我发现这个主题的文档搜索起来相当乏味,所以这里有一个快速而肮脏的入门指南:

    run                                start program execution
    break function-name                set breakpoint at function-name
    clear function-name                clear breakpoint at function-name
    continue                           continue execution after breakpoint
    si                                 next instruction, enter functions
    ni                                 next instruction, doesn’t enter functions
    disassemble                        function-name display function’s code
    info registers                     display values in registers
    display variable-name              show value of variable-name on breakpoint
    print variable-name                show value of variable-name
       p $register                     or the value of register
       p/x, p/d, p/c, p/f              … as hex, signed int, char, float
    x address                          examine memory at address
    x &variable-name                   examine value of variable-name

See also asm debugging tips at the bottom of the x86 tag wiki , especially strace to decode Linux system calls, or equivalent for other platforms.另请参阅x86 标签 wiki底部的 asm 调试提示,尤其是strace以解码 Linux 系统调用,或其他平台的等效项。

For whole-system debugging, if Bochs emulates the CPU features you're using, it has a built-in debugger which could be useful for debugging a hypervisor / VM-monitor.对于整个系统调试,如果 Bochs 模拟您正在使用的 CPU 功能,它有一个内置调试器,可用于调试管理程序/VM 监视器。

If this VMM is supposed to run on a Windows host, you should be able to debug the assembly using Visual Studio.如果此 VMM 应该在 Windows 主机上运行,​​您应该能够使用 Visual Studio 调试程序集。

If your problem is that you're unfamiliar with the necessary hardware structures, such as the VMCS, GDT, LDT, IDT, TSS and such, then I suggest you take the time to familiarize yourself with IA32, especially the Software Developer's Guide .如果您的问题是您不熟悉必要的硬件结构,例如 VMCS、GDT、LDT、IDT、TSS 等,那么我建议您花时间熟悉 IA32,尤其是Software Developer's Guide It's a long read with many details, but I don't see how you can write a VMM without it.这是一篇包含许多细节的长篇文章,但我看不出没有它如何编写 VMM。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM