带有 qemu 的 GDB 不会在断点处停止

问题描述 投票:0回答:1

我正在尝试使用 gdb 调试我的内核,但由于某种原因它不会在断点处停止

编译内核:

    gcc -g -Werror -nostdlib -o kernel.o -c kernel/main.c
    gcc -g -nostdlib -ffreestanding -e kmain -o kernel.elf kernel.o 

内核/main.c

int kmain(Bootinfo *Bootinfo) {
    
    for (;;);
}

这就是我从引导加载程序调用它的方式

    stat = uefi_call_wrapper(BS->ExitBootServices, 2, IH, mapkey);
    kmain(&bootinfo);

qemu

qemu-system-x86_64 -s -S -bios /usr/share/ovmf/OVMF.fd -drive file=/os.img,format=raw

和 gdb

target remote :1234
symbol-file kernel.elf
break kmain
continue
layout next

即使在

break kmain
之后,它也显示断点1位于0x1000:文件kernel/main.c,第5行 但在
continue
之后它就不会停止

c debugging gdb kernel bootloader
1个回答
0
投票

为了清理一点,这个问题有两个答案:

使用

nokaslr
启动参数禁用 KASLR,如下所示:使用 qemu 和 gdb 调试内核,断点不起作用?

或者你自己的后续问题调试 PIE 内核时 GDB 没有在断点处停止:使用

file <name> -o <offset>
来匹配 QEMU 中的内存重定位。

© www.soinside.com 2019 - 2024. All rights reserved.