From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 2F70C389244E for ; Mon, 24 May 2021 18:25:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2F70C389244E Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-589-7DMYo9plMsaeJ8qXyr0ZXA-1; Mon, 24 May 2021 14:25:57 -0400 X-MC-Unique: 7DMYo9plMsaeJ8qXyr0ZXA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 501D7180FD69; Mon, 24 May 2021 18:25:56 +0000 (UTC) Received: from [10.3.112.40] (ovpn-112-40.phx2.redhat.com [10.3.112.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0C52560C05; Mon, 24 May 2021 18:25:55 +0000 (UTC) Subject: Re: [PATCH] gdb: Don't change the uiout to console one when doing gdb.execute in TUI To: Marco Barisione , gdb-patches@sourceware.org References: <20210520153722.17526-1-mbarisione@undo.io> From: Keith Seitz Message-ID: <6f0cf89e-0eca-e8fc-5826-58937bdaad0d@redhat.com> Date: Mon, 24 May 2021 11:25:55 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210520153722.17526-1-mbarisione@undo.io> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Mon, 24 May 2021 18:26:00 -0000 On 5/20/21 8:37 AM, Marco Barisione via Gdb-patches wrote: > > This fix changes gdb.execute to only change current_uiout while in MI. > This seems reasonable to me, but please wait for a maintainer's approval. I have just a few minor comments. > gdb/ChangeLog: > > * python/python.c (execute_gdb_command): Change currently_uiout > only when in MI to avoid breaking TUI mode. s/currently/current/ ? > > gdb/testsuite/ChangeLog: > > * gdb.python/py-execute-in-tui.c: New test. > * gdb.python/py-execute-in-tui.exp: New test. > --- > gdb/python/python.c | 12 ++- > gdb/testsuite/gdb.python/py-execute-in-tui.c | 22 ++++++ > .../gdb.python/py-execute-in-tui.exp | 74 +++++++++++++++++++ > 3 files changed, 104 insertions(+), 4 deletions(-) > create mode 100644 gdb/testsuite/gdb.python/py-execute-in-tui.c > create mode 100644 gdb/testsuite/gdb.python/py-execute-in-tui.exp > > diff --git a/gdb/python/python.c b/gdb/python/python.c > index 4cea83c3837..881dd1275f4 100644 > --- a/gdb/python/python.c > +++ b/gdb/python/python.c > @@ -630,10 +630,14 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) > > scoped_restore save_uiout = make_scoped_restore (¤t_uiout); > > - /* Use the console interpreter uiout to have the same print format > - for console or MI. */ > - interp = interp_lookup (current_ui, "console"); > - current_uiout = interp->interp_ui_out (); > + /* When in MI, use the console interpreter uiout to have the same > + print format as console. It's important the uiout is not > + changed in TUI mode, otherwise the output can get garbled. */ I appreciate the comment! > + if (current_uiout->is_mi_like_p ()) > + { > + interp = interp_lookup (current_ui, INTERP_CONSOLE); > + current_uiout = interp->interp_ui_out (); > + } > > if (to_string) > to_string_res = execute_control_commands_to_string (lines.get (), > diff --git a/gdb/testsuite/gdb.python/py-execute-in-tui.exp b/gdb/testsuite/gdb.python/py-execute-in-tui.exp > new file mode 100644 > index 00000000000..de033aee7d6 > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-execute-in-tui.exp > @@ -0,0 +1,74 @@ I realize this file is copied from another test, however, in the interests of keeping the code clean(er)... > +if ![runto_main] then { > + fail "can't run to main" > + return > +} Please maintain a consistent Tcl style here. [Again, I realize this is copy/paste.] The canonical way to do `if' statements in modern Tcl is if {cond} { } [Modern Tcl? Oxymoron? :-)] > + > +# A backtrace executed via gdb.execute must produce something like this: > +# #0 main () at foo.c:42 > +# Where the function name is styled. "\x1b" is the start of an ANSI > +# escape sequence to style the function name. > + > +set gdb_execute_backtrace "python gdb.execute ('backtrace')" > +set expected_backtrace_styled_output ".*#0.*\x1b.*main.*" > + > +gdb_test $gdb_execute_backtrace $expected_backtrace_styled_output \ > + "backtrace from gdb.execute without TUI" > + > +# After entering TUI mode, the behaviour must remain the same. > + > +if {![Term::enter_tui]} { > + unsupported "TUI not supported" > + return > +} > + > +# We can't use Term::command and Term::check_contents as that drops the > +# ANSI escape codes. > +send_gdb "${gdb_execute_backtrace}\n" > +set test_name "backtrace from gdb.execute with TUI" > +gdb_expect { > + -re $expected_backtrace_styled_output { > + pass $test_name > + } > + timeout { > + fail $test_name > + } > +} > We normally use gdb_test instead of gdb_send/gdb_expect. Is it not possible here? Keith