从JNI调用exception.printStackTrace() [英] calling exception.printStackTrace() from JNI

查看:191
本文介绍了从JNI调用exception.printStackTrace()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在的问题是找出哪些Java函数调用一些JNI函数。在Java中,这将与新Exception.printStackTrace()实现,但必须从本地进行(JNI)的功能。

The problem is to find out which Java functions call some JNI function. In Java, this would be achieved with new Exception.printStackTrace(), but this must be done from a native (JNI) function.

由于后来发现自己的code中的最简单方法是在网络出版,我张贴这两个问题的答案。

Since the easiest way to find your own code later is to publish it in the 'net, I post both the question and the answer.

推荐答案

的JNI模拟新Exception.printStackTrace()是:

//#include <android/log.h>
//#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG  , "~~~~~~", __VA_ARGS__)
//#define DLOG(...) __android_log_print(ANDROID_LOG_DEBUG  , "~~~~~~", __VA_ARGS__)
void printStackTrace(JNIEnv *env) {
LOGD("###################################################################################printStackTrace{");
    jclass cls = env->FindClass("java/lang/Exception");
    if (cls != NULL) {
        jmethodID constructor = env->GetMethodID(cls, "<init>", "()V");
        if(constructor != NULL) {
            jobject exc = env->NewObject(cls, constructor);
            if(exc != NULL) {
                jmethodID printStackTrace = env->GetMethodID(cls, "printStackTrace", "()V");
                if(printStackTrace != NULL) {
                    env->CallObjectMethod(exc, printStackTrace);
                } else { DLOG("err4"); }
            } else { DLOG("err3"); }
            env->DeleteLocalRef(exc);
        } else { DLOG("err2"); }
    } else { DLOG("err1"); }
    /* free the local ref */
    env->DeleteLocalRef(cls);
LOGD("###################################################################################printStackTrace}");
}

这篇关于从JNI调用exception.printStackTrace()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆