From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 421AF3857028; Wed, 31 Aug 2022 17:15:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 421AF3857028 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1661966116; bh=GfrDWTcVwEYt71JbQbwLSF0TOh277Hpe2ksMvQl8TcI=; h=From:To:Subject:Date:From; b=HJ+kom1jcIjTij04w4ByNXPDc/4meYhtxwB+IRUG9SKHFTMC9EWx5NM7xYnhl8pCS O3WDiJFQmfrcS9WROZ0vZ9AQq70IVnCrBuD+XIL09yZNqVLoHrb/Nz7Hla+2MPEc/E aGQlKddCYiCaHly6XQ2ddcjJn7LQodClnxDZ6GO8= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Fix interpreter-exec crash X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 1e28eebbbc34ebec69ea4913f7e8d19352e35630 X-Git-Newrev: 058dc2c95935d54caa8891613a1080d57665fc43 Message-Id: <20220831171516.421AF3857028@sourceware.org> Date: Wed, 31 Aug 2022 17:15:16 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D058dc2c95935= d54caa8891613a1080d57665fc43 commit 058dc2c95935d54caa8891613a1080d57665fc43 Author: Tom Tromey Date: Fri Aug 12 13:15:01 2022 -0600 Fix interpreter-exec crash =20 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=3D=3Dnullp= tr. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D10347 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) =20 /* 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 =3D=3D main_ui) + one instance of readline. Also, INSTREAM might be nullptr when + executing a user-defined command. */ + if (ui->instream !=3D nullptr && ISATTY (ui->instream) + && editing && ui =3D=3D 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/int= erp.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\"" "" { } } =20 +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 say= ing just \"end\".\r\n>$" { + pass "$test" + } +} +gdb_test "$commands\nend" "" "finish defining hello command" + +gdb_test "hello" [string_to_regexp "^done,value=3D\"23\""] + if ![runto_main] then { return -1 }