How to use GDB in 16-bit mode?

后端 未结 2 379
清歌不尽
清歌不尽 2020-12-18 10:11

I have the following code, where I am trying to implement a function that prints string using the BIOS functions:

int printString(char* string)
{
 int i = 0;         


        
2条回答
  •  难免孤独
    2020-12-18 10:29

    Minimal QEMU example

    qemu-system-i386 -hda main.img -S -s &
    gdb -ex 'target remote localhost:1234' \
        -ex 'set architecture i8086' \
        -ex 'break *0x7c00' \
        -ex 'continue'
    

    where main.img is a boot sector.

    • break *0x7c00: the first instruction will not be your boot sector, but rather 0x0000fff0 which does the BIOS setup, see also. So we use this to start from where the boot sector gets loaded to.
    • set architecture i8086: for regular ELF executables, GDB can decide architecture from the headers. But for raw boot sectors, there is no such metadata, so we have to tell it.

    See also:

    • How to get source level debug info: How to do source level debugging of x86 code with GDB inside QEMU?
    • Similar questions: Low level qemu based debugging || Debug qemu with gdb || Debugging bootloader with gdb in qemu
    • Some more good ideas: https://stackoverflow.com/a/32960272/895245
    • How to step over int: How to step over interrupt calls when debugging a bootloader/bios with gdb and QEMU?

提交回复
热议问题