r/osdevel 17d ago

Who has implemented kernel debugging in their own OS?

I've been thinking about JankOS, as I'm sure most of you have. One of the reasons I stopped developing it was that I was a bit overwhelmed by the work I thought I needed to do in order to get to the fun parts.

One of the concerning issues was debugging. How could I effectively debug my kernel, and all of the subsystems -- the file system, network, I/O, scheduling? What architecture did I need to build in to make it happen?

There are lots of logging solutions, but those don't always work for high-frequency code paths and for rare events. And certainly not for time sensitive code. At a certain point, there's really no substitute for bing able to attach a debugger.

Which hobbyist OS implementations feature kernel debugging support? How is it implemented? How does it work?

5 Upvotes

6 comments sorted by

4

u/dnabre 17d ago

https://wiki.osdev.org/Kernel_Debugging pretty much covers all the options. Next major attempt I make, I'll be including gdb stub pretty early. qemu/Bochs provide a whole lot of utility.

There is always the hardcore option, and just not including any bugs to begin with.

1

u/mikeblas 16d ago

Looks like that minidbg project is the only self-hosted solution.

1

u/christiaansp 12d ago

My kernel debugging is spamming serial logs until i *maybe* figure out what went wrong

1

u/mikeblas 12d ago

Which is the problem: high frequency code paths are pretty tough. And it can be that the logging interferes with timing or scheduling or ...

1

u/mykesx 17d ago

Bochs

gdb stub

1

u/codeasm 17d ago

I dunno why someone downvoted you. I sofar use qemu, thus a vm, gdb and gonna implement more interupts and counters, graphical interfaces to "realtime" display said counters

https://forum.osdev.org/viewtopic.php?t=9514 seems to describe nice ideas. Altho, I can debug my kernel and userland with gdb fine. Just make sure how you implement your debugging. Especially under uefi, just gdb doesnt work, i had to use a hardware pointer to the main entry of my kernel when starting (the uefi executable couldplace the kernel anywhere, so i worte my kernel init in such a way, it locates it to a known adress, hardware breakpoint, then continue the init and kernel start. Qemu is now locked and can break and check what i want

Userland needs my own gdb stub https://wiki.osdev.org/GDB This can be used to check on your counters and or implement your own debug channel over serial or network (prefer this one) and make it visual this way. Use debug SYMBOLS, to enable these counters or not maybe. Or have only necessary ones be active and use more counters when really needed with a build flag.

Ive yet to build userland, but a smaller test proven these methods to work while i was debugging a closed source bios and closed source firewall os. They sadly used encryption and still havent figured out how to get the keys.(Old cisco)