I started from the android kernel debugging. Among all possible debugging methods, kprobe looks good so that I wanted to try. (no other reason)
Kprobe is kind of run-time on-off-able hook. When off, there are no differences on kernel behavior with just minimized overhead. When on, you can make a hook on (almost) any position on the source code and register a callback function at that hook. When the source code at hook runs, your callback will be called. You can make and destroy hooks dynamically (on the fly).
So… my goal is to test kprobe on the real target. But one thing is, I had to re-build kernel with some KPROBE config. Putting a re-built kernel on the real target looks a little bit scary for me, so I wanted to test with emulator.
You can download android emulator at android site. I recommand to download ADT, a bundle with SDK and eclipse IDE (including emulator). Run eclipsse.
~/android/adt-bundle-linux-x86_64/eclipse$ ./eclipse &
At Windows -> Android Virtual Device Manager, you can create a profile of virtual device you want to emulate. Go to Device Definitions tab, select a model, press Create AVD button. I tried Nexus 7, but launcher app crashed infinitely so I changed to Galaxy Nexus and got no problem yet.
Go Android Virtual Devices and select the profile you just created, press Start button to run the emulator. Alternatively, you can run emulator by command:
~/android/adt-bundle-linux-x86_64/sdk/tools$ ./emulator -avd AVD_for_Galaxy_Nexus_by_Google
AVD_for_Galaxy_Nexus_by_Google is the name of your profile. You can check by
ls ~/.android/avd
Without much effort, I could see the emulator run. Next step is download the android kernel to replace with emulated one. I tried some googling result (including http://source.android.com/source/building-kernels.html) but when I replace the emulator with my kernel, emulator showed just a black screen. It looked like the kernel config problem, and finally I found this great page. The main thing is, instead of using default config (make goldfish_defconfig), getting the config of running kernel. It worked for me.
When you successfully finished to build kernel, you can replace the emulater kernel with yours.
~/android/adt-bundle-linux-x86_64/sdk/tools$ ./emulator -avd AVD_for_Galaxy_Nexus_by_Google -kernel ~/src/android/kernel/goldfish/arch/arm/boot/zImage
Finally, I ran make menuconfig to enable the Kprobe:
~/src/android/kernel/goldfish$ ARCH=arm make menuconfig
Check General setup -> Kprobes to enable kprobe. Also I checked Enable loadable module support gor further testing. Again run the emulator, and now I can test kprobe on the emulator.
Pingback: Running Kprobe example on Android Emulator | duyoungoh