0

Google breakpad catches signal (about crash in native code via JNI) but the app still dies after it. What should be done in order to prevent it?

log:

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.

code:

#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");
}
4ntoine
  • 19,816
  • 21
  • 96
  • 220

1 Answers1

0

In some cases, there is no way of preventing your app from crashing, even if you use Breakpad or CoffeeCatch.

However, you will be notified before the crash occurs. You can use that time to warn the user about what is happening (a fatal error) and what will happen next (the app will force close).

Sebastiano
  • 12,289
  • 6
  • 47
  • 80
  • Sure, how can i know if it's fatal case or i can prevent crash? – 4ntoine Mar 09 '14 at 06:59
  • I guess you can do some tests and see which errors are non-recoverable. Then, in your code, you take a look at the error message and act accordingly. I know this does not sound like a good plan, but I had these problems myself and this was the best I could come up with: both because you can actually log the native exceptions on your issue tracker of choice and because you can at least try to figure out what the problem is and on which devices/conditions it usually happens. – Sebastiano Mar 09 '14 at 08:17
  • @4ntoine Hey did you find any solution for this? After including some deliberate crasher like your test code. It was not able to call crash reporter. Did you find any scenario for crash test which i use to make sure it will lauch the reporter from any part of the code. – StraightCirle Dec 07 '15 at 07:12