Linux – Kernel Hacking Environment

debuggingdevelopmentkernellinuxserial-console

I have been working in embedded OS like uCOS, ThreadX. While I have coded apps in Linux, now I’m planning to start learning Linux Kernel. I have few questions regarding the environment.

  1. Which is best distro, which has easy to use tools for kernel development? (so far I had used RHEL and Fedora. While I am comfortable with these, it also looks like Ubuntu has in-built scripts for easy kernel compilation like make_kpkg, etc)

  2. Can you describe the best setup for kernel debugging? While debugging other embedded OSes, I have used serial port to dump progress, JTAG, etc. Which kind of setup does the Linux kernel devs use? (Will my testbed PC with serial port is enough for my needs? If yes, how to configure the kernel to dump to serial port?) I'm planning to redirect kernel messages to serial console which will be read in my laptop.

  3. What tool is best for debugging and tracing kernel code? As mentioned earlier, is serial console the only way? Or any IDE/JTAG kind of interface exists for PC?

Best Answer

My personal flavor for Linux Kernel development is Debian. Now for your points:

  1. As you probably guessed Ubuntu doesn't bring anything new to the kernel to ease development afaik, apart from what's already available in Debian. For e.g. make_kpkg is a Debian feature and not Ubuntu. Here are some links to get you started on common Linux Kernel development tasks in Debian:

  2. The easiest way to do kernel debugging is using QEMU and GDB. Some links to get you started:

    Though, you should be aware that this method is not viable for certain scenarios like specific hardware issues debugging and such, for which you would be better of using physical serial debugging and real hardware. For this you can use KGDB(it works using ethernet too). KDB is also a good choice. Oh, and by the way, both KGDB and KDB have been merged into the Linux Kernel. More on those two here. Another cool method, which works marvelously for non-hardware related issues, is using the User-mode Linux Kernel. Running the Kernel in user-mode as any other process allows you to debug it just like any other program(examples). More on User-mode Linux here. UML is part of the Linux Kernel since 2.6.0 , thus you can build any official kernel version above that into UML mode by following these steps.

  3. See item 2. Unfortunately there is no ultimate best method here, since each tool/method has its pro's and con's.

Related Question