开发者

ndk-gdb crashes JNI

The gdbserver shipped with the android-ndk has some really odd behaviour. The example below crashes instantly as soon as one step is taken, while running it without debugging works perfectly fine:

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();
}

Changed the this to thiz but it didn't affect the crash:

Program received signal SIGSEGV, Segmentation fault.
0x804019cc in _Unw开发者_开发技巧ind_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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜