public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Aktemur, Tankut Baris" <tankut.baris.aktemur@intel.com>
To: Pedro Alves <pedro@palves.net>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: [PATCH] gdb/cli: if redirecting output, also redirect top-level interpreter's ui-out
Date: Fri, 27 Nov 2020 13:19:15 +0000	[thread overview]
Message-ID: <SN6PR11MB2893947D3B4AC1A7FD870ADBC4F80@SN6PR11MB2893.namprd11.prod.outlook.com> (raw)
In-Reply-To: <db033596-f417-f23a-9e9b-0309f863b599@palves.net>

On Thursday, October 22, 2020 6:09 PM, Pedro Alves wrote:
> On 10/6/20 4:40 PM, Tankut Baris Aktemur via Gdb-patches wrote:
> > When executing commands from Python, the API provides an option to
> > capture the command output in a string and return this to the user.
> > See the `gdb.execute` function at
> >
> >   https://sourceware.org/gdb/onlinedocs/gdb/Basic-Python.html#Basic-Python
> >
> > When the `to_string` argument is True, the output of the executed
> > command is supposed to be captured and returned to the caller.  For
> > this, GDB temporarily redirects the ui-outs to a string file.
> >
> > However, output does not get captured if the executed command prints
> > its output through the top-level interpreter's ui-out.  E.g., in the
> > following we still see the output being printed.
> >
> >   (gdb) python gdb.execute("inferior 1", from_tty=False, to_string=True)
> >   [Switching to inferior 1 [<null>] (<noexec>)]
> 
> Note this output is not really considered output of the command.
> It's asynchronous output sent to all UIs in reaction to the
> inferior-switching event.
> 
> If e.g., the top interpreter is MI (say, you run that python from a breakpoint
> command), then you get:
> 
>  (gdb)
>  python gdb.execute("inferior 1", from_tty=False, to_string=True)
>  &"python gdb.execute(\"inferior 1\", from_tty=False, to_string=True)\n"
>  ~"[Switching to inferior 1 [<null>] (/home/pedro/gdb/binutils-gdb/build/gdb/gdb)]\n"
>  ^done
>  (gdb)
> 
> And your patch won't capture that:
> 
>  python str=gdb.execute("inferior 1", from_tty=False, to_string=True)
>  &"python str=gdb.execute(\"inferior 1\", from_tty=False, to_string=True)\n"
>  ~"[Switching to inferior 1 [<null>] (<noexec>)]\n"
>  ^done
>  (gdb)
>  python print(str)
>  &"python print(str)\n"
>  ~"\n"
>  ^done
>  (gdb)

Sorry for the delayed response.  The motivation behind this patch is this: 
We have a Python script via which we create an additional inferior, connect
it to a target, and later remove this inferior.  For the actions for which a
dedicated Python API does not exist, we use gdb.execute().  Switching the
inferior as well as connecting to a target produces output that we want to
hide from the user.  In principle, the goal is to suppress the output on the
CLI to obtain clean command-line interaction, but additionally we would like
to avoid temporary context switches in an IDE, if connected via MI.

Potential solutions:
1.  Expose "cli_suppress_notification" and "mi_suppress_notification" via
maintenance commands.  Use these commands in the Python script via gdb.execute()
to suppress the CLI and MI outputs.

2.  Extend the "add-inferior" command to accept a target string so that an
explicit switch is not necessary to make the target connection.  This would
avoid context switch-related output, but the target connection's output would
still be visible.  Perhaps CLI/MI suppress mechanism has to be used here, again.

3.  Extend the Python API to allow the actions we need (e.g. add a new inferior,
connect it to a target, etc.) instead of gdb.execute().  The Python API suppresses
the output before performing the actual actions.

Suggestions are welcome and appreciated.

Thanks
-Baris


Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

      reply	other threads:[~2020-11-27 13:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-06 15:40 Tankut Baris Aktemur
2020-10-21  6:56 ` Aktemur, Tankut Baris
2020-10-22 16:09 ` Pedro Alves
2020-11-27 13:19   ` Aktemur, Tankut Baris [this message]

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=SN6PR11MB2893947D3B4AC1A7FD870ADBC4F80@SN6PR11MB2893.namprd11.prod.outlook.com \
    --to=tankut.baris.aktemur@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    /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).