From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id 144C83858427 for ; Sat, 13 Aug 2022 00:54:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 144C83858427 Received: by mail-il1-x12c.google.com with SMTP id x2so1294281ilp.10 for ; Fri, 12 Aug 2022 17:54:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=i1dxSoK9xljMDuAuGWVLgfuplzox5jIzAaVH/3y/mj8=; b=Vc1nkXzGbzAqmJ4uYWXmafJE4HZHY8LL3i3Rfc0/D829NWnX0EYmazLjdA0MpWwviV 3Gv5ZidbdAXWaRxs92O6Tdo7la5T0rbgldAJM8ZsT5iqTzUvhkqxcRndY8lBb96uBIqL iuhyxerPzraYgUK/ofx7AMHyayA7krFjaFID3F+RTL24bl1HJvRRgao9CFXtmRIUdQ9l PqNjSq26R0vnfg8V2xevgIGmZb0R9PlxOAnBUZVD7ExMAiW8OwbylOTwRrZkz4tkL7ES FU2YDQReB1R5r6LdoL+SZw5czmtkquxDkHF3YToBmv437gho2NyJvQDaRtd6nP0m6ciZ Aqpg== X-Gm-Message-State: ACgBeo1o5GVxAo6J5UPS/nqJG/yctEm+9DdF2mxktVplp88yKUD1BOsK +eNYJP7hShuJlAPq2ptf2E83k38JH9Fx4g== X-Google-Smtp-Source: AA6agR7b335ecm4Vp2a7SqD1hyOtKt66Z8E5jTy8eLM17cd4SwskD/VwCECagxJONqOK46tnV+7Spw== X-Received: by 2002:a05:6e02:1ca5:b0:2df:3283:b4a8 with SMTP id x5-20020a056e021ca500b002df3283b4a8mr3084544ill.131.1660352093806; Fri, 12 Aug 2022 17:54:53 -0700 (PDT) Received: from murgatroyd.Home (71-211-185-228.hlrn.qwest.net. [71.211.185.228]) by smtp.gmail.com with ESMTPSA id p17-20020a056638217100b00343455007f7sm494366jak.110.2022.08.12.17.54.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Aug 2022 17:54:53 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 14/14] Fix interpreter-exec crash Date: Fri, 12 Aug 2022 18:54:42 -0600 Message-Id: <20220813005442.4163512-15-tromey@adacore.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220813005442.4163512-1-tromey@adacore.com> References: <20220813005442.4163512-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Aug 2022 00:54:55 -0000 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