Bochs GDB with Higher Half Kernel (x86-64)
Posted: Sat Feb 20, 2021 3:03 am
Not sure exactly what part of the title is relevant, but essentially the situation is this: I have a x86-64 kernel, which I was initially loading at virtual address 0xC0000000 using a custom bootloader. At that point I had full debug support via a combination of Bochs and GDB, as in, I could set and hit breakpoints anywhere in the entire address space. I decided to start loading the kernel at -2GB instead, as I was reading about the benefits of higher half kernels, so I made the relevant changes to do so in the bootloader, rebuilt libgcc and my kernel with `-mcmodel=kernel` and adjusted the link script to load at -2GB. To my surprise, everything seemed to work, with one exception: I find myself unable to set breakpoints in the kernel in either the Bochs internal debugger or in GDB. The symbol addresses seem to be correct -- `print &kmain` and `print &_init` within GDB seem to report the correct addresses -- and I can hit breakpoints in the bootloader perfectly fine. I just can't hit any breakpoints in the kernel binary itself. What's even stranger is that GDB does break upon hitting an interrupt handler, but even after that point isn't capable of inserting breakpoints.
I did some googling, and found someone who ran into a similar issue a while back but they had a different configuration and still never seemed to resolve the underlying issue.
Anyone else run into this problem and know a solution? Perhaps a bug in Bochs? The fact that it doesn't work even in the Bochs internal debugger leads me to suspect it, rather than GDB, is the culprit, but I haven't been able to get QEMU working with my bootloader to confirm.
I did some googling, and found someone who ran into a similar issue a while back but they had a different configuration and still never seemed to resolve the underlying issue.
Anyone else run into this problem and know a solution? Perhaps a bug in Bochs? The fact that it doesn't work even in the Bochs internal debugger leads me to suspect it, rather than GDB, is the culprit, but I haven't been able to get QEMU working with my bootloader to confirm.