From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 17BA5385AC12 for ; Mon, 8 Mar 2021 10:01:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 17BA5385AC12 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-wm1-x336.google.com with SMTP id m20-20020a7bcb940000b029010cab7e5a9fso3410318wmi.3 for ; Mon, 08 Mar 2021 02:01:13 -0800 (PST) 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=9N2gXFSXJLHYp3KW2MSDuWgyRyEjSLww5x6YzgLTriQ=; b=UwY1EbXfRfnzzqYnAWwU11hKxND7PdZ6h9ZjKwjtYewoN59Jzd6bTc9dhK0cGTbGLq v96qnek0Wb4olOJ/jDLYBglM1lyCwdzEwT3ys+CHu6iaHn8Ac6WXI0J3cL0Efq6QOU2c 7EBixT3kyLRJ5h+tOpXcqbcARi7tSF0SltYXOJyTOmYS55/gPKGocDUyDTAALAMpjo+x ARcP9y5DcfOv2xluKGKjMamtLF2Qhu86n10VN6COBVlIvLG96KDL0u7G/IuslzdSBH5N PXmz70NJPwHJUmEYemddBnB/9g2SLnB1+/XW3yXCRvFHm+SsDuaKz3njiV6dxjBPtw4K Kcsg== 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=9N2gXFSXJLHYp3KW2MSDuWgyRyEjSLww5x6YzgLTriQ=; b=bEBv27RzhJtw90bRV7BI4HzLJSC41UD/myVUGEoQw/27omxG9eNjusgyHf1RTccx3E +SpxZFPJnonc/8HgmbRHyPar4RuSbKkPl93K5yaKTre+ngtQaj2Ipp6+to5fmXMczFp5 YwM38/ag822B5Xb7Uy7Ek+f6bfROxPu34i9q/Y7gcPF1h63zLGHMnl40khqmf7MyhCIe 1nDDKl3MbOq5aX+LeMOIu4v1sB38s1v4tgMuYJT0fHpAtigY9yGy7UjwNbiHaZX8k9Ak JRudWbC0c5ryiAXp2QqNKaLv/mh2wFPOCMKUhv1AYsWtGftuDZ0zSq2pv23Cf6+U9urW tCNg== X-Gm-Message-State: AOAM532jZYqHCIeKt9IFFXeQnVROWKnmXBWiluNlkkd0AoHrnlB6v/uE D564o0U1DOL+05TSuU34GVMoq9nFLHtdRw== X-Google-Smtp-Source: ABdhPJwyyVT7+ABThtbD8V0efjO6bWQxG7Iz1mUlZSWEiJx2WxYWj9n8ykBc87xGAF6SqQD3fwDk2g== X-Received: by 2002:a7b:cc0c:: with SMTP id f12mr21426864wmh.137.1615197672160; Mon, 08 Mar 2021 02:01:12 -0800 (PST) Received: from localhost (host86-134-238-232.range86-134.btcentralplus.com. [86.134.238.232]) by smtp.gmail.com with ESMTPSA id z2sm5860289wrv.47.2021.03.08.02.01.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 02:01:11 -0800 (PST) Date: Mon, 8 Mar 2021 10:01:11 +0000 From: Andrew Burgess To: Hannes Domani Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 10/22] Add optional styled argument to gdb.execute Message-ID: <20210308100111.GL1720904@embecosm.com> References: <20210306174102.21597-1-ssbssa.ref@yahoo.de> <20210306174102.21597-1-ssbssa@yahoo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210306174102.21597-1-ssbssa@yahoo.de> X-Operating-System: Linux/5.8.13-100.fc31.x86_64 (x86_64) X-Uptime: 09:52:54 up 89 days, 14:37, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Spam-Status: No, score=-11.6 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 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, 08 Mar 2021 10:01:14 -0000 * Hannes Domani via Gdb-patches [2021-03-06 18:40:50 +0100]: > 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 9d0dd7796e0..8729c7c7132 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 8624bf55839..57cfff4ba33 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); The comment immediately above this function needs updating. > > /* Exported to gdb/breakpoint.c */ > > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi > index 97a28d054fa..565e87d0784 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. I think this leaves out a lot of information. You need to mention that `styled` is optional, and that the default is false. You should also be explicit that when `to_string` is false `styled` is ignored, something like: The optional argument @var{styled} defaults to @code{True}. 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. If @var{to_string} is @code{False} then @var{styled} is ignored. > @end defun > > @findex gdb.breakpoints > diff --git a/gdb/python/python.c b/gdb/python/python.c > index 009c0c4c6d7..e4e00e4627c 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; That `from_tty` and `to_string` are int is a legacy of GDB's past. The new `styled` should be bool. Thanks, Andrew > + 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); > } > -- > 2.30.1 >