A step-by-step guide for debugging native code, by Carlos Souto

Pre-requisites

  • 0) Sequoyah Native Debug feature must be installed.
    You can install it from Sequoyah update site:

    It will install CDT's dependencies if needed:
  • 1) The platform must be Android 2.2 (android-8)
  • 2) The ndk version must be r4b (it contains bugfixes to ndk-gdb that are necessary)
  • 3) Eclipse CDT 7.0 or newer must be installed
  • 4) The AndroidManifest.xml must have the property of the application node android:debuggable="true":

  • 5) The build must have been done with the ndk-build (if using the Sequoyah Android components, it will be automatic)

Configurations

  • 01) Create a debug configuration for an Android application (can be done with Eclipse or MOTODEV Studio)
  • 02) Create a debug configuration for a C/C++ application
  • 03) Set the following properties:

  • 04) The process launcher must be the Standard Process Launcher. This is selected at the bottom of the Main tab:

  • 05) On the "Main" tab:
    the Field C/C++ Application: $PROJECT_PATH/obj/local/armeabi/app_process
  • 06) On the "Debugger" tab:
    • field Debugger: gdbserver
    • On the "Main" subtab:

    • 07) GDB debugger: $NDK_PATH/build/prebuilt/$ARCH/arm-eabi-$GCC_VERSION/bin/arm-eabi-gdb
    • 08) GDB command file: $PROJECT_PATH/obj/local/armeabi/gdb2.setup
      [Windows users] Uncheck the "Use full file path to set breakpoints" option
    • On the "Connection" subtab:

    • 09) Type: TCP
    • 10) Hostname or IP address: localhost
    • 11) Port number: 5039

Instructions

  • Open the ndk-gdb script that came with the android NDK and comment the last line
    (we are not calling the usual gdb client, but we will attach an Eclipse gdb session instead):
    # $GDBCLIENT -x $GDBSETUP -e $APP_PROCESS
  • Insert a breakpoint in your Java code, preferably after all System.loadLibrary() calls.
    (To make sure that the debugger is correctly attached to the Java process)
  • Launch the android debug and wait for it to reach the breakpoint
  • From a Terminal session, in the project folder, run the modified ndk-gdb command. It should not attach
    to an gdb client, but call the gdbserver on the emulator and open a TCP port for connection.
  • In the $PROJECT_PATH/obj/local/armeabi/, modify the gdb.setup file, removing the target remote:5039 statement.
    (For some reason, the Eclipse GDB session does not like this statement being done in the commands file)
    Rename this new file to gdb2.setup. This step need to be run just once, on the first debug session.
    (I am working on further tweaking the ndk-gdb script to generate the gdb.setup file without the target statement,
    but for the time being, this workaround will work)
  • Launch the C/C++ Application debug and wait for the Eclipse GDB session
    to fully connect to the emulator's gdbserver instance
    After following these steps, one can continue to debug the application as usual, using the "continue" option
    to let the execution flow until the next breakpoint is hit or by using the usual "step-in" to execute each statement
    individually. Setting a breakpoint on a Java statement that calls a native function through JNI and stepping
    into will place the user at the beginning of the native code.

Latest Build [More] Sequoyah RSS
  • You can find our latest build here.
Project News [More] Sequoyah RSS
  • Sequoyah has moved to Tools project
    Posted on: Mar 11, 2011

    As part of the DSDP Restructuring, process, Sequoyah has moved to Tools project. The following items have been affected and updated: SVN repository, Bugzilla, IPLogs and web resources in general (download pages, web site, wiki page, blog). Those changes shouldn't affect Sequoyah users in any way different than reconfiguring SVN access and using different download pages.

  • 1.0.2 is available!
    Posted on: Mar 07, 2011

    Sequoyah 1.0.2 is now oficially available for download here. Please, check it out and feel free to leave us a message on our mailing list! :)

  • 1.0.1 is available!
    Posted on: Sep 24, 2010

    Sequoyah 1.0.1 is now oficially available for download here. Please, check it out and feel free to leave us a message on our mailing list! :)

  • Native debug
    Posted on: Aug 26, 2010

    We have just added a guide to help users setup their development environment correctly.

  • Simultaneously running
    Posted on: Aug 19, 2010

    Check out our latest post on Sequoyah Project Blog!
    Soon we'll share more of our thoughts and experiences!

  • More than Strings
    Posted on: Jul 28, 2010

    We have a proposal for extending Localization framework in order
    to support other resources, such as image, sound and video.
    You can find more information about it here.