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?

2
  • 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. Commented Apr 29, 2013 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
    Commented Apr 29, 2013 at 20:19

2 Answers 2

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.

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 =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.