DS-5 CE Android Debug
The ARM® DS-5™ Community Edition is an Eclipse plug-in that enables you to easily connect to Android targets for debug of NDK-generated code. It ships a customized version of gdbserver to be deployed with your debuggable application package (.apk), giving you more control over multi-threaded applications and processor registers such as the NEON™ ones. Better still, the DS-5 Debugger perspective eliminates the need for you to edit and run scripts from the command line, and also packs lots of productivity features that will help you create efficient and bug-free C/C++ code for Android apps.
To debug an Android package containing native C/C++ code you need to install DS-5 CE plug-ins and its prerequisite packages. If you haven't done so, see installation instructions.
If you are planning to debug your native code on an end user Android device, be aware that some products based on version 2.2 (Froyo) haven't got this feature enabled.
Replacing NDK's gdbserver
To use the DS-5 Debugger to debug native code, update the version of gdbserver in the Android NDK ...\toolchains\...\prebuilt directory with the version of gdbserver provided by DS-5. You can locate this file by selecting Help → ARM Extras... from the main menu. Ensure that you rename it to gdbserver. The gdbserver provided in DS-5 is based on a newer version of GNU's gdbserver and provides additional multi-threading capabilities, access to ARM NEON registers (when available), and improved stability.
Creating an Android Virtual Device to debug the app
If you haven't done so, configure your Android ADT plug-in to pick up your Android SDK installation. To do that, follow these steps:
- Select Window → Preferences → Android and click on Browse... then set the location of the SDK.
- Open the Android SDK and AVD Manager dialog box by selecting Window → Android SDK and AVD Manager.
- Expand the Available packages group and add SDK platforms as required. For example, Android SDK Platform Android 2.3.
- Create a new Android Virtual Device (AVD).
Using an Android device to debug the app
- Set up your device to allow installation of non-Market applications. On the device, go to Settings > Applications and enable "unknown sources" (on an Android 4.0 device, the setting is located in Settings > Security).
- Turn on USB debug. On the device, go to Settings > Applications > Development and enable USB debugging (on an Android 4.0 device, the setting is located in Settings > Developer options).
- Set up your system to detect your device. On Windows, you need to install a USB driver for adb. Find the correct driver for your device on: http://developer.android.com/sdk/oem-usb.html. For Linux hosts, check the correct procedure on the Android developer website.
- Now that you have installed the Android SDK, you need to add the location of adb to our path to allow the tools to find the binary to communicate with the device.
- On Windows: Open the System Properties from your Control Panel select Advanced and add the path to the “SDK Tools/platform-tools” directory to your Path variable in the System Variables dialog.
- On Linux: In the shell add the Path by executing something similar to “export PATH=$PATH:<path to SDK Folder/platform-tools> Now launch eclipse. On Linux you need to launch it from the same shell you used in step 4.
Building Your App for Debug
- Build the native code inside Android application using the ndk build scripts. For example in Cygwin from the NDK root directory run “ndk-build –C samples/hello-neon” to build the hello-neon example.
- With Android NDK r7 you can also run the same command on Windows command shell (i.e. “ndk-build.cmd –C samples/hello-neon”)
- Now that the native libraries are built you need to build the Android application from Eclipse. Create a new project in Eclipse by selecting File → New → Android → Android Project. Import your project code into Eclipse.
- Open the AndroidManifest.xml file to enable the application to be Debuggable. Click on the Application tab and select the Debuggable flag as True. Save the changes and close the file. tab.
- Build your Android project.
Installing the App and Connecting the DS-5 Debugger
- Go to the DS-5 Debug perspective. Window → Open Perspective → Other → DS-5 Debug.
- Create a new debug configuration from Run → Debug Configurations → DS-5 Debugger → Right click → New.
- In the connection tab of the new configuration, enter a name for your project and select a device to connect to from the Connections drop down box.
- In the Files tab select your project directory and the .apk you want to debug. The Process and Activity boxes should auto complete. The Android apk will be located inside the bin folder of your project.dsds.
- Next select the shared library containing symbols which you want to debug. For a arm v5 target the location is normally <project_folder>/obj/local/armeabi, for a v7 arm target the location is <project_folder>/obj/local/armeabi-v7.
- Select Apply and Debug to debug your application.
- The debugger will install your application, attach gdbserver to the native process of the application and connect DS-5 Debugger so that you can debug your application.