Verizon Fios Tech Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Thursday, 22 August 2013

How to debug Android Native Code with Eclipse

Posted on 06:29 by Unknown
This blog summarizes the steps needed to set-up your Eclipse environment to support the debugging of an Android native application written in C/C++. It's taken from Carlos Suoto's web page at http://www.eclipse.org/sequoyah/documentation/native_debug.php.

1. Pre-Requisites


  • Make sure you compile your C/C++ with the "-g" option (or use -DCMAKE_BUILD_TYPE:STRING="Debug" if you use cmake).
  • Make sure APP_OPTIM is set to "APP_OPTIM:=debug" in Android.mk and Application.mk.
  • Make sure build/core/build-binary.mk in Android NDK doesn't strip executables. For example patch android-ndk-r8e/build/core/build-binary.mk to the following:

    --- build/core/build-binary.mk.orig     2013-08-21 11:06:39.818329442 -0400
    +++ build/core/build-binary.mk  2013-08-21 11:13:11.877214361 -0400
    @@ -485,10 +485,16 @@ $(LOCAL_INSTALLED): PRIVATE_DST       :=
     $(LOCAL_INSTALLED): PRIVATE_STRIP     := $(TARGET_STRIP)
     $(LOCAL_INSTALLED): PRIVATE_STRIP_CMD := $(call cmd-strip, $(PRIVATE_DST))
     
    +ifeq ($(APP_OPTIM),debug)
    +$(LOCAL_INSTALLED): $(LOCAL_BUILT_MODULE) clean-installed-binaries
    +       @$(HOST_ECHO) "Install        : $(PRIVATE_NAME) => $(call pretty-dir,$(PRIVATE_DST))"
    +       $(hide) $(call host-install,$(PRIVATE_SRC),$(PRIVATE_DST))
    +else
     $(LOCAL_INSTALLED): $(LOCAL_BUILT_MODULE) clean-installed-binaries
            @$(HOST_ECHO) "Install        : $(PRIVATE_NAME) => $(call pretty-dir,$(PRIVATE_DST))"
            $(hide) $(call host-install,$(PRIVATE_SRC),$(PRIVATE_DST))
            $(hide) $(PRIVATE_STRIP_CMD)
    +endif

1.1. Install the Eclipse Sequoyah plugin


  1. In Eclipse go to Help -> Install New Software
  2. Click on the Add button
  3. Enter 'Sequoyah Metadata Repository' in the Name field
  4. Enter 'http://download.eclipse.org/sequoyah/updates/2.0/' in the Location field
  5. If you still see the "There are no categorized items" message, uncheck the "Group items by category" radio button
  6. Select "Sequoyah Android Native Code Support" and install the plugin

1.2. Convert The Android Java Application into C/C++ Project


You must convert your Java project to C/C++ using the Sequoyah plugin or else you won't be able to see the configuration options to set the proper debugger settings.
  1. In Eclipse select the Android Java project you need to convert
  2. Right click with the mouse and select Android Tools -> Add Native Support

1.3. Other Pre-Requisites


  1. The platform must be Android 2.2 (android-8) or later
  2. The ndk version must be r4b (it contains bugfixes to ndk-gdb that are necessary) or later
  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)

2. 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:

    http://www.eclipse.org/sequoyah/images/native_debug_2.png
  • 04) The process launcher must be the Standard Process Launcher. This is selected at the bottom of the Main tab:

    http://www.eclipse.org/sequoyah/images/native_debug_3.png
  • 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:

      http://www.eclipse.org/sequoyah/images/native_debug_4.png
    • 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:

      http://www.eclipse.org/sequoyah/images/native_debug_5.png
    • 09) Type: TCP
    • 10) Hostname or IP address: localhost
    • 11) Port number: 5039 

    3. 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 (or in alternative if you have an Android device connected to your USB port, the ndk-gdb script will run gdbserver on the device itself).
  • 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.
  • 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.
Another way to set breakpoints in the C/C++ code is from Eclipse to click on File -> Open File and browse to the location of your source code. Then double-click on the line where you want to set the breakpoint.
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in Android, ARM | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Free Blogger Opp – Timjan Design Malachite 5/1
    Here comes another Visionary Bri blogger opportunity. Sign up now for the Timjan Bloomers Giveaway. Our sponsor, Timjan Design , has offered...
  • Problems with new version of rpmbuild
    The Problem With the new version of rpmbuild installed on CentOS 6.x, if you try to use an old RPM spec file, you will get an error like the...
  • Installing the Android SDK
    These instructions refer to a Ubuntu 12.04.1 LTS system running on an Intel processor. Head to the developer.android.com web site and downl...
  • Meeting The Tate's
       Hello, we are Cody and Aimee Tate. We live in Florida and have been married for 3 years. Recently we have decided to start doing product ...
  • How to Cross-Compile libiconv for Android
    If your legacy C/C++ code includes <iconv.h> to convert the encoding of characters from one coded character set to another, and you ne...
  • Python For Android (Py4A)
    A better solution for cross-compiling Python for Android is to use the Py4A project which is made to be used together with SL4A (Scripting L...
  • Free Blogger Op Getting Ready for Summer Giveaway
    Hosted by:   NYSavingSpecials   and  Your Fashion Resource Come and join us on this great giveaway "Getting ready for Summer" We w...
  • PAINT released to the public for Research Purposes Only
    Digital Operatives is proud to release to the public for Research Purposes Only, a beta version of PAINT, Process Attribution In Network Tra...
  • How to compile busybox with Android NDK for both ARM and x86 architectures
    I was looking for a way to run busybox on a Motorola RAZRi with an x86 Intel Atom processor but I couldn't find any Android app from th...
  • DermOrganics Review
    "DermOrganic ®  products are made using ingredients that are synergistic to your hair and skin to replenish from the outside what your ...

Categories

  • amazon
  • amazon.com
  • Android
  • Apple
  • Arduino
  • ARM
  • baby
  • baby reviews
  • back to school
  • beef jerky
  • bicycle. wagon
  • bike
  • Blanket Buddies
  • blogging
  • Blogging with The Tate's
  • books
  • busybox
  • camera
  • camera giveaway
  • candle giveaway
  • candles
  • CaseApp
  • CentOS
  • coffee
  • david haskell
  • dermorganic
  • DHCP
  • digital camera
  • events
  • Florida
  • Fortran
  • free blogger giveaway
  • free blogger sign-ups
  • full of flavor
  • giveaways
  • GNU
  • GPON
  • hair care
  • happy husband
  • Hot tea
  • Husband and Wife perspective
  • iMac
  • ipad
  • iphone
  • iphone case
  • iphone case review
  • Javascript
  • Keurig Coffee Review
  • Keurig Review
  • Kindle
  • ksh
  • LifeProof iPhone Case Review
  • Linux
  • MacOSX
  • Malachite Bloomers
  • man and women perspective
  • meat
  • Mips
  • Network
  • Pretzel Crisps
  • Pretzels
  • product reviews
  • products
  • Python
  • Router
  • scentsy
  • scentsy candles
  • school
  • scooter
  • security system
  • skin care
  • snacks
  • sony
  • sony cyber-shot
  • Stuff Animal
  • suface pro
  • Summer
  • summer fun
  • surface pro giveaway
  • techno thriller
  • Timjan Design
  • too much information
  • UNIX
  • vegan
  • vegan products
  • verizon
  • verizon fios
  • VitaminsBaby
  • waterproof case
  • Windows
  • x86
  • yummy

Blog Archive

  • ▼  2013 (41)
    • ►  November (2)
    • ►  October (2)
    • ►  September (3)
    • ▼  August (3)
      • Krave Beef Jerky Review
      • Defending Your E-Mails from Surveillance … Conveni...
      • How to debug Android Native Code with Eclipse
    • ►  July (2)
    • ►  June (2)
    • ►  May (6)
    • ►  April (8)
    • ►  March (2)
    • ►  February (5)
    • ►  January (6)
  • ►  2012 (17)
    • ►  December (3)
    • ►  November (4)
    • ►  October (8)
    • ►  July (1)
    • ►  June (1)
Powered by Blogger.

About Me

Unknown
View my complete profile