From a184d5d375b08ae1c092694f42e9b382e2afbab6 Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Wed, 1 Oct 2025 09:12:44 +0000 Subject: [PATCH] gmessages: Check /proc/self/status for TracerPid != 0 before sending SIGTRAP Also might exist on FreeBSD or other systems which support /proc, so this codepath will run on these systems but won't fail since it checks if the file exists anyway --- glib/gmessages.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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 */