This tutorial describes how to debug the
provided with the Android Native Development Kit (NDK).
It uses the Android SDK Platform 2.2 and the Android emulator as
It does not describe how to install any of the Android tools. See the Android Developers website for more information.
Before you can debug an Android package containing native C/C++ code you must:
Download and install the Android Software Development Kit (SDK). This enables you to build Java applications together with any native C/C++ code into an Android package with a
Download and install the Android NDK. This is a companion tool to the Android SDK that enables you to build performance-critical parts of your applications in native code such as C and C++ languages.
On Windows, you must also download and install cygwin, including the make package so that you can run the scripts inside the Android NDK.
Update the version of gdbserver in the relevant Android NDK toolchain directory by copying the Android version provided with DS-5
. This tutorial uses the
Set up the Eclipse plug-in for Android:
Install the Android Development Tools (ADT) Eclipse plug-ins.
Select Window → Preferences → Android and click on Browse... to set the location of the Android 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.2.
Create a new Android Virtual Device (AVD).
Edit the Android NDK script file,
ndk-gdbto debug using DS-5. The Android NDK contains a script file to run gdbserver and the application on the target before launching the debugger. By default, the script file is not set up to debug using DS-5. To change this behavior you must comment out the last line as shown:
#$GDBCLIENT -x `native_path $GDBSETUP`
To debug the application:
hello-neonsource files with debug information using the scripts provided by the Android NDK. This tutorial uses the
...\toolchains\arm-eabi-4.4.0\prebuiltdirectory. For example:
./ndk-build -C samples/hello-neon NDK_TOOLCHAIN=arm-eabi-4.4.0 NDK_DEBUG=1
Create a new Android project:
Select File → New → Project...
Expand the Android group and select Android Project.
Enter a suitable project name. For example,
Select Create project from your existing source and locate the
Leave the Use default location option selected so that the project is created in the default directory shown. Alternatively, deselect this option and browse to your preferred project directory.
Select the required Build Target. For example, Android 2.2.
Enter a suitable Application name. For example,
Enter a suitable Package name. For example,
Enter a suitable Activity name. For example,
Ensure that the application builds with debug information. You can do this by:
Click on the Application tab.
Select true in the Debuggable field.
Save the changes and close the file.
Clean and rebuild the Android project.
If the application is already installed on the target you must uninstall it. For example:
path\adb uninstall com.example.neon
Install the application. For example:
path\adb install samples/hello-neon/bin/HelloNeon.apk
ndk-gdbscript to start the application and connect gdbserver. For example:
./ndk-gdb --project=samples/hello-neon --verbose --port=5000 --start --force --adb=adb
See the Android NDK documentation for more information on using the script file and the command-line options.
Connect DS-5 to the application using a gdbserver TCP connection:
Select Debug Configurations... from the Run menu.
Select DS-5 Debugger from the configuration tree and then click on New to create a new configuration. Alternatively you can select an existing DS-5 Debugger configuration and then click on Duplicate from the toolbar.
In the Name field, enter a suitable name for the new configuration.
Click on the Connection tab and configure a DS-5 Debugger target connection as shown in the following figure.
Click on the Files tab and select the
app_processbinary file and the
Click on the Debugger tab and select Connect only in the Run Control panel.
Select Execute debugger commands and enter sharedlibrary in the associated text box to load debug information from all shared libraries into the debugger.
In the Paths panel, specify the shared library search directory on the host that the debugger uses when it displays source code.
Click on Debug to connect to the target.
Debugging requires the DS-5 Debug perspective. If the Confirm Perspective Switch dialog box opens, click on Yes to switch perspective.
To debug the application, set breakpoints, run, and step as required.