From ae4ff45468c816129a50940be67802d82b30d998 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 9 Mar 2023 12:31:17 -0500 Subject: [PATCH 1/3] call mono_pmip_u in the crash handler --- src/mono/mono/mini/mini-posix.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mono/mono/mini/mini-posix.c b/src/mono/mono/mini/mini-posix.c index be8f83d396872..207b6f57ab3f3 100644 --- a/src/mono/mono/mini/mini-posix.c +++ b/src/mono/mono/mini/mini-posix.c @@ -809,6 +809,9 @@ dump_native_stacktrace (const char *signal, MonoContext *mctx) } else { g_async_safe_printf ("\t%p - %s : %s\n", ip, fname, sname); } + char *method_name = mono_pmip_u (ip); + if (method_name) + g_async_safe_printf ("\t\t%p - %s\n", ip, method_name); } #if !defined(HOST_WIN32) && defined(HAVE_SYS_SYSCALL_H) && ((!defined(HOST_DARWIN) && defined(SYS_fork)) || HAVE_FORK) From a8f7247b87dff5749509a04c66c208509d072e03 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 9 Mar 2023 16:37:20 -0500 Subject: [PATCH 2/3] _Unwind_Backtrace? --- src/mono/mono/mini/mini-arm64.h | 2 +- src/mono/mono/mini/mini-exceptions.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/mini/mini-arm64.h b/src/mono/mono/mini/mini-arm64.h index 7dfe8eed08c06..2943c6c5ae127 100644 --- a/src/mono/mono/mini/mini-arm64.h +++ b/src/mono/mono/mini/mini-arm64.h @@ -198,7 +198,7 @@ typedef struct { #endif -#if defined(TARGET_IOS) || defined(TARGET_WATCHOS) +#if defined(TARGET_IOS) || defined(TARGET_WATCHOS) || defined(__linux__) #define MONO_ARCH_HAVE_UNWIND_BACKTRACE 1 #endif diff --git a/src/mono/mono/mini/mini-exceptions.c b/src/mono/mono/mini/mini-exceptions.c index 56935279a18bd..97e503dc2cf43 100644 --- a/src/mono/mono/mini/mini-exceptions.c +++ b/src/mono/mono/mini/mini-exceptions.c @@ -369,7 +369,7 @@ is_address_protected (MonoJitInfo *ji, MonoJitExceptionInfo *ei, gpointer ip) #ifdef MONO_ARCH_HAVE_UNWIND_BACKTRACE -#if 0 +#if 1 static gboolean show_native_addresses = TRUE; #else static gboolean show_native_addresses = FALSE; From 0720035095ee1a0d64fabebebce8f6c7e54a919c Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 9 Mar 2023 18:45:09 -0500 Subject: [PATCH 3/3] more _Unwind_Backtrace --- src/mono/mono/mini/mini-posix.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/mini/mini-posix.c b/src/mono/mono/mini/mini-posix.c index 207b6f57ab3f3..d5ce694e0bf70 100644 --- a/src/mono/mono/mini/mini-posix.c +++ b/src/mono/mono/mini/mini-posix.c @@ -80,6 +80,10 @@ #include "jit-icalls.h" #include +#ifdef HAVE_UNWIND_H +#include +#endif + #ifdef HOST_DARWIN #include #include @@ -774,6 +778,21 @@ fork_crash_safe (void) } #endif +#ifdef MONO_ARCH_HAVE_UNWIND_BACKTRACE +static _Unwind_Reason_Code +dump_unwind_backtrace (struct _Unwind_Context *frame_ctx, G_GNUC_UNUSED void *state) +{ + uintptr_t ip = _Unwind_GetIP (frame_ctx); + + g_async_safe_printf ("\t Frame: %p\n\t\t"); + mono_print_method_from_ip ((void*)ip); + g_async_safe_printf ("\n"); + + return _URC_NO_REASON; +} + +#endif + static void dump_native_stacktrace (const char *signal, MonoContext *mctx) { @@ -789,6 +808,13 @@ dump_native_stacktrace (const char *signal, MonoContext *mctx) } +#ifdef MONO_ARCH_HAVE_UNWIND_BACKTRACE + g_async_safe_printf ("\n=================================================================\n"); + g_async_safe_printf (" _Unwind_Backtrace stacktrace:\n"); + g_async_safe_printf ("=================================================================\n"); + _Unwind_Backtrace (dump_unwind_backtrace, NULL); +#endif + #ifdef HAVE_BACKTRACE_SYMBOLS void *array [256]; @@ -809,9 +835,6 @@ dump_native_stacktrace (const char *signal, MonoContext *mctx) } else { g_async_safe_printf ("\t%p - %s : %s\n", ip, fname, sname); } - char *method_name = mono_pmip_u (ip); - if (method_name) - g_async_safe_printf ("\t\t%p - %s\n", ip, method_name); } #if !defined(HOST_WIN32) && defined(HAVE_SYS_SYSCALL_H) && ((!defined(HOST_DARWIN) && defined(SYS_fork)) || HAVE_FORK)