public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Marco Barisione <mbarisione@undo.io>
To: Hannes Domani <ssbssa@yahoo.de>
Cc: GDB patches mailing list <gdb-patches@sourceware.org>,
	Simon Marchi <simon.marchi@polymtl.ca>
Subject: Re: [PATCHv2] Add optional styled argument to gdb.execute
Date: Thu, 20 May 2021 18:03:33 +0100	[thread overview]
Message-ID: <78173C52-C72D-4135-8580-374CEB008360@undo.io> (raw)
In-Reply-To: <825504811.4306871.1621528447747@mail.yahoo.com>

On 20 May 2021, at 17:34, Hannes Domani via Gdb-patches <gdb-patches@sourceware.org> wrote:
> Am Donnerstag, 20. Mai 2021, 18:12:47 MESZ hat Simon Marchi <simon.marchi@polymtl.ca> Folgendes geschrieben:
> 
>> On 2021-05-20 11:42 a.m., Hannes Domani wrote:
>>> When I call gdb.execute() with to_string=False, the output to stdout is colored,
>>> so do you mean styled=False should disable the colors?
>> 
>> Yes.  Well, I'm asking whether we might want that in the future (to be
>> able to control styling when using gdb.execute with to_string=False).
>> If we might want that in the future, I think it would be natural to use
>> the "styled" parameter for this.  And so I ask whether a simple
>> True/False boolean will be enough for this, given that True/False would
>> (presumably) force the styling to on or off.  Will there be a need for a
>> third (default) value to say "do whatever the default is"?
> 
> I'm not sure it's necessary, anyone who wants styling enabled/disabled,
> can call gdb.execute(to_string=True) with styled True/False, and just print
> the output string.

This is not the same as the command may take time, so you don’t want to
delay the printing until the command is finished.


In the project I work on, I use an older version of this patch (which,
by the way, works great).  My use case is to get the output of the
command, do some stuff to it and print it back.

Simon,  I’m not sure I understand correctly your proposal about
using None/True/False.  Do you mean that when styled=True the output
would be styled even if you did "set style enabled off"?
I think this would make writing code more complicated as there would
be no easy way to achieve what I think is the patch’s original purpose,
i.e. just get a string containing what GDB would have printed to the
terminal.

On the other hand, disabling styling temporarily is trivial.  I use
code similar to this in the project I work on:

    @contextlib.contextmanager
    def style_disabled():
        enabled_before = gdb.parameter("style enabled")

        try:
            gdb.execute("set style enabled off")
            yield
        finally:
            if enabled_before:
                gdb.execute("set style enabled on")


    with style_disabled():
        gdb.execute("backtrace")


-- 
Marco Barisione


  reply	other threads:[~2021-05-20 17:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210519172649.2935-1-ssbssa.ref@yahoo.de>
2021-05-19 17:26 ` Hannes Domani
2021-05-19 17:34   ` Eli Zaretskii
2021-05-20 15:18   ` Simon Marchi
2021-05-20 15:42     ` Hannes Domani
2021-05-20 16:12       ` Simon Marchi
2021-05-20 16:34         ` Hannes Domani
2021-05-20 17:03           ` Marco Barisione [this message]
2021-05-20 17:49             ` Simon Marchi
2021-05-20 18:02               ` Hannes Domani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=78173C52-C72D-4135-8580-374CEB008360@undo.io \
    --to=mbarisione@undo.io \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    --cc=ssbssa@yahoo.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).