Fix a crash on android three different ways?

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4387 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-08-05 03:10:24 +00:00
parent bfc8bb864d
commit e8fe32d5af
3 changed files with 20 additions and 2 deletions

View File

@ -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

View File

@ -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)
{

View File

@ -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);