Gdbserver, поставляемый с android-ndk, ведет себя довольно странно. Пример ниже
аварийно завершает работу сразу после выполнения одного шага, при этом его запуск без отладки прекрасно работает:
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);
}
ЦСИ / де / 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());
}
}
ЦСИ / де / 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)