Current Linux Kernel Debugging Techniques

How is Linux kernel live debugging done and what tools are used?

Another option is to use an ICE or JTAG controller, and GDB. This 'hardware' solution is especially used with embedded systems.

But for instance QEMU offers similar features:

  • start QEMU with a GDB 'remote' stub which listens on 'localhost:1234' : qemu -s ...,

  • then with GDB, you open the kernel file vmlinux compiled with debug information (you can take a look a this mailing list thread where they discuss the unoptimization of the kernel).

  • connect GDB and QEMU: target remote localhost:1234

  • see your live kernel:

      (gdb) where
    #0 cpu_v7_do_idle () at arch/arm/mm/proc-v7.S:77
    #1 0xc0029728 in arch_idle () atarm/mach-realview/include/mach/system.h:36
    #2 default_idle () at arm/kernel/process.c:166
    #3 0xc00298a8 in cpu_idle () at arch/arm/kernel/process.c:199
    #4 0xc00089c0 in start_kernel () at init/main.c:713

Unfortunately, user-space debugging is not possible so far with GDB (no task list information, no memory management unit reprogramming to see different process contexts, ...), but if you stay in kernel-space, that's quite convenient.

  • info threads will give you the list and states of the different CPUs

You can get more details about the procedure in this PDF:

Debugging Linux systems using GDB and QEMU.

what tool for debugging a linux kernel?

First, see related question Linux kernel live debugging, how it's done and what tools are used?. Try to use KDB or Ftrace.

Checking Linux Kernel Debugging option

To find out how your kernel was configured, check in the /boot/ directory. Depending on how your distro does things, there might be a config-* file, which shows the kernel configuration options that were used to build the kernel. Look for the debug settings (eg CONFIG_DEBUG_KERNEL).

Debugging Linux kernel code on Android platforms

The traditional method (which I use most of the time) is to simply add printk to the relevant sections of the code, and then read the code and fix whatever the problem is once you have narrowed it down. I believe this is generally what MOST kernel developers do (certainly all 6 of my colleagues in my team, and the five-six that work in a different group). [I work with Linux on PC's, not in Android devices, but it's essentially the same kernel...]

I'm sure kgdb can be used in some way, but it relies on having a suitable port (e.g. serial or ethernet) to connect the debugger via, serial is hard to find on modern PC's, and don't exist at all in mobile phones. Ethernet will be fine, but most mobile phones (and other Android platforms) tend to only have WiFi, and as far as I understand, that requires a whole other lot of software on top of the regular IP stack to make it work right. I don't beleive kgdb supports wifi.

Sorry I can't give you a better answer. [I see from your links that you didn't exactly find a good answer...]

Edit: However, maybe this will help at least sometimes:
http://bootloader.wikidot.com/android:kgdb



Related Topics



Leave a reply



Submit