私はネイティブコードで関数を書いていて、他の関数がそれを呼んだ関数の内部から知りたいのでjava.lang.Thread.dumpStack
、自分のCコードで使用することにしましたが、動作していません。他の可能な方法を知っている人はいますか?どうもありがとう!
以下はコードです:
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
{
__android_log_print(ANDROID_LOG_INFO, "TIM", "JNI_OnLoad Called");
JNIEnv *env = NULL;
if (vm->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK)
{
__android_log_print(ANDROID_LOG_INFO, "TIM", "GetEnv Failed");
return JNI_ERR;
}
__android_log_print(ANDROID_LOG_INFO, "TIM", "GetEnv Called");
// public static void dumpStack ()
jclass cls2 = env->FindClass("java/lang/Thread");
if(!cls2)
{
__android_log_print(ANDROID_LOG_INFO, "TIM", "FindClass Failed");
return JNI_ERR;
}
__android_log_print(ANDROID_LOG_INFO, "TIM", "FinClass Called");
jmethodID mid = env->GetStaticMethodID(cls2, "dumpStack", "()V");
if(!mid)
{
__android_log_print(ANDROID_LOG_INFO, "TIM", "GetStaticMethodID loadLibrary Failed");
return JNI_ERR;
}
__android_log_print(ANDROID_LOG_INFO, "TIM", "GetStaticMethodID Called");
env->CallStaticVoidMethod(cls2, mid);
return JNI_VERSION_1_6;
}
これは私が得たエラーです:
04-24 11:44:48.217: D/dalvikvm(4140): Trying to load lib /data/data/com.tim.myjni/lib/libmyjni.so 0x413486d8
04-24 11:44:48.267: D/dalvikvm(4140): Added shared lib /data/data/com.tim.myjni/lib/libmyjni.so 0x413486d8
04-24 11:44:48.267: I/TIM(4140): JNI_OnLoad Called
04-24 11:44:48.277: I/TIM(4140): GetEnv Called
04-24 11:44:48.277: I/TIM(4140): FinClass Called
04-24 11:44:48.277: I/TIM(4140): GetStaticMethodID Called
04-24 11:44:48.287: W/System.err(4140): java.lang.Throwable: stack dump
04-24 11:44:48.348: W/System.err(4140): at java.lang.Thread.dumpStack(Thread.java:496)
04-24 11:44:48.348: W/System.err(4140): at java.lang.Runtime.nativeLoad(Native Method)
04-24 11:44:48.377: W/System.err(4140): at java.lang.Runtime.loadLibrary(Runtime.java:368)
04-24 11:44:48.377: W/System.err(4140): at java.lang.System.loadLibrary(System.java:535)
04-24 11:44:48.407: W/System.err(4140): at com.tim.myjni.MainActivity.<clinit>(MainActivity.java:53)
04-24 11:44:48.407: W/System.err(4140): at java.lang.Class.newInstanceImpl(Native Method)
04-24 11:44:48.417: W/System.err(4140): at java.lang.Class.newInstance(Class.java:1319)
04-24 11:44:48.417: W/System.err(4140): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
04-24 11:44:48.417: W/System.err(4140): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
04-24 11:44:48.417: W/System.err(4140): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
04-24 11:44:48.417: W/System.err(4140): at android.app.ActivityThread.access$600(ActivityThread.java:122)
04-24 11:44:48.417: W/System.err(4140): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
04-24 11:44:48.447: W/System.err(4140): at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 11:44:48.447: W/System.err(4140): at android.os.Looper.loop(Looper.java:137)
04-24 11:44:48.467: W/System.err(4140): at android.app.ActivityThread.main(ActivityThread.java:4340)
04-24 11:44:48.467: W/System.err(4140): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 11:44:48.477: W/System.err(4140): at java.lang.reflect.Method.invoke(Method.java:511)
04-24 11:44:48.477: W/System.err(4140): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-24 11:44:48.477: W/System.err(4140): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-24 11:44:48.477: W/System.err(4140): at dalvik.system.NativeStart.main(Native Method)