-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Native crashes caused by calls to LOG_ALWAYS_FATAL
have details missing in the reports
#2121
Comments
Hi @zacharee Thanks for raising this. The We are discussing this further internally, and we’ll make sure to post any updates on this thread. As a temporary workaround, you can manually report errors to BugSnag by setting a custom aborter using Below is an example implementation of a custom aborter function. This is not an official implementation. You can use it when setting up a custom aborter function, and while this solution appears to be robust, we can’t guarantee it is 100% reliable. Please note that you have to add the #include <jni.h>
#include <android/log.h>
#include "bugsnag.h"
#include <cstdlib>
#include <cstring>
bool bugsnag_on_error(void *event) {
char* error_class = bugsnag_error_get_error_class(event);
if (strcmp(error_class, "SIGABRT") == 0) {
return false;
}
}
void aborter(const char *abort_message) {
bugsnag_notify("NativeCrash", abort_message, BSG_SEVERITY_ERR);
bugsnag_add_on_error(bugsnag_on_error);
std::abort();
}
extern "C"
JNIEXPORT void JNICALL
Java_com_example_myapplication_MainActivity_triggerNativeCrash(JNIEnv *env, jobject thiz) {
__android_log_set_aborter(aborter);
__android_log_assert("0", "NativeCrash", "Native crash triggered deliberately!");
} |
Thanks for the code sample! I modified it to try to just report the error instead of aborting and to check the API level since // Requires `android.defaultConfig.externalNativeBuild.cmake.arguments.add("-DANDROID_WEAK_API_DEFS=ON")`
// in build.gradle to work with a minSdk below 30.
#include <jni.h>
#include <android/log.h>
#include "bugsnag.h"
#include <cstdlib>
#include <cstring>
bool bugsnag_on_error(void *event) {
char* error_class = bugsnag_error_get_error_class(event);
return strcmp(error_class, "SIGABRT") != 0;
}
void aborter(const char *abort_message) {
bugsnag_notify("NativeCrash", abort_message, BSG_SEVERITY_ERR);
bugsnag_add_on_error(bugsnag_on_error);
std::abort();
}
extern "C"
JNIEXPORT void JNICALL
Java_com_example_myapplication_MainActivity_setUpAborter(JNIEnv *env, jobject thiz) {
if (__builtin_available(android 30, *)) {
__android_log_set_aborter(aborter);
}
} |
Hi @zacharee Thanks for sharing. I'm going to close this ticket out, but please feel free to re-ping if you come across any further issues and have any follow up questions. |
Describe the bug
I've noticed a few native crashes in my app reported on the Bugsnag dashboard with the
SIGABRT
error code. Looking at the stack trace, the app is killed because some native code made a call toLOG_ALWAYS_FATAL
(which is a convenience wrapper for__android_log_assert
), which terminates the process once it logs whatever message it was given. Unfortunately, when Bugsnag reports the error, it only has the stack trace and the final error code, and not the actual message that was passed toLOG_ALWAYS_FATAL
. This makes it difficult to know what could be causing the issue leading to the process termination.Example stacktrace:
Steps to reproduce
I'm not sure how to reproduce a real error, but calling
__android_log_assert
with a message should be a way to reproduce that the message isn't available in the Bugsnag dashboard.Environment
Example stacktrace:
There should be a message similar to
Failed to set damage region on surface %p, error=%s
attached here.https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/libs/hwui/renderthread/EglManager.cpp;l=610?q=eglmanager.cpp
The text was updated successfully, but these errors were encountered: