[PATCH] gdb/cli: if redirecting output, also redirect top-level interpreter's ui-out
Aktemur, Tankut Baris
tankut.baris.aktemur@intel.com
Fri Nov 27 13:19:15 GMT 2020
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
More information about the Gdb-patches
mailing list