From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 0Dv8Gun29mK29CUAWB0awg (envelope-from ) for ; Fri, 12 Aug 2022 20:57:13 -0400 Received: by simark.ca (Postfix, from userid 112) id 6B8091E745; Fri, 12 Aug 2022 20:57:13 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=pP9a6VF+; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id EA7B21E13B for ; Fri, 12 Aug 2022 20:57:12 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9ADA9385C32C for ; Sat, 13 Aug 2022 00:57:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9ADA9385C32C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1660352232; bh=i1dxSoK9xljMDuAuGWVLgfuplzox5jIzAaVH/3y/mj8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=pP9a6VF+bXjtzJApAiuz45M5EVxQiQyj4CuZx5MRK2RedsZWglc9DqCz1i7rwrZJP ZxuksXWPrtUMRRFpLCnbCqBV3tBs9oc2oCt1YexExfXp0p/jA0X6VsGMph+tLUnEMA jCZy7hwqadAGyxdjYGMWlsw8RL9dvt4ou4/evhs8= 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) To: gdb-patches@sourceware.org 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-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: , From: Tom Tromey via Gdb-patches Reply-To: Tom Tromey Cc: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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