Linux, Open Source & Ubuntu - eWeek




How to Set Up Android Platform Development and Debugging





  Table of Contents:
  1. How to Set Up Android Platform Development and Debugging
  2. Native Code Debug Setup
  3. Native Debugging

Most of the existing Android documentation is geared toward application developers utilizing the Java-based Android SDK. Documentation for Android at the platform level is rather sparse and includes fewer tools and support for developers. Here, Knowledge Center contributor Larry Schiefer discusses platform-level development for Android, and guides developers through Android platform source and tools setup, including how to set up native, platform-level debugging using Eclipse.

How to Set Up Android Platform Development and Debugging - Native Code Debug Setup
( Page 2 of 3 )

Native code debug setup

Eclipse needs to be configured to use a remote C/C++ target. For every service or application that uses native code that you wish to debug, you will need to do the following twelve steps:

Step No. 1: Create a C/C++ project for the application/service containing native code to debug. Eclipse’s CDT plug-in requires a project in order to be able to debug code. In most cases, platform native code will not be built with Eclipse and therefore will not have an Eclipse project. You will still need to create a project as a "dummy" and point it to the appropriate native source. In Eclipse, select the File menu, then select New C or C++ Project.

Step No. 2: Fill in the project name and uncheck the "Use default location" checkbox.

Step No. 3: Click the Browse button, navigate and select the top-level directory of your native code, and click OK. If your native code is built using "makefiles", you can select the "Makefile empty project."

Step No. 4: Click Finish.

Step No. 5: In the main Eclipse window, select the C/C++ project you just created in the Navigator or Package Explorer pane.

Step No. 6: From the Run menu, select Debug Configurations. In the dialog box, select "C/C++ Local Application" in the left pane, and click the "New launch configuration" icon in the upper left. In the right pane, give the new configuration a name, and select the project you created earlier.

Step No. 7: In the "C/C++ Application" box, find the executable image where the native code will run. For Android applications, find the executable image for "app_process" in the built Android source tree.

Step No. 8: Select the Debugger tab in the right pane. From the Debugger dropdown, select "gdbserver Debugger."

Step No. 9: In the "GDB Debugger" section, locate arm-eabi-gdb from the Android source tree's "prebuilt" directory.

Step No. 10: Uncheck the box next to "Stop on startup at."

Step No. 11: If you know the path to any external shared libraries (native) that are used by the code to be debugged, click on the "Shared Libraries" tab and add the directories.

Step No. 12: On the Connection tab, change the connection type to TCP. Click Apply.

Once configured, you can connect to your target and step through native code. Note: There is no way to auto-step from Java down to native code within the debugger. You will need to embed a "busy wait" in your native code to allow you to connect. A simple infinite poll works well:

#define DBG_HALT()  ({ volatile int i=0; while (i == 0); })

Insert DBG_HALT(); in the native code you would like to debug. Currently, there is no way to embed a hard-coded breakpoint in native code.



 
 
>>> More Linux, Open Source & Ubuntu Articles          >>> More By Larry Schiefer
 

FEATURED SPONSOR MESSAGE

Microsoft Sponsored Resource Center

Increase Your Microsoft Office 365 Knowledge! Dig inside this suite of cloud-based collaboration tools.

Watch the video >>

Brought to you by





Advertisement
eWEEK Quick LInks

 
Close this advertisement