public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Fix interpreter-exec crash
@ 2022-08-31 17:15 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-08-31 17:15 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=058dc2c95935d54caa8891613a1080d57665fc43

commit 058dc2c95935d54caa8891613a1080d57665fc43
Author: Tom Tromey <tromey@adacore.com>
Date:   Fri Aug 12 13:15:01 2022 -0600

    Fix interpreter-exec crash
    
    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

Diff:
---
 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 1b522a77d79..290c3d87744 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -1332,8 +1332,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
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-31 17:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-31 17:15 [binutils-gdb] Fix interpreter-exec crash Tom Tromey

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).