From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v6 4/4] [gdb/tui] Fix crash with debuginfod query (C-x C-a)
Date: Fri, 17 Apr 2026 09:57:19 +0200 [thread overview]
Message-ID: <20260417075719.852558-5-tdevries@suse.de> (raw)
In-Reply-To: <20260417075719.852558-1-tdevries@suse.de>
PR tui/33794 reports an abort when the debuginfod query happens while enabling
TUI using the "C-x C-a" key combination.
The abort triggering is this one in rl_callback_read_char:
...
if (rl_linefunc == NULL)
{
_rl_errmsg ("readline_callback_read_char() called with no handler!");
abort ();
}
...
This is similar to PR python/24796, and can be fixed by applying a similar fix
in tui_enable:
...
void
tui_enable (void)
{
+ SCOPE_EXIT { reinstall_readline_callback_handler_cleanup (); };
...
After doing so, things seem to be fixed, but when compiling gdb with Asan, we
run into a heap-use-after-free.
The problem here is that readline is used recursively:
- readline is entered when handling the C-x C-a key combination
- readline is entered again when handling the debuginfod query
This would have to be addressed in readline, but in the mean time we need a
fix in gdb.
An RFC [1] was posted exploring the option of avoiding recursive readline use
by rather than handling the key combination directly, queueing it in an event
queue and handling the events later.
This patch takes a conservative approach: bail out if debuginfod enabled is
set to ask when entering TUI.
The fix is minimal, and consequently low-risk, and applies cleanly to the
gdb-17-branch (and that holds more or less as well for the patches this patch
is dependent on).
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33794
[1] https://sourceware.org/pipermail/gdb-patches/2026-February/225289.html
---
gdb/testsuite/gdb.tui/query.exp | 3 +--
gdb/tui/tui.c | 10 ++++++++--
gdb/tui/tui.h | 2 +-
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/gdb/testsuite/gdb.tui/query.exp b/gdb/testsuite/gdb.tui/query.exp
index acf0db63ebb..eb0bee49aec 100644
--- a/gdb/testsuite/gdb.tui/query.exp
+++ b/gdb/testsuite/gdb.tui/query.exp
@@ -49,8 +49,7 @@ file delete $tmpfile
set l {}
lappend l "command"
-# Disabled due to PR33794.
-#lappend l "keys"
+lappend l "keys"
foreach_with_prefix how $l {
save_vars { env(DEBUGINFOD_URLS) } {
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index 9cf21f390c8..d2f1b79616c 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -41,6 +41,7 @@
#include "top.h"
#include "ui.h"
#include "observable.h"
+#include "debuginfod-support.h"
#include <fcntl.h>
@@ -140,7 +141,7 @@ tui_rl_switch_mode (int notused1 = 0, int notused2 = 0)
/* If tui_enable throws, we'll re-prep below. */
rl_deprep_terminal ();
- tui_enable ();
+ tui_enable (false);
}
}
catch (const gdb_exception_forced_quit &ex)
@@ -399,13 +400,18 @@ gdb_getenv_term (void)
the gdb output, configures the readline to work in tui mode.
When in curses mode, it does nothing. */
void
-tui_enable (void)
+tui_enable (bool queries_allowed)
{
TUI_SCOPED_DEBUG_ENTER_EXIT;
if (tui_active)
return;
+ if (!queries_allowed
+ && debuginfod_enabled_ask_p ()
+ && defaulted_query_auto_answers_p () != TRIBOOL_TRUE)
+ error (_("Please set debuginfod enabled to on or off before enabling TUI"));
+
tui_batch_rendering defer;
/* To avoid to initialize curses when gdb starts, there is a deferred
diff --git a/gdb/tui/tui.h b/gdb/tui/tui.h
index 7daefe2c9bb..e90c40b562e 100644
--- a/gdb/tui/tui.h
+++ b/gdb/tui/tui.h
@@ -70,7 +70,7 @@ extern bool tui_get_command_dimension (unsigned int *width,
extern void tui_ensure_readline_initialized ();
/* Enter in the tui mode (curses). */
-extern void tui_enable (void);
+extern void tui_enable (bool queries_allowed = true);
/* Leave the tui mode. */
extern void tui_disable (void);
--
2.51.0
next prev parent reply other threads:[~2026-04-17 7:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-17 7:57 [PATCH v6 0/4] [gdb/tui] Fix crash with debuginfod query Tom de Vries
2026-04-17 7:57 ` [PATCH v6 1/4] [gdb/tui] Fix crash with debuginfod query (tui enable) Tom de Vries
2026-04-17 7:57 ` [PATCH v6 2/4] [gdb] Add debuginfod_enabled_ask_p Tom de Vries
2026-04-17 7:57 ` [PATCH v6 3/4] [gdb] Add defaulted_query_auto_answers_p Tom de Vries
2026-04-17 7:57 ` Tom de Vries [this message]
2026-04-25 14:40 ` [PATCH v6 0/4] [gdb/tui] Fix crash with debuginfod query Andrew Burgess
2026-05-01 14:26 ` Andrew Burgess
2026-05-01 16:34 ` Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260417075719.852558-5-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox