6

I have an android application that uses a shared library which I would like to step through with a debugger. I've had success using IDA 6.3 to debug executables with the android_server debug server included with IDA but haven't gotten it to work with shared objects yet.

For a specific example, suppose I have the following Java code (This comes from the hellojni example in the Android NDK):

System.loadLibrary("hello-jni");
tv.setText( stringFromJNI() );

With the JNI C code as:

jstring
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject thiz )
{
        return (*env)->NewStringUTF(env, "Hello from JNI !");
}

If the java code is run only when the application starts up, how can I break in the function Java_com_example_hellojni_HelloJni_stringFromJNI?

amccormack
  • 1,326
  • 2
  • 13
  • 29
  • Can't you attach to the running process? It can be unconfortable if your code is triggered before you attach, but it's a start. – Marco Grassi Apr 29 '13 at 20:02
  • @MarcoGrassi That is the problem I am running into. I don't know how to trigger the catch since I can't attach until after the call has executed. – amccormack Apr 29 '13 at 20:19

2 Answers2

5

There are two options I can see.

  1. Start the Dalvik VM manually using app_process. The command line seems to be something like (see am script source):

    app_process /system/bin com.android.commands.am.Am start -a <ACTION>
    
  2. Put an endless loop in the beginning of your JNI method, run the app, attach to the new process and skip the loop manually in the debugger.

Igor Skochinsky
  • 36,553
  • 7
  • 65
  • 115
1

Newer versions of Android actually include a mechanism like this. It uses jdwp to send a signal to tell the app that you've connected up. See the ndk-gdb script from the NDK =)

jduck
  • 61
  • 1