Merge branch 'tracerpid-abort' into 'main'

gmessages: Check /proc/self/status for TracerPid != 0 before sending SIGTRAP

Closes #3790

See merge request GNOME/glib!4845
This commit is contained in:
Philip Withnall
2025-10-01 09:12:44 +00:00

View File

@@ -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 */