public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* Re: [PING] [PATCH 3/4] Add optional styled argument to gdb.execute
       [not found] <1663229521.1186702.1621081645735.ref@mail.yahoo.com>
@ 2021-05-15 12:27 ` Hannes Domani
  2021-05-17 16:20   ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Hannes Domani @ 2021-05-15 12:27 UTC (permalink / raw)
  To: Hannes Domani via Gdb-patches, Tom Tromey

 Ping.


Am Montag, 8. Februar 2021, 19:30:09 MEZ hat Hannes Domani via Gdb-patches <gdb-patches@sourceware.org> Folgendes geschrieben:

> Am Sonntag, 7. Februar 2021, 02:15:01 MEZ hat Tom Tromey <tom@tromey.com> Folgendes geschrieben:
>
> > >>>>> "Hannes" == Hannes Domani via Gdb-patches <gdb-patches@sourceware.org> writes:
> >
> > Hannes> Ping.
> >
> > Hi.  Sorry about the delay on this.
> >
> > >> > > > 2020-12-29  Hannes Domani  <ssbssa@yahoo.de>
> > >> > > >
> > >> > > >     * 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  <ssbssa@yahoo.de>
> > >> > > >
> > >> > > >     * python.texi (Basic Python): Document "styled" argument.
> >
> > I think the general idea is fine, though I feel that a new feature
> > should also include a test case.
>
> For some reason, for me on Windows, the styling is always omitted in the
> testsuite.
> It's the same as in gdb.base/style.exp, all tests checking for the style fail.
>
> But based on style.exp, I came up with this test:
>
> >>>>>>>>>>>>>>>>>>>> py-execute-styled.exp
>
> # Copyright (C) 2021 Free Software Foundation, Inc.
>
> # This program is free software; you can redistribute it and/or modify
> # it under the terms of the GNU General Public License as published by
> # the Free Software Foundation; either version 3 of the License, or
> # (at your option) any later version.
> #
> # This program is distributed in the hope that it will be useful,
> # but WITHOUT ANY WARRANTY; without even the implied warranty of
> # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> # GNU General Public License for more details.
> #
> # You should have received a copy of the GNU General Public License
> # along with this program.  If not, see <http://www.gnu.org/licenses/>.
>
> # Test styled output of gdb.execute().
>
> load_lib gdb-python.exp
>
> standard_testfile py-cmd.c
>
> if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
>     return -1
> }
>
> # Skip all tests if Python scripting is not enabled.
> if { [skip_python_tests] } { continue }
>
> if ![runto_main] then {
>     fail "cannot run to main."
>     return 0
> }
>
> gdb_test_no_output "set style enabled on"
>
> gdb_test "python print (gdb.execute ('bt', to_string=True))" \
>        "#0\[ \t\]*main \\(\\) at \[^\r\n\]+"
>
> set main_expr [style main function]
> set base_file_expr [style ".*py-cmd\\.c" file]
> set file_expr "$base_file_expr:\[0-9\]"
>
> gdb_test "python print (gdb.execute ('bt', to_string=True, styled=True))" \
>        "#0\[ \t\]*$main_expr \\(\\) at $file_expr"
>
> <<<<<<<<<<<<<<<<<<<< py-execute-styled.exp
>
>
> Maybe someone could try it and report back.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PING] [PATCH 3/4] Add optional styled argument to gdb.execute
  2021-05-15 12:27 ` [PING] [PATCH 3/4] Add optional styled argument to gdb.execute Hannes Domani
@ 2021-05-17 16:20   ` Simon Marchi
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2021-05-17 16:20 UTC (permalink / raw)
  To: Hannes Domani, Hannes Domani via Gdb-patches, Tom Tromey

On 2021-05-15 8:27 a.m., Hannes Domani via Gdb-patches wrote:
>  Ping.

Since it's (unfortunately) been a long time, it's not clear to me what's
the status of this.  Especially since there's a patch of the same name
in a larger, more recent series:

  [PATCH 10/22] Add optional styled argument to gdb.execute

It might be clearer to post a clean new version at this point.

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PING] [PATCH 3/4] Add optional styled argument to gdb.execute
       [not found] <306670220.3652381.1610640933525.ref@mail.yahoo.com>
@ 2021-01-14 16:15 ` Hannes Domani
  0 siblings, 0 replies; 3+ messages in thread
From: Hannes Domani @ 2021-01-14 16:15 UTC (permalink / raw)
  To: gdb-patches, Tom Tromey, Simon Marchi

Ping.


Am Donnerstag, 31. Dezember 2020, 05:29:18 MEZ hat Simon Marchi <simon.marchi@polymtl.ca> Folgendes geschrieben:

> 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  <ssbssa@yahoo.de>
> >
> >     * 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  <ssbssa@yahoo.de>
> >
> >     * 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-17 16:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1663229521.1186702.1621081645735.ref@mail.yahoo.com>
2021-05-15 12:27 ` [PING] [PATCH 3/4] Add optional styled argument to gdb.execute Hannes Domani
2021-05-17 16:20   ` Simon Marchi
     [not found] <306670220.3652381.1610640933525.ref@mail.yahoo.com>
2021-01-14 16:15 ` Hannes Domani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).