From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sonic301-22.consmr.mail.ir2.yahoo.com (sonic301-22.consmr.mail.ir2.yahoo.com [77.238.176.99]) by sourceware.org (Postfix) with ESMTPS id 0D228385802E for ; Sat, 6 Mar 2021 17:41:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0D228385802E X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1615052490; bh=F8lUUPoL2lP93Z5Ykvd4ToZSg5Jcvxdf8TiYwZMzvcQ=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=iWD6vACBSaz8lP3AHWgcRXJWUl8QW/CzLj6Rk7t+YHr05nnY994TSRyKu4yDAsj8+xjQlNrTL9gIP7Y3MKGHoZsT+GF+nXOMFbs2C+hr7ORnbKLTrjHN9kg3GFXMdoG+ugJwjtZZDHlbxMzKhXkI6RfSFpZ5c6hEpjayWbBgvLi7DI67eFsmSLq9cywNOEXCKlGJ5UrDpIfq4O44nsVqjVE+CqsYdkbaOc2MGk+uKdUwffMu0RytuBTdR0OELaueq0bpSvv9eYqHPOUqKWqxodCY8F8HRCjHf1HAxAmFRKZMrIpfmylky89o3hkxeIc2BPhx/mJBf5dr1lHO0lUWpg== X-YMail-OSG: Cs2wb7UVM1mXox9VI7T0soy6Be7fEFspIf6TcA7hX.NQKMoJOaPT4Wfeh0SA9bd E883l2lQx3At1oOptynqQwRlP5UQA0JrqagyHhN63Z55danipmiG1iCipMMggWTfznwi2kUYPqMX FWI1Wboq9TzBtPNRlzYsIA_i8WYC9xoC2FfhLk4X47z6p.hpDyt2WaGYP5AC28w4Z.kZAubkJQPu quMMivWFVo91iK7oTVr68.5LuNfB3nZHwswTzQg1uEJJA74h7QBGIAstMc4NFWndJKLwGbwgVlLj i69eJkwQmeCzPvem_NgkzamH1vgXnLt7nedo5NcNmLtMzci4Da0xOdLE0WaTi8xMgSvJwRckVtl1 ENmh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v4peNQWGGx8iav5gckMrJU2XnE X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ir2.yahoo.com with HTTP; Sat, 6 Mar 2021 17:41:30 +0000 Received: by smtp405.mail.ir2.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID a5c7f4eda18399a55bb44d180f23ad87; Sat, 06 Mar 2021 17:41:29 +0000 (UTC) From: Hannes Domani To: gdb-patches@sourceware.org Subject: [PATCH 10/22] Add optional styled argument to gdb.execute Date: Sat, 6 Mar 2021 18:40:50 +0100 Message-Id: <20210306174102.21597-1-ssbssa@yahoo.de> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Antivirus: Avast (VPS 210306-0, 03/06/2021), Outbound message X-Antivirus-Status: Clean References: <20210306174102.21597-1-ssbssa.ref@yahoo.de> X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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: Sat, 06 Mar 2021 17:41:33 -0000 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); /* 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. @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; + 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