Merge branch 'on-error-stack' into 'main'

Small improvements to g_on_error_stack_trace and g_on_error_query

See merge request GNOME/glib!4375
This commit is contained in:
Philip Withnall 2024-11-06 12:30:09 +00:00
commit 7868e6dd33

View File

@ -157,20 +157,12 @@ g_on_error_query (const gchar *prg_name)
retry:
if (prg_name)
_g_fprintf (stdout,
"%s (pid:%u): %s%s%s: ",
prg_name,
(guint) getpid (),
query1,
query2,
query3);
else
_g_fprintf (stdout,
"(process:%u): %s%s: ",
(guint) getpid (),
query1,
query3);
_g_fprintf (stdout,
"(process:%u): %s%s%s: ",
(guint) getpid (),
query1,
query2,
query3);
fflush (stdout);
if (isatty(0) && isatty(1))
@ -189,8 +181,7 @@ g_on_error_query (const gchar *prg_name)
else if ((buf[0] == 'P' || buf[0] == 'p')
&& buf[1] == '\n')
return;
else if (prg_name
&& (buf[0] == 'S' || buf[0] == 's')
else if ((buf[0] == 'S' || buf[0] == 's')
&& buf[1] == '\n')
{
g_on_error_stack_trace (prg_name);
@ -237,8 +228,8 @@ g_on_error_query (const gchar *prg_name)
/**
* g_on_error_stack_trace:
* @prg_name: the program name, needed by gdb for the "[S]tack trace"
* option
* @prg_name: (nullable): the program name, needed by gdb for the
* "[S]tack trace" option, or `NULL` to use a default string
*
* Invokes gdb, which attaches to the current process and shows a
* stack trace. Called by g_on_error_query() when the "[S]tack trace"
@ -260,13 +251,17 @@ g_on_error_stack_trace (const gchar *prg_name)
#if defined(G_OS_UNIX)
pid_t pid;
gchar buf[16];
gchar buf2[64];
const gchar *args[5] = { DEBUGGER, NULL, NULL, NULL, NULL };
int status;
if (!prg_name)
return;
{
_g_snprintf (buf2, sizeof (buf2), "/proc/%u/exe", (guint) getpid ());
prg_name = buf2;
}
_g_sprintf (buf, "%u", (guint) getpid ());
_g_snprintf (buf, sizeof (buf), "%u", (guint) getpid ());
#ifdef USE_LLDB
args[1] = prg_name;
@ -449,8 +444,10 @@ stack_trace (const char * const *args)
checked_write (in_fd[1], "quit\n", 5);
#else
/* Don't wrap so that lines are not truncated */
checked_write (in_fd[1], "set width unlimited\n", 20);
checked_write (in_fd[1], "backtrace\n", 10);
checked_write (in_fd[1], "set width 0\n", 12);
checked_write (in_fd[1], "set height 0\n", 13);
checked_write (in_fd[1], "set pagination no\n", 18);
checked_write (in_fd[1], "thread apply all backtrace\n", 27);
checked_write (in_fd[1], "p x = 0\n", 8);
checked_write (in_fd[1], "quit\n", 5);
#endif