brett
brett

Reputation: 5649

how to debug x86 assembly

I am writing a VMM for intel x86 architecture. Most of the code contains x86 platform specific assembly and c code. Can some one help me how to debug the assembly code please including hardware data structures.

Upvotes: 1

Views: 6553

Answers (2)

Ray
Ray

Reputation: 1442

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. (Or use 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).

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.

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.

Upvotes: 3

Nathan Fellman
Nathan Fellman

Reputation: 127598

If this VMM is supposed to run on a Windows host, you should be able to debug the assembly using 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. It's a long read with many details, but I don't see how you can write a VMM without it.

Upvotes: 1

Related Questions