5

It seems this subject doesn't have a nice fully one place documentation.

Here are references without any solution. Can anyone contribute his knowledge for how to debug and trace in linux kernel and Android platform.

Some Links

Community
  • 1
  • 1
0x90
  • 39,472
  • 36
  • 165
  • 245
  • What sort of problem are your trying to debug? – Chris Stratton Dec 24 '12 at 22:47
  • I want to debug the kernel code as in eclipse, or visual studio. – 0x90 Dec 25 '12 at 03:55
  • 1
    Perhaps it's worth taking a minute to look at the word "debug" which is to say, de - bug. If one is not trying to understand (as a prelude to removing) a "bug" one is arguably not debugging, but rather just stepping through code out of curiosity. If you want to do that, you'd be far better off doing so on a simulator such as QEMU, than with the added frustrations of setting up to do so on real hardware. – Chris Stratton Dec 25 '12 at 04:07
  • debugging is not related to Eclipse. Eclipse is just an editor (or an IDE). It is not a debugger. (It might give some graphical interface to a debugger, ...). – Basile Starynkevitch Dec 25 '12 at 08:20

2 Answers2

5

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

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
  • A number of the phones do have a debug serial port that can be activated in the kernel configuration, though special wiring (very low voltage converters, etc) is often required. – Chris Stratton Dec 24 '12 at 22:48
  • Yes, I found this, page, which seems to indicate that it CAN be done via UBS, at least on some devices: http://bootloader.wikidot.com/android:kgdb – Mats Petersson Dec 24 '12 at 22:51
3

I write Linux device drivers for android. Using adb is the first choice tool for android developers. You can get the kernel logs using "adb shell cat /proc/kmsg" command. If you are working on a platform which provides a serial terminal, you can get these kernel logs from that. Using printk and kernel log is only tool I use to debug kernel code.

You can mount debugfs and get hardware specific information.

Android comes with a set of tools like stack utility to get stack traces, etc. I know there is not much documentation for android platform developers out there. Most documentation is for app development.

Punit Soni
  • 1,229
  • 3
  • 17
  • 26