diff --git a/glib/gmessages.c b/glib/gmessages.c index fece4e7c2..3c8d07930 100644 --- a/glib/gmessages.c +++ b/glib/gmessages.c @@ -421,8 +421,30 @@ _g_log_abort (gboolean breakpoint) #ifdef G_OS_WIN32 debugger_present = IsDebuggerPresent (); +#elif defined(G_OS_UNIX) + gchar *proc_status = NULL; + gsize len; + + /* It's possible for /proc to exist on *BSD as well, so we will + * attempt to read the file regardless. + */ + if (g_file_get_contents ("/proc/self/status", + &proc_status, + &len, + NULL)) + { + /* First, check if the line even exists... */ + if (g_strstr_len (proc_status, len, "TracerPid:")) + debugger_present = (g_strstr_len (proc_status, len, "TracerPid:\t0") == NULL); + else /* Otherwise, very likely not debugging. */ + debugger_present = FALSE; + } + else /* The file likely doesn't exist, so we'll just assume we are debugging. */ + debugger_present = TRUE; + + g_free (proc_status); #else - /* Assume GDB is attached. */ + /* Assume debugger is attached. */ debugger_present = TRUE; #endif /* !G_OS_WIN32 */