Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug the NFC implementation of Android?

Tags:

android

gdb

nfc

This question can be decomposed into multiple smaller problems. The end result would be to be able to set a breakpoint in the C/C++ NFC implementation of a Galaxy Nexus (Android 4.1) device using a debugger such as gdb to examine it's internal state.

  1. Is it possible to replace the libraries on a Galaxy Nexus devices with ones that contain debugging symbols?
  2. Is it possible to use gdb to debug the C/C++ implementation of an Android device?
  3. Is it possible to cross-compile the NFC implementation of Android?
  4. Are there any examples of somebody trying something similar maybe with another library?

Update: Rooting the device and compiling Jellybean went well overall with some minor errors. In fact there are some very nice flags in the libnfc makefile which enable extensive output while communicating.

However there there is still a debugging problem. To debug libnfc (external/libnfc-nxp) i must attach myself to the process using the library which most likely is the Nfc Manager (packages/apps/Nfc). To debug an application i have to set the debuggable flag. If i rebuild the Nfc Manager the signature does not match the one already installed on the device which means adb install -r <file> won't work. adb uninstall com.android.nfc doesn't work either. Using the hard way of simply deleting the apk from /system/app creates the error INSTALL_FAILED_SHARED_USER_INCOMPATIBLE when i try to install the new one. At this point Nfc didn't work at all anymore and i had to reflash the stock image.

Any other ideas how to debug the libnfc library?

like image 426
mibollma Avatar asked Aug 26 '12 15:08

mibollma


People also ask

How do I run Android in debug mode?

For Android 4.2 and newer, Developer options is hidden by default; use the following steps: On the device, go to Settings > About <device>. Tap the Build number seven times to make Settings > Developer options available. Then enable the USB Debugging option.


1 Answers

In general, the answer is yes. The complete Android NFC implementation is part of the Android Open Source Project. Answers to the specific parts of your question:

  1. Yes, you need to unlock the bootloader and root your device to be able to mount the system partition in read/write mode, so you can replace the NFC library.
  2. Yes, you should be able to do remote debugging using gdb. I have never actually done this, though.
  3. Yes, just download the Android source and compile the relevant parts of the NFC stack. The relevant parts are in packages/apps/Nfc (NFC manager), external/libnfc-nxp (C library), frameworks/base/core/java/android/nfc (Java NFC API) and vendor/nxp (NFC chip firmware).
  4. Yes, see e.g. How to debug an App on Android with GDBSERVER? or https://www.google.com/search?q=remote+gdb+android. (This question may be relevant, too: Remote debugging with Android emulator)
like image 98
NFC guy Avatar answered Sep 22 '22 01:09

NFC guy