[exception] print process map when crashing on Linux
authorBernhard Urban <bernhard.urban@xamarin.com>
Wed, 14 Dec 2016 12:11:14 +0000 (13:11 +0100)
committerBernhard Urban <bernhard.urban@xamarin.com>
Mon, 19 Dec 2016 15:27:33 +0000 (16:27 +0100)
mono/mini/mini-exceptions.c

index b258a6cbfc9800ee48b624fa920710347f109720..00e6addd57897fd82a07abf0dba95141096c1de2 100644 (file)
@@ -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];