Fix gdb backtraces on OSX.
authorRolf Bjarne Kvinge <rolf@xamarin.com>
Mon, 19 Dec 2011 23:56:40 +0000 (00:56 +0100)
committerRolf Bjarne Kvinge <rolf@xamarin.com>
Tue, 20 Dec 2011 10:21:29 +0000 (11:21 +0100)
We can't redirect output from gdb: since gdb will suspend us we won't
be able to read from the pipe we've redirected output to, and we'll
end up deadlocking if gdb outputs a lot of data (see bug #2548).

mono/mini/mini-darwin.c
mono/mini/mini-exceptions.c
mono/mini/mini-posix.c
mono/mini/mini.h

index 1fafa1f7aab5edfe4faea0b8a20e38d3e2bd75e2..38dfde0910524f24462ad13c6cf4cde67daea2c6 100644 (file)
@@ -227,7 +227,7 @@ mono_runtime_syscall_fork ()
        return (pid_t) fork ();
 }
 
-gboolean
+void
 mono_gdb_render_native_backtraces (pid_t crashed_pid)
 {
        const char *argv [5];
@@ -235,7 +235,7 @@ mono_gdb_render_native_backtraces (pid_t crashed_pid)
 
        argv [0] = g_find_program_in_path ("gdb");
        if (argv [0] == NULL) {
-               return FALSE;
+               return;
        }
 
        if (mkstemp (gdb_template) != -1) {
@@ -257,8 +257,6 @@ mono_gdb_render_native_backtraces (pid_t crashed_pid)
 
                unlink (gdb_template);
        }
-
-       return TRUE;
 }
 
 gboolean
index aae124d98da3ac59b054c8301b59c9bd870ea7a0..35469acc95023c828ca267e837c141d54a6bf9d6 100644 (file)
@@ -2219,16 +2219,10 @@ mono_handle_native_sigsegv (int signal, void *ctx)
 #if !defined(HOST_WIN32) && defined(HAVE_SYS_SYSCALL_H) && defined(SYS_fork)
        if (!mini_get_debug_options ()->no_gdb_backtrace && !mono_debug_using_mono_debugger ()) {
                /* From g_spawn_command_line_sync () in eglib */
-               int res;
-               int stdout_pipe [2] = { -1, -1 };
                pid_t pid;
                int status;
-               char buffer [1024];
                pid_t crashed_pid = getpid ();
 
-               res = pipe (stdout_pipe);
-               g_assert (res != -1);
-                       
                //pid = fork ();
                /*
                 * glibc fork acquires some locks, so if the crash happened inside malloc/free,
@@ -2237,31 +2231,14 @@ mono_handle_native_sigsegv (int signal, void *ctx)
                pid = mono_runtime_syscall_fork ();
 
                if (pid == 0) {
-                       close (stdout_pipe [0]);
-                       dup2 (stdout_pipe [1], STDOUT_FILENO);
-
-                       for (i = getdtablesize () - 1; i >= 3; i--)
-                               close (i);
-
-                       if (!mono_gdb_render_native_backtraces (crashed_pid))
-                               close (STDOUT_FILENO);
+                       dup2 (STDERR_FILENO, STDOUT_FILENO);
 
+                       mono_gdb_render_native_backtraces (crashed_pid);
                        exit (1);
                }
 
-               close (stdout_pipe [1]);
-
                fprintf (stderr, "\nDebug info from gdb:\n\n");
-
-               while (1) {
-                       int nread = read (stdout_pipe [0], buffer, 1024);
-
-                       if (nread <= 0)
-                               break;
-                       write (STDERR_FILENO, buffer, nread);
-               }               
-
-               waitpid (pid, &status, WNOHANG);
+               waitpid (pid, &status, 0);
        }
 #endif
        /*
index 79e521325d1e4568ad57688eced1c47d0a47cb0a..9fec75e966f91becd8fd9df6b073bd940dc87990 100644 (file)
@@ -651,7 +651,7 @@ mono_runtime_syscall_fork ()
 #endif
 }
 
-gboolean
+void
 mono_gdb_render_native_backtraces (pid_t crashed_pid)
 {
        const char *argv [9];
@@ -659,7 +659,7 @@ mono_gdb_render_native_backtraces (pid_t crashed_pid)
 
        argv [0] = g_find_program_in_path ("gdb");
        if (argv [0] == NULL) {
-               return FALSE;
+               return;
        }
 
        argv [1] = "-ex";
@@ -673,8 +673,6 @@ mono_gdb_render_native_backtraces (pid_t crashed_pid)
        argv [8] = 0;
 
        execv (argv [0], (char**)argv);
-
-       return TRUE;
 }
 #endif
 #endif /* __native_client__ */
index 1cf71cf959e0097be79e75c86550285c2480c805..5b54ac445b0afa829260879eaf95b9058150aa55 100644 (file)
@@ -2454,7 +2454,7 @@ void mono_runtime_setup_stat_profiler (void) MONO_INTERNAL;
 void mono_runtime_shutdown_stat_profiler (void) MONO_INTERNAL;
 void mono_runtime_posix_install_handlers (void) MONO_INTERNAL;
 pid_t mono_runtime_syscall_fork (void) MONO_INTERNAL;
-gboolean mono_gdb_render_native_backtraces (pid_t crashed_pid) MONO_INTERNAL;
+void mono_gdb_render_native_backtraces (pid_t crashed_pid) MONO_INTERNAL;
 
 /*
  * Signal handling