From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +r/2Al7obV8xHQAAWB0awg (envelope-from ) for ; Fri, 25 Sep 2020 08:53:50 -0400 Received: by simark.ca (Postfix, from userid 112) id F367A1EF4B; Fri, 25 Sep 2020 08:53:49 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 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 31D8C1E599 for ; Fri, 25 Sep 2020 08:53:47 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4EC35398B14B; Fri, 25 Sep 2020 12:53:46 +0000 (GMT) Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by sourceware.org (Postfix) with ESMTPS id D034C398797D for ; Fri, 25 Sep 2020 12:53:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D034C398797D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wr1-x443.google.com with SMTP id e16so3523546wrm.2 for ; Fri, 25 Sep 2020 05:53:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=WDjKupsMxclNJ4jgC2q0Bg+85i5tTSWhj49jSZInlss=; b=MjX5bllCgKDNjUmXoywjKrcFjsQWPmSH6SKOz8GYiAIde/38sYLIVSgk4W6yhperaG vegh4MV7tteghfWU+Rmb7duOR97poMba/NcZG9lwBNJvGA72wtAa6lianZBRE1JcrEx0 ZlFMONO76U7IPhMCGsey7BaW04qjuEIRoXMcgOgLLrsmA4GgbdA666elghBZE6jNX0he ORWvfe7Wtz2yAhAu63WJtQ8Yl7K09ygnXBPJFTubyms1a0iwWzcDlC7FaAA78Wln+OPb lSphZgHERrJ9RnWw3IBfCAW4pdV7NiQOH3XtSz1diMAz8klHB5PyQEXyKnrwurEOVgMH Sz/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=WDjKupsMxclNJ4jgC2q0Bg+85i5tTSWhj49jSZInlss=; b=P0ONzYDmDwZjdHwrFm84w4SJIMP7S7IIyp/q8fhxlIzYdHvH5iYnYwT1WDp/t4CHvt YnIQkC8a1n7b2sruZFEbBlJCgu1/Q8xuiCVVtQhepueOzLXx1Q57GvUIIyOhgb+eRdWr 8lNjKlNslaWQg58rlGeCb2myEAPdeHZWclrj9el9Nt8Bc8KWkd80Dx4FmWvnlgLQ5EVm 7UguB37bV7ow16MrcfqvW/2NHtLft1vj642dseJ0ljKub30cibp2ToAmHcbL4sF8sBrt BrYIYdSIHk/37o9ac0All+VrLEfwb3oZjXM/IMNyl7Yywzg4IExHOzEq62DB5hGCNSXG QIQQ== X-Gm-Message-State: AOAM532TsUIfuH9FJCMu79x5+EPVxdQd6LwUS06Si61nYFV7nYrxqh7I kuz6Ggr+ANyFT7FJ7d7akGVBsA== X-Google-Smtp-Source: ABdhPJyEUhnmD86yXYIWQ1w6KMVlydANXXjqNqENnV/kP6tEtdtO2zS2e6JXvAY4d196OVvXj5Cr4Q== X-Received: by 2002:a5d:660d:: with SMTP id n13mr4510265wru.308.1601038422788; Fri, 25 Sep 2020 05:53:42 -0700 (PDT) Received: from localhost (host109-151-23-62.range109-151.btcentralplus.com. [109.151.23.62]) by smtp.gmail.com with ESMTPSA id n2sm3093730wma.29.2020.09.25.05.53.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:53:42 -0700 (PDT) Date: Fri, 25 Sep 2020 13:53:40 +0100 From: Andrew Burgess To: Gareth Rees Subject: Re: [PATCH] gdb: Fix from_tty argument to gdb.execute in Python. Message-ID: <20200925125340.GM1540618@embecosm.com> References: <20200922102343.8440-1-grees@undo.io> <20200922135157.GH1540618@embecosm.com> <20200924110912.GK1540618@embecosm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: Linux/5.8.9-101.fc31.x86_64 (x86_64) X-Uptime: 13:52:31 up 6 days, 21:00, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] 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: , Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" * Gareth Rees [2020-09-24 12:16:32 +0100]: > Here's a patch with a comment and commit message updated to use "nullptr" > instead of "0". LGTM. Do you have commit access to push this? Thanks, Andrew > From 7efaa3657c8b72c128675b27a2cb2f21e2e05b14 Mon Sep 17 00:00:00 2001 > From: Gareth Rees > Date: Tue, 8 Sep 2020 15:52:44 +0100 > Subject: [PATCH] gdb: Fix from_tty argument to gdb.execute in Python. > > Prior to commit 56bcdbea2b, the from_tty keyword argument to the > Python function gdb.execute controlled whether the command took input > from the terminal. When from_tty=True, "starti" and similar commands > prompted the user: > > (gdb) python gdb.execute("starti", from_tty=True) > The program being debugged has been started already. > Start it from the beginning? (y or n) y > Starting program: /bin/true > > Program stopped. > > When from_tty=False, these commands did not prompt the user, and "yes" > was assumed: > > (gdb) python gdb.execute("starti", from_tty=False) > > Program stopped. > > However, after commit 56bcdbea2b, the from_tty keyword argument no > longer had this effect. For example, as of commit 7ade7fba75: > > (gdb) python gdb.execute("starti", from_tty=True) > The program being debugged has been started already. > Start it from the beginning? (y or n) [answered Y; input not from terminal] > Starting program: /bin/true > > Program stopped. > > Note the "[answered Y; input not from terminal]" in the output even > though from_tty=True was requested. > > Looking at commit 56bcdbea2b, it seems that the behaviour of the > from_tty argument was changed accidentally. The commit message said: > > Let gdb.execute handle multi-line commands > > This changes the Python API so that gdb.execute can now handle > multi-line commands, like "commands" or "define". > > and there was no mention of changing the effect of the from_tty > argument. It looks as though the code for setting the instream to > nullptr was accidentally moved from execute_user_command() to > execute_control_commands() along with the other scoped restores. > > Accordingly, the simplest way to fix this is to partially reverse > commit 56bcdbea2b by moving the code for setting the instream to > nullptr back to execute_user_command() where it was to begin with. > > Additionally, add a test case to reduce the risk of similar breakage > in future. > > gdb/ChangeLog: > > * cli/cli-script.c (execute_control_commands): don't set > instream to nullptr here as this breaks the from_tty argument > to gdb.execute in Python. > (execute_user_command): set instream to nullptr here instead. > > gdb/testsuite/ChangeLog: > > * gdb.python/python.exp: add test cases for the from_tty > argument to gdb.execute. > --- > gdb/cli/cli-script.c | 9 +++++---- > gdb/testsuite/gdb.python/python.exp | 13 +++++++++++++ > 2 files changed, 18 insertions(+), 4 deletions(-) > > diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c > index da4a41023a..f8ac610d4d 100644 > --- a/gdb/cli/cli-script.c > +++ b/gdb/cli/cli-script.c > @@ -392,10 +392,6 @@ execute_cmd_post_hook (struct cmd_list_element *c) > void > execute_control_commands (struct command_line *cmdlines, int from_tty) > { > - /* Set the instream to 0, indicating execution of a > - user-defined function. */ > - scoped_restore restore_instream > - = make_scoped_restore (¤t_ui->instream, nullptr); > scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); > scoped_restore save_nesting > = make_scoped_restore (&command_nest_depth, command_nest_depth + 1); > @@ -464,6 +460,11 @@ execute_user_command (struct cmd_list_element *c, const char *args) > if (user_args_stack.size () > max_user_call_depth) > error (_("Max user call depth exceeded -- command aborted.")); > > + /* Set the instream to nullptr, indicating execution of a > + user-defined function. */ > + scoped_restore restore_instream > + = make_scoped_restore (¤t_ui->instream, nullptr); > + > execute_control_commands (cmdlines, 0); > } > > diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp > index a031ea5a18..017f33afe5 100644 > --- a/gdb/testsuite/gdb.python/python.exp > +++ b/gdb/testsuite/gdb.python/python.exp > @@ -526,3 +526,16 @@ gdb_test "print \$cvar3" "= void" \ > # Test PR 23669, the following would invoke the "commands" command instead of > # "show commands". > gdb_test "python gdb.execute(\"show commands\")" "$decimal print \\\$cvar3.*" > + > +# Test that the from_tty argument to gdb.execute is effective. If > +# False, the user is not prompted for decisions such as restarting the > +# program, and "yes" is assumed. If True, the user is prompted. > +gdb_test "python gdb.execute('starti', from_tty=False)" \ > + "Program stopped.*" \ > + "starti via gdb.execute, not from tty" > +gdb_test_multiple "python gdb.execute('starti', from_tty=True)" \ > + "starti via gdb.execute, from tty" { > + -re {The program being debugged has been started already\.\r\nStart it from the beginning\? \(y or n\) $} { > + gdb_test "y" "Starting program:.*" "starti via interactive input" > + } > +} > -- > 2.26.0 >