Improve docs
[platform/upstream/glib.git] / glib / gbacktrace.c
index 004a6aa..9ff26ee 100644 (file)
@@ -35,7 +35,6 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include "galias.h"
 #include "glib.h"
 #include "gprintfint.h"
 
@@ -46,6 +45,9 @@
 #include <sys/times.h>
 #endif
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
+#include <sys/wait.h>
+#endif
 
 #include <time.h>
 #ifdef HAVE_UNISTD_H
 #include <sys/select.h>
 #endif /* HAVE_SYS_SELECT_H */
 
-#ifdef STDC_HEADERS
 #include <string.h> /* for bzero on BSD systems */
-#endif
 
 #ifdef G_OS_WIN32
 #  define STRICT               /* Strict typing, please */
+#  define _WIN32_WINDOWS 0x0401 /* to get IsDebuggerPresent */
 #  include <windows.h>
 #  undef STRICT
 #endif
@@ -76,6 +77,7 @@
 #  endif
 #endif
 
+#include "galias.h"
 
 #ifndef G_OS_WIN32
 static void stack_trace (char **args);
@@ -88,9 +90,9 @@ void
 g_on_error_query (const gchar *prg_name)
 {
 #ifndef G_OS_WIN32
-  static const gchar *query1 = "[E]xit, [H]alt";
-  static const gchar *query2 = ", show [S]tack trace";
-  static const gchar *query3 = " or [P]roceed";
+  static const gchar * const query1 = "[E]xit, [H]alt";
+  static const gchar * const query2 = ", show [S]tack trace";
+  static const gchar * const query3 = " or [P]roceed";
   gchar buf[16];
 
   if (!prg_name)
@@ -156,10 +158,11 @@ g_on_error_query (const gchar *prg_name)
 void
 g_on_error_stack_trace (const gchar *prg_name)
 {
-#ifdef G_OS_UNIX
+#if defined(G_OS_UNIX) || defined(G_OS_BEOS)
   pid_t pid;
   gchar buf[16];
   gchar *args[4] = { "gdb", NULL, NULL, NULL };
+  int status;
 
   if (!prg_name)
     return;
@@ -180,12 +183,13 @@ g_on_error_stack_trace (const gchar *prg_name)
       perror ("unable to fork gdb");
       return;
     }
-  
-  while (glib_on_error_halt)
-    ;
-  glib_on_error_halt = TRUE;
+
+  waitpid (pid, &status, 0);
 #else
-  abort ();
+  if (IsDebuggerPresent ())
+    G_BREAKPOINT ();
+  else
+    abort ();
 #endif
 }
 
@@ -299,3 +303,6 @@ stack_trace (char **args)
 }
 
 #endif /* !G_OS_WIN32 */
+
+#define __G_BACKTRACE_C__
+#include "galiasdef.c"