From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Oi45JJJT7V+2GwAAWB0awg (envelope-from ) for ; Wed, 30 Dec 2020 23:29:06 -0500 Received: by simark.ca (Postfix, from userid 112) id 83A511F0AA; Wed, 30 Dec 2020 23:29:06 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [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 2E6AD1E965 for ; Wed, 30 Dec 2020 23:29:06 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9F06E385803C; Thu, 31 Dec 2020 04:29:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F06E385803C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1609388945; bh=UtgpnYHypjuu4MaMEgzmufywpwwePiuFzhI9bOhAUUI=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fd5oauEB4MRX8CeAWy4pZRRkDWX2ZFln0+QNE5epvsVPPl0gTnqkzGnUeDjkWzjBV YL/vunDMVvp9fqge7tFXO+jO6Uqbp6lBtbj/nig8K0K0qiez2nvF+4JA8FgZ4OSNkr z0GotuDZcnks0AqkoykU4eXwcNfw0qIcU8fCW/24= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 9221F385803C for ; Thu, 31 Dec 2020 04:29:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9221F385803C Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 0BV4SvpR010159 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Dec 2020 23:29:02 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 0BV4SvpR010159 Received: from [10.0.0.213] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id D83021E965; Wed, 30 Dec 2020 23:28:57 -0500 (EST) Subject: Re: [PATCH 3/4] Add optional styled argument to gdb.execute To: Hannes Domani , gdb-patches@sourceware.org, Tom Tromey References: <20201229170227.821-1-ssbssa@yahoo.de> <20201229170227.821-3-ssbssa@yahoo.de> Message-ID: <96a1f992-0ba5-944c-3f8c-23cfb8ad3664@polymtl.ca> Date: Wed, 30 Dec 2020 23:28:57 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20201229170227.821-3-ssbssa@yahoo.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 31 Dec 2020 04:28:58 +0000 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: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 2020-12-29 12:02 p.m., Hannes Domani via Gdb-patches wrote: > This makes it possible to use the colored output of commands, e.g. for > a custom TuiWindow. > > gdb/ChangeLog: > > 2020-12-29 Hannes Domani > > * cli/cli-script.c (execute_control_commands_to_string): Use > styled argument. > * cli/cli-script.h (execute_control_commands_to_string): Add > styled argument. > * python/python.c (execute_gdb_command): Parse "styled" argument. > > gdb/doc/ChangeLog: > > 2020-12-29 Hannes Domani > > * python.texi (Basic Python): Document "styled" argument. > --- > gdb/cli/cli-script.c | 4 ++-- > gdb/cli/cli-script.h | 2 +- > gdb/doc/python.texi | 6 +++++- > gdb/python/python.c | 24 ++++++++++++++++++------ > 4 files changed, 26 insertions(+), 10 deletions(-) > > diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c > index c9c4a713de..273f925cbc 100644 > --- a/gdb/cli/cli-script.c > +++ b/gdb/cli/cli-script.c > @@ -422,13 +422,13 @@ execute_control_commands (struct command_line *cmdlines, int from_tty) > > std::string > execute_control_commands_to_string (struct command_line *commands, > - int from_tty) > + int from_tty, bool styled) > { > /* GDB_STDOUT should be better already restored during these > restoration callbacks. */ > set_batch_flag_and_restore_page_info save_page_info; > > - string_file str_file; > + string_file str_file (styled); > > { > current_uiout->redirect (&str_file); > diff --git a/gdb/cli/cli-script.h b/gdb/cli/cli-script.h > index 6ad6e61fb4..2ca9f13d4f 100644 > --- a/gdb/cli/cli-script.h > +++ b/gdb/cli/cli-script.h > @@ -135,7 +135,7 @@ extern void execute_control_commands (struct command_line *cmdlines, > will be temporarily set to true. */ > > extern std::string execute_control_commands_to_string > - (struct command_line *commands, int from_tty); > + (struct command_line *commands, int from_tty, bool styled = false); > > /* Exported to gdb/breakpoint.c */ > > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi > index 51f6d1aa05..c97866e9fc 100644 > --- a/gdb/doc/python.texi > +++ b/gdb/doc/python.texi > @@ -217,7 +217,7 @@ A string containing the python directory (@pxref{Python}). > @end defvar > > @findex gdb.execute > -@defun gdb.execute (command @r{[}, from_tty @r{[}, to_string@r{]]}) > +@defun gdb.execute (command @r{[}, from_tty @r{[}, to_string @r{[}, styled@r{]]]}) > Evaluate @var{command}, a string, as a @value{GDBN} CLI command. > If a GDB exception happens while @var{command} runs, it is > translated as described in @ref{Exception Handling,,Exception Handling}. > @@ -234,6 +234,10 @@ returned as a string. The default is @code{False}, in which case the > return value is @code{None}. If @var{to_string} is @code{True}, the > @value{GDBN} virtual terminal will be temporarily set to unlimited width > and height, and its pagination will be disabled; @pxref{Screen Size}. > + > +If both @var{to_string} and @var{styled} are @code{True}, then the returned > +string also contains the ANSI terminal escape styling sequences used for > +colored output. > @end defun > > @findex gdb.breakpoints > diff --git a/gdb/python/python.c b/gdb/python/python.c > index bf3abdbbbe..eb9f8fb4fe 100644 > --- a/gdb/python/python.c > +++ b/gdb/python/python.c > @@ -574,13 +574,15 @@ static PyObject * > execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) > { > const char *arg; > - PyObject *from_tty_obj = NULL, *to_string_obj = NULL; > - int from_tty, to_string; > - static const char *keywords[] = { "command", "from_tty", "to_string", NULL }; > + PyObject *from_tty_obj = NULL, *to_string_obj = NULL, *styled_obj = NULL; > + int from_tty, to_string, styled; > + static const char *keywords[] = { "command", "from_tty", "to_string", > + "styled", NULL }; > > - if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg, > + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!O!", keywords, &arg, > &PyBool_Type, &from_tty_obj, > - &PyBool_Type, &to_string_obj)) > + &PyBool_Type, &to_string_obj, > + &PyBool_Type, &styled_obj)) > return NULL; > > from_tty = 0; > @@ -601,6 +603,15 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) > to_string = cmp; > } > > + styled = 0; > + if (styled_obj) > + { > + int cmp = PyObject_IsTrue (styled_obj); > + if (cmp < 0) > + return NULL; > + styled = cmp; > + } > + > std::string to_string_res; > > scoped_restore preventer = prevent_dont_repeat (); > @@ -638,7 +649,8 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) > > if (to_string) > to_string_res = execute_control_commands_to_string (lines.get (), > - from_tty); > + from_tty, > + styled); > else > execute_control_commands (lines.get (), from_tty); > } > I think that also makes sense, but I'd like if Tom could give it a quick look too. Simon