ARM DS-5 Tutorial For Android

Note: This was originally posted on 5th December 2011 at http://forums.arm.com

Hi,

I've created a step by step blog post for using DS-5 as debugger tool for Android http://kernel.ozandroid.info/?p=83

Hope this is useful for others.

Cheers
  • Note: This was originally posted on 21st January 2012 at http://forums.arm.com

    What is your device you are testing on?
  • Note: This was originally posted on 17th January 2012 at http://forums.arm.com

    Hi! First of all, thanks for your work. That is the first debugger that somehow works. I tried it on android ndk sample projects - it went fine. But on my own projects I have encountered problems.
    I do everything like in tutorial, but execution of the app stops, I hit Run/Continue button, but only get message:

    wait
    continue
    Stopped due to signal 11: SIGSEGV (Invalid memory segment access)
    Execution stopped at: 0x80CB1314
    In thread 1 (OS thread id 1793)
    0x80CB1314   LDR      r0,[r0,#0x38]

    Any hints?
  • Note: This was originally posted on 19th December 2011 at http://forums.arm.com


    did u add "LOCAL_CFLAGS += -g" in your jni/Android.mk ?

    No, I haven't added it, as (I think) it's not needed, as in my AndroidManifest.xml I have android:debuggable="true". I've also tested now with "LOCAL_CFLAGS += -g", and no difference.
    Most time when I use "Download and debug an Android application" I do get error "[1]   Segmentation fault      run-as com.examp..." (it's as I think form gdbserver)

    But debugging works on SGS2 now with some "special" taken actions (as in my post from 17 December 2011 - 03:26 PM).
  • Note: This was originally posted on 17th December 2011 at http://forums.arm.com

    Finally I've got DS-5 Debugger 'working' with SGS2 on GB (2.3). But it's a little painful.
    EDIT: Debugging on SGS2 with ICS (4.0 LPQ) works fine, at least! No need to use below manual.

    First of all, option in DS-5 named "Download and debug an Android application" wasn't work as expected.
    I'll describe it more later, after I do more tests with it.

    To make debugging work on SGS2 (and Windows) I need to:
    0. Create DS-5 Debugger profile as in tutorial, but change "Debug operation" to "Attach to a running Android application"
    1. Build and Install apk
    You can use "Android application" debugging profile. It will:
    - build .apk
    - install it on device
    - run it
    Of course you need build your .so first if you haven't for example added ndk-build to your
    project "Builders" (which is really easy as of NDK v7 - no need to use cygwin).
    2. Run activity on device(if it wasn't started in point 1), and then close it by 'back button'
    As I know, process of this activity will be still running (but activity thread/application(?) will be closed).
    Closing activity is very important. I couldn't get debbuging work without this point!.
    3. Start debugging using your DS-5 debug profile.
    You shouldn't get any errors, and in "Debug Control" there should be break on thread waiting on "epoll_wait".
    Debugger should attach to your process (but activity isn't running) and pause it.
    4. Set breakpoint(s) in your C/C++ code. (optional)
    5. Press "Run/Continue" (green button in "Debug Control").
    It will not run your activity! It will just continue run of your paused android process (in point 3).
    6. Then start your activity on device. You should see breakpoint hit (if you set it in point 4).
    7. You can also add breakpoints later, but first you need to pause application.
    In "Debug Control" window press yellow II button, and then you can
    add/remove breakpoints, and next press again "Run/Continue" button.

    But this doesn't work always (but most time do).
    Sometimes I get errors at point 3 or at point 6 (gdbserver: "[1]   Segmentation fault      run-as com.examp...")
    Then you need to try again from point 2. (run and close activity...).

    Problem with this configuration is that, if your application crashing at start,
    you won't be able to debug it :(
    You need to successfully run and close activity (process of activity must remain running).
    I think that this one could be workarounded by changes in code (to run your main code at some condition/variable,
    which will be chnaged manually on debugging session at second activity run).

    I would really thanks to DS-5 team and @nicksydney. Good job!
    It's first debbuger (and tutorial for it) that worked for me!

    PS. Really nice view to see debugging working on device after 6+ months of
    using of LOGI/__android_log_print and analysing/filtering LogCat :)
    But I think that it cannot replace my VisualStudio+Mali OpenGL ES 2.0 emulator setup,
    at least for now, but I will definitly help when testing code/application on real device!
  • Note: This was originally posted on 17th March 2012 at http://forums.arm.com


    Did you replaced gdbserv from ARM Extras "menu" (as in link from first post of this topic)?



    I'm trying to debug my game on the emulator, I did replace the gdbserver from the ARM extras folder, but every time I press the debug button, my eclipse IDE does a recompile and replaces every file on my folder, so the the gdbserver from DS-5 is replaced.

    Also if I manage to replace again the gdbserver before the game launches then the correct debugger is launched but as you can see from my screenshot the game stops a lot sooner than my game's entry point/

    http://dl.dropbox.co...bug_capture.png

    I've placed a breakpoint in my

    void android_main(android_app* pApplication)

    but it never fires
  • Note: This was originally posted on 14th February 2012 at http://forums.arm.com

    Hi Krystian,

    I had not replaced gdbserv from the ARM Extras menu.  I have now though and still get the problem.  I will try your other suggestions and let you know how I get on.  Thanks for all your help!

    Barney
  • Note: This was originally posted on 6th February 2012 at http://forums.arm.com

    Did you replaced gdbserv from ARM Extras "menu" (as in link from first post of this topic)?

    I'm using 2.3.5 (from around 09.2011). "Real" GDB Server comes from device "manufacturer", AFIK this gdbserv is only some kind of bridge between real GDB server and application. So it might be it (new version of Android in device --> possible new/fixed version of GDB Server).
    Also you might try to update Kies as it comes with new USB drivers that allows USB debugging.


    If above won't help, you might try to switch USB cable to other USB port .
    Today at work I saw problems with debugging Java/Dalvik code (or even problems with adb connection), when 1,8m USB cable was plugged into back PC USB ports (it might be some USB3.0 ports). When cable was plugged into front-PC USB ports, then there was no problems at all.
    When I plug SGS2 to combo USB+eSata+"Charge" port in my laptop, it connects/disconnects device every 1-2s. I need use only 'regular' USB ports.
  • Note: This was originally posted on 6th February 2012 at http://forums.arm.com

    Hi Krystian,

    Sorry I should have said,  I get this error when my code hits a breakpoint.  I did follow your steps above, including step 2 - it is the only reason it works at all, thank you!  I will try and post more information when I get home later.

    I am running Android 2.3.3 so maybe upgrading to 2.3.5+ will help.

    Thanks,
    Barney
  • Note: This was originally posted on 6th February 2012 at http://forums.arm.com

    Yes, I had similar or even same crashes. I don't see any problems with debugging non "main" threads (even if log says "AAAAAH, Can't debug threads!" ;) ) . I'm using NativeActivity, so my NDK/C++ code does not  run on main thread but on it's own thread.

    Did you followed steps exactly as in my post? Most important thing before each ndk debugging session on SGS2 is point "two" - run activity, and close it, but do NOT terminate it! Then you can start debugging by "Attach to a running Android application" (as in this "SGS2 NDK debug tutorial").

    Write what steps make you trouble, so I help you.
  • Note: This was originally posted on 5th February 2012 at http://forums.arm.com

    Hi Krsystian,

    Thank you for your Galaxy S2 instructions, I am also using the S2 and I was wondeirng how you solved this error:

    ERROR(LUX42): Stopped due to signal 5: SIGTRAP (Trace trap (used by debugger))
    Application terminated due to signal 5

    I have read that this was a problem related to only being able to debug on the main thread but you aren't having this problem?  I get this error whenever I hit a breakpoint.

    Thanks,
    Barney

  • Note: This was originally posted on 18th December 2012 at http://forums.arm.com

    [size="4"]It is [/size][size="4"][size="4"][size="4"] one of Hot topics  [size="4"]about [/size][/size]Debugging native code of Android NDK is, but it is igored about Compiling native code of Android NDK with ARMCC .[/size]
    [/size]
  • Note: This was originally posted on 18th December 2012 at http://forums.arm.com

    C[size="4"]ould ARMCC in DS-5 pro be used to compile the native code of Android NDK? If could, then how to do?
    We  try to use ARMCC to compile NEON intrincis in the native code of  Android NDK, but found none guideline or articles, any sugessions?  thanks a lot... [/size]
  • Note: This was originally posted on 11th August 2012 at http://forums.arm.com

    ICS is an "Ice Cream Sandwich" - Android 4.0.
    Originally on SGSII there was GB (Gingerbread - Android 2.3), and there was problems with debugging, but after Samsung updated software on SGSII to ICS (4.0), everything works much better.
  • Note: This was originally posted on 10th August 2012 at http://forums.arm.com

    Hello Krystian.

    I'm having exactly the same problem you are describing with DS-5, on a Samsung Galaxy Ace and  a Samsung Galaxy Y Phone.
    Your detailed steps of "Attaching to a running Android application" are working fine - thank you very much for that -,  but I'm curious of your Edit, where you are using something called ICS.  Could you elaborate a bit on this workaround you found?

    Thank you very much in Advance!

    Gerardo
  • Note: This was originally posted on 20th March 2012 at http://forums.arm.com

    You could try to replace gdbserver inside NDK (like ...\android-ndk\toolchains\arm-linux-androideabi-4.4.3\prebuilt)

    Does LogCat says anything useful? Maybe you are trying to use for example OpenGL ES 2.0 in emulator (which isn't supported)?
    Also, hitting breakpoint at begining of android_main is a little bit tricky...


    --

    Just for note, debugging on SGS2 with official ICS (4.0) works fine now (or at least same as on other devices)!
More questions in this forum