public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 14/14] Fix interpreter-exec crash
Date: Fri, 12 Aug 2022 18:54:42 -0600	[thread overview]
Message-ID: <20220813005442.4163512-15-tromey@adacore.com> (raw)
In-Reply-To: <20220813005442.4163512-1-tromey@adacore.com>

PR mi/10347 points out that using interpreter-exec inside of a
"define" command will crash gdb.  The bug here is that
gdb_setup_readline doesn't check for the case where instream==nullptr.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=10347
---
 gdb/event-top.c                   |  6 ++++--
 gdb/testsuite/gdb.base/interp.exp | 11 +++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/gdb/event-top.c b/gdb/event-top.c
index 151849c01ea..a131b571213 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -1330,8 +1330,10 @@ gdb_setup_readline (int editing)
 
   /* If the input stream is connected to a terminal, turn on editing.
      However, that is only allowed on the main UI, as we can only have
-     one instance of readline.  */
-  if (ISATTY (ui->instream) && editing && ui == main_ui)
+     one instance of readline.  Also, INSTREAM might be nullptr when
+     executing a user-defined command.  */
+  if (ui->instream != nullptr && ISATTY (ui->instream)
+      && editing && ui == main_ui)
     {
       /* Tell gdb that we will be using the readline library.  This
 	 could be overwritten by a command in .gdbinit like 'set
diff --git a/gdb/testsuite/gdb.base/interp.exp b/gdb/testsuite/gdb.base/interp.exp
index f748ffd8050..3db90f64103 100644
--- a/gdb/testsuite/gdb.base/interp.exp
+++ b/gdb/testsuite/gdb.base/interp.exp
@@ -79,6 +79,17 @@ gdb_test_multiple "interpreter-exec mi3 \"-break-insert main\"" "" {
     }
 }
 
+set test "define hello command"
+set commands "interpreter-exec mi3 \"-data-evaluate-expression 23\""
+gdb_test_multiple "define hello" "$test" {
+    -re "Type commands for definition of \"hello\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+	pass "$test"
+    }
+}
+gdb_test "$commands\nend" "" "finish defining hello command"
+
+gdb_test "hello" [string_to_regexp "^done,value=\"23\""]
+
 if ![runto_main] then {
   return -1
 }
-- 
2.34.1


  parent reply	other threads:[~2022-08-13  0:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-13  0:54 [PATCH 00/14] Minor ui / interp cleanups Tom Tromey
2022-08-13  0:54 ` [PATCH 01/14] Remove some dead code Tom Tromey
2022-08-13  0:54 ` [PATCH 02/14] Free ui::line_buffer Tom Tromey
2022-08-13  0:54 ` [PATCH 03/14] Use ui_out_redirect_pop in more places Tom Tromey
2022-08-13  0:54 ` [PATCH 04/14] Remove the "for moment" comments Tom Tromey
2022-08-13  0:54 ` [PATCH 05/14] Remove obsolete filtering comment Tom Tromey
2022-08-13  0:54 ` [PATCH 06/14] Remove two unused members from mi_interp Tom Tromey
2022-08-13  0:54 ` [PATCH 07/14] Use member initialization in 'struct ui' Tom Tromey
2022-08-13  0:54 ` [PATCH 08/14] Use scoped_restore in safe_parse_type Tom Tromey
2022-08-13  0:54 ` [PATCH 09/14] Remove tui_out_new Tom Tromey
2022-08-13  0:54 ` [PATCH 10/14] Remove a ui-related memory leak Tom Tromey
2022-08-13  0:54 ` [PATCH 11/14] TUI stdout buffering cleanup Tom Tromey
2022-08-13  0:54 ` [PATCH 12/14] Remove a call to clear_interpreter_hooks Tom Tromey
2022-08-13  0:54 ` [PATCH 13/14] Fix "source" with interpreter-exec Tom Tromey
2022-08-13  1:58   ` Enze Li
2022-08-15 17:28     ` Tom Tromey
2022-08-13  0:54 ` Tom Tromey [this message]
2022-08-31 17:13 ` [PATCH 00/14] Minor ui / interp cleanups Tom Tromey

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=20220813005442.4163512-15-tromey@adacore.com \
    --to=tromey@adacore.com \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).