7

I am porting a complex C application to Android, as an SO library, wrapped with thin java layer. After few hours of hassle, i have the code compiling under Android, but of course, the application crashes :(

After looking around, i understand the only way to debug C application under Android is by gdb. Since I don't have a lot of experience with gdb, any one out there can share some insights?

Anyone has a tutorial for gdb under windows :) ?

thx

youri
  • 933
  • 1
  • 9
  • 28
Noam
  • 220
  • 1
  • 2
  • 9
  • nice, but i can't access it :( – Noam Jul 14 '10 at 06:05
  • @ognian your account with the link is suspended...lol I would like t know the answer to this question too as I followed the asnwers link and found that the solution didn't work either. – JPM Dec 07 '11 at 16:28

1 Answers1

8

for a more recent version of NDK (I am using r7c), you can build debug version by

  1. add android:debuggable="true" flag to <Application> tag in AndroidManifest.xml
  2. invoke ndk-build with NDK_DEBUG=1 (NDK_DEBUG flag not necessary if running ndk-build with unix shell)

on Windows, things get a bit tricky because to use ndk-gdb, you still need bash (or cygwin) as of NDK r7c, yet ndk-build running in cygwin bash will run into permission problem if you ever use any of the pre-built static library

my solution on windows machine is

  1. add android:debuggable="true" flag to <application tag in AndroidManifest.xml (same as above)
  2. in cmd (windows' command prompt): invoke ndk-build with NDK_DEBUG=1
  3. in cygwin bash: run ndk-gdb

for quick initial investigation of native so library, create a simple activity with one button to trigger library entry function and loadLibrary in the activity like:

class MyActivity extends Activity {
    static {
       System.loadLibrary("mylibrary");
    }

    /* other functions like onCreate, etc... */

    public native void libfunc();

    public void onClick(View v){
       libfunc();
    }
}

So when gdb starts, the library in question is actually loaded, yet you can still have time to set break points, etc before the program crashes; when you finish setting up the debugger, at (gdb) prompt, type continue (or just 'c'), then hit the button to start the crashing program and happy debugging...

Yenchi
  • 2,076
  • 24
  • 30