logoalt Hacker News

nytputoday at 5:20 PM3 repliesview on HN

Because attaching a debugger to the Linux Kernel is so convenient and easy :P

But yeah, I was just being lazy and dumb. I solved it within ten minutes of someone saying "why don't you just go through the binfmt_elf code?" A debugger would've probably been more tedious than reading the relevant code directly, but would've been just as effective.


Replies

yjftsjthsd-htoday at 7:38 PM

So I'm no kernel dev and only did a web search out of curiosity... Based on https://www.kernel.org/doc/html/latest/process/debugging/gdb... and https://sergioprado.blog/debugging-the-linux-kernel-with-gdb... , it reads as if it's fairly easy so long as you're willing to compile the kernel yourself. Actually, at that point I would personally favor UML, since at that point Linux is just a normal userspace program that you can attach to: https://www.kernel.org/doc/html/latest/virt/uml/user_mode_li...

But I'm not a kernel dev and it's been a very long time since I would have needed to debug the kernel; does this not actually work?

saagarjhatoday at 5:41 PM

It's not and actually I do find it kind of amusing that Linux is possibly the hardest of the three main OSes to get a debugging set up for, but yeah I've had to do it enough that I don't mind doing and I can probably get it set up in a few minutes. Plus if the bug isn't in some architecture specific or hardware dependent thing there's this Linux compatibility userspace layer I help out on sometimes that is much easier to work with. And if it's that easy, I will generally choose to that instead of having to actually think about what I am doing ;)

tayo42today at 6:13 PM

I think you can do it with qemu and gdb.

Unless the other os and debugger mentioned has an easy way to do it with a machine that's not virtualized?