From: Pedro Alves <pedro@palves.net>
To: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>,
gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb/cli: if redirecting output, also redirect top-level interpreter's ui-out
Date: Thu, 22 Oct 2020 17:09:15 +0100 [thread overview]
Message-ID: <db033596-f417-f23a-9e9b-0309f863b599@palves.net> (raw)
In-Reply-To: <1601998842-22089-1-git-send-email-tankut.baris.aktemur@intel.com>
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)
next prev parent reply other threads:[~2020-10-22 16:09 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 [this message]
2020-11-27 13:19 ` Aktemur, Tankut Baris
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=db033596-f417-f23a-9e9b-0309f863b599@palves.net \
--to=pedro@palves.net \
--cc=gdb-patches@sourceware.org \
--cc=tankut.baris.aktemur@intel.com \
/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).