[build] Fix warning (#4177)
[mono.git] / mono / mini / mini-exceptions.c
index b258a6cbfc9800ee48b624fa920710347f109720..f4c1d974efa41777c8f48886e4e67b022e0f6b2c 100644 (file)
@@ -180,6 +180,15 @@ mini_above_abort_threshold (void)
        return above_threshold;
 }
 
+static int
+mono_get_seq_point_for_native_offset (MonoDomain *domain, MonoMethod *method, gint32 native_offset)
+{
+       SeqPoint sp;
+       if (mono_find_prev_seq_point_for_native_offset (domain, method, native_offset, NULL, &sp))
+               return sp.il_offset;
+       return -1;
+}
+
 void
 mono_exceptions_init (void)
 {
@@ -225,6 +234,7 @@ mono_exceptions_init (void)
        cbs.mono_clear_abort_threshold = mini_clear_abort_threshold;
        cbs.mono_above_abort_threshold = mini_above_abort_threshold;
        mono_install_eh_callbacks (&cbs);
+       mono_install_get_seq_point (mono_get_seq_point_for_native_offset);
 }
 
 gpointer
@@ -2422,6 +2432,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 +2502,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];
@@ -2495,7 +2535,7 @@ mono_handle_native_crash (const char *signal, void *ctx, MONO_SIG_HANDLER_INFO_T
 #if defined(PLATFORM_ANDROID)
                /* SYS_fork is defined to be __NR_fork which is not defined in some ndk versions */
                g_assert_not_reached ();
-#elif defined(SYS_fork)
+#elif !defined(PLATFORM_MACOSX) && defined(SYS_fork)
                pid = (pid_t) syscall (SYS_fork);
 #elif defined(PLATFORM_MACOSX) && HAVE_FORK
                pid = (pid_t) fork ();
@@ -2531,8 +2571,9 @@ mono_handle_native_crash (const char *signal, void *ctx, MONO_SIG_HANDLER_INFO_T
         * this has changed on later versions of Android.  Also, we don't want to
         * set this on start-up as DUMPABLE has security implications. */
        prctl (PR_SET_DUMPABLE, 1);
+
+       mono_runtime_printf_err ("\nNo native Android stacktrace (see debuggerd output).\n");
 #endif
-       mono_exception_native_unwind (ctx, info);
 #endif
 
        /*