Android ndk 应用程序在被google_breakpad捕捉到信号后崩溃?

Android ndk 应用程序在被google_breakpad捕捉到信号后崩溃?,android-ndk,google-breakpad,Android Ndk,Google Breakpad,Google breakpad捕捉到了信号(关于通过JNI在本机代码中崩溃),但应用程序在它之后仍然死亡。为了防止这种情况,应该做些什么 日志: 代码: #包括“native_lib.h” #包括 #包括“client/linux/handler/exception_handler.h” #包括“client/linux/handler/minidump_descriptor.h” #包括 无效调试(常量字符*格式,…){ va_列表参数; va_开始(argptr,格式); __安卓日志打印(

Google breakpad捕捉到了信号(关于通过JNI在本机代码中崩溃),但应用程序在它之后仍然死亡。为了防止这种情况,应该做些什么

日志:

代码:

#包括“native_lib.h”
#包括
#包括“client/linux/handler/exception_handler.h”
#包括“client/linux/handler/minidump_descriptor.h”
#包括
无效调试(常量字符*格式,…){
va_列表参数;
va_开始(argptr,格式);
__安卓日志打印(安卓日志错误,“本机库”,格式,argptr);
va_端(argptr);
}
bool DumpCallback(const google_breakpad::minidumpsdescriptor和descriptor,
void*上下文,
布尔(成功){
调试(“转储路径:%s\n”,descriptor.path());
返回成功;
}
JNIEXPORT jint JNICALL Java_name_antosmirnov_android_app_libnative_func(JNIEnv*env,jobject obj)
{
调试(“init breakpad”);
google_breakpad::MinidumpDescriptor描述符(“.”);
例外处理程序eh(描述符,NULL,DumpCallback,NULL,true,-1);
{
调试(“测试崩溃\n”);
char*ptr=0;
*ptr='!';//此处出错!
调试(“不可访问\n”);
}
调试(“已完成”);
}

在某些情况下,即使您使用了BreakpadCoffeeCatch,也无法防止应用程序崩溃


但是,您将在崩溃发生之前收到通知。你可以利用这段时间来警告用户正在发生什么(致命错误)以及接下来会发生什么(应用程序将强制关闭)。

当然,我如何知道这是致命的情况,或者我可以防止崩溃?我想你可以做些测试,看看哪些错误是不可恢复的。然后,在代码中,查看错误消息并相应地执行操作。我知道这听起来不是个好计划,但我自己也遇到了这些问题,这是我能想到的最好的办法:既因为你可以在你选择的问题跟踪器上记录本机异常,也因为你至少可以试着找出问题所在以及通常发生在哪些设备/条件上。@4ntoine嘿,你找到了解决方法吗?在加入一些故意的破坏者之后,比如你的测试代码。它无法呼叫坠机记者。您是否发现了崩溃测试的任何场景,我使用这些场景来确保它将从代码的任何部分启动reporter。
03-08 15:04:13.398: ERROR/NATIVE_LIB(2828): init breakpad
03-08 15:04:13.398: ERROR/NATIVE_LIB(2828): testing crash
03-08 15:04:13.468: ERROR/NATIVE_LIB(2828): Dump path: ./5f6097b2-5feb-0723-3271a7ff-2a4fcadd.dmp
03-08 15:04:13.468: WARN/crash_handler(2828): Caught a crash, signum=11

...

03-08 15:04:14.589: INFO/ActivityManager(544): Process name.antonsmirnov.android.app (pid 2828) has died.
#include "native_lib.h"

#include <stdio.h>

#include "client/linux/handler/exception_handler.h"
#include "client/linux/handler/minidump_descriptor.h"

#include <android/log.h>

void debug(const char *format, ... ) {
    va_list argptr;
    va_start(argptr, format);
    __android_log_vprint(ANDROID_LOG_ERROR, "NATIVE_LIB", format, argptr);
    va_end(argptr);
}

bool DumpCallback(const google_breakpad::MinidumpDescriptor& descriptor,
                  void* context,
                  bool succeeded) {
  debug("Dump path: %s\n", descriptor.path());
  return succeeded;
}

JNIEXPORT jint JNICALL Java_name_antonsmirnov_android_app_libnative_func(JNIEnv *env, jobject obj)
{
    debug("init breakpad");
    google_breakpad::MinidumpDescriptor descriptor(".");
    google_breakpad::ExceptionHandler eh(descriptor, NULL, DumpCallback, NULL, true, -1);

    {
        debug("testing crash\n");

        char *ptr = 0;
        *ptr = '!'; // ERROR HERE!
        debug("unreachable\n");

    }

    debug("finished\n");
}