ndk-gdb崩溃了JNI

时间:2011-09-09 09:29:42

标签: android gdb java-native-interface android-ndk

android-ndk附带的gdbserver有一些非常奇怪的行为。以下示例 一旦采取一步就立即崩溃,而在没有调试的情况下运行它完全正常:

0xafd0ec9c in __futex_syscall3 () from /home/lhw/workspace/JNITest/obj/local/armeabi/libc.so
(gdb) b Java_de_ring0_Native_callMe 
Breakpoint 1 at 0x80b00c18: file /home/lhw/workspace/JNITest/jni/JNITest.c, line 4.
(gdb) c
Continuing.
[New Thread 12144]
[Switching to Thread 12144]

Breakpoint 1, Java_de_ring0_Native_callMe (env=0xaa50, this=0x476e3ad8) at /home/lhw/workspace/JNITest/jni/JNITest.c:4
4       jclass cl = (*env)->GetObjectClass(env, this);
(gdb) s

Program received signal SIGSEGV, Segmentation fault.
0x80a4cc5c in ?? ()
(gdb)

JNI / JNITest.c

#include <jni.h>

Java_de_ring0_Native_callMe(JNIEnv *env, jobject thiz) {
    jclass cl = (*env)->GetObjectClass(env, thiz);
    jfieldID jfid = (*env)->GetFieldID(env, cl, "findme", "I");
    jint field = (*env)->GetIntField(env, thiz, jfid);

    field = 42;

    (*env)->SetIntField(env, thiz, jfid, field);
}

的src / DE / RING0 / JNITestActivity.java

package de.ring0;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class JNITestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        System.loadLibrary("JNITest");
        Native n = new Native(23);
*       n.callMe(); // DEBUG Entrypoint

        TextView tv = (TextView)findViewById(R.id.textView);
        tv.setText(((Integer)n.findme).toString());
    }
}

的src / DE / RING0 / Native.java

public class Native {
    public int findme;

    public Native(int xy) {
        findme = xy;
    }
    public native void callMe();
}

将此更改为thiz但不影响崩溃:

Program received signal SIGSEGV, Segmentation fault.
0x804019cc in _Unwind_VRS_Pop (context=0xbe8bd3f0, regclass=<value optimized out>, 
    discriminator=<value optimized out>, representation=<value optimized out>)
    at /tmp/ndk-digit/src/build/../gcc/gcc-4.4.3/libgcc/../gcc/config/arm/unwind-arm.c:416
416 /tmp/ndk-digit/src/build/../gcc/gcc-4.4.3/libgcc/../gcc/config/arm/unwind-arm.c: No such file or directory.
    in /tmp/ndk-digit/src/build/../gcc/gcc-4.4.3/libgcc/../gcc/config/arm/unwind-arm.c
(gdb)

0 个答案:

没有答案