From 5247fa62ed2d68076c63c6e7260a3a35dd88101f Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Wed, 14 Dec 2016 13:11:14 +0100 Subject: [PATCH] [exception] print process map when crashing on Linux --- mono/mini/mini-exceptions.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/mono/mini/mini-exceptions.c b/mono/mini/mini-exceptions.c index b258a6cbfc9..00e6addd578 100644 --- a/mono/mini/mini-exceptions.c +++ b/mono/mini/mini-exceptions.c @@ -2422,6 +2422,34 @@ print_stack_frame_to_string (StackFrameInfo *frame, MonoContext *ctx, gpointer d #ifndef MONO_CROSS_COMPILE +static void print_process_map () +{ +#ifdef __linux__ + FILE *fp = fopen ("/proc/self/maps", "r"); + char line [256]; + + if (fp == NULL) { + mono_runtime_printf_err ("no /proc/self/maps, not on linux?\n"); + return; + } + + mono_runtime_printf_err ("/proc/self/maps:"); + + while (fgets (line, sizeof (line), fp)) { + // strip newline + size_t len = strlen (line) - 1; + if (len >= 0 && line [len] == '\n') + line [len] = '\0'; + + mono_runtime_printf_err ("%s", line); + } + + fclose (fp); +#else + /* do nothing */ +#endif +} + static gboolean handling_sigsegv = FALSE; /* @@ -2464,6 +2492,8 @@ mono_handle_native_crash (const char *signal, void *ctx, MONO_SIG_HANDLER_INFO_T mono_walk_stack (print_stack_frame_to_stderr, MONO_UNWIND_LOOKUP_IL_OFFSET, NULL); } + print_process_map (); + #ifdef HAVE_BACKTRACE_SYMBOLS { void *array [256]; -- 2.25.1