diff --git a/Makefile b/Makefile index 4626cb42..9de5de85 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,8 @@ $(ANDROID_TARGETS): CFLAGS += \ -fPIC \ -fdebug-compilation-dir . \ -fomit-frame-pointer \ - -fno-asynchronous-unwind-tables + -fno-asynchronous-unwind-tables \ + -funwind-tables $(ANDROID_TARGETS): LDFLAGS += --sysroot $(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC $(DEBUG_TARGETS): CFLAGS += -DDEBUG -Og $(RELEASE_TARGETS): CFLAGS += -DNDEBUG diff --git a/src/main.c b/src/main.c index ec210e12..fa8ba2d9 100644 --- a/src/main.c +++ b/src/main.c @@ -586,6 +586,14 @@ static void _backtrace_error(void* data, const char* message, int errnum) tf_printf("libbacktrace error %d: %s\n", errnum, message); } +static void _error_handler(int sig) +{ + const char* stack = tf_util_backtrace_string(); + tf_printf("ERROR:\n%s\n", stack); + tf_free((void*)stack); + _exit(1); +} + int main(int argc, char* argv[]) { bool tracking = false; @@ -624,6 +632,15 @@ int main(int argc, char* argv[]) } #endif + bool use_error_handler = false; +#if defined(__ANDROID__) + use_error_handler = true; +#endif + if (use_error_handler && signal(SIGSEGV, _error_handler) == SIG_ERR) + { + perror("signal"); + } + int result = 0; if (argc >= 2) { diff --git a/src/ssb.c b/src/ssb.c index d0e20933..c7da9419 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -762,7 +762,7 @@ void tf_ssb_connection_rpc_send_error(tf_ssb_connection_t* connection, uint8_t f JSValue message = JS_NewObject(context); const char* stack = tf_util_backtrace_string(); JS_SetPropertyStr(context, message, "name", JS_NewString(context, "Error")); - JS_SetPropertyStr(context, message, "stack", JS_NewString(context, stack)); + JS_SetPropertyStr(context, message, "stack", JS_NewString(context, stack ? stack : "stack unavailable")); JS_SetPropertyStr(context, message, "message", JS_NewString(context, error)); tf_ssb_connection_rpc_send_json(connection, ((flags & k_ssb_rpc_flag_stream) ? (k_ssb_rpc_flag_stream | k_ssb_rpc_flag_end_error) : 0), request_number, message, NULL, NULL, NULL); JS_FreeValue(context, message);