public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Aktemur, Tankut Baris" <tankut.baris.aktemur@intel.com>
To: "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: Wed, 21 Oct 2020 06:56:39 +0000	[thread overview]
Message-ID: <DM6PR11MB2889D6879D60EF8006F12E08C41C0@DM6PR11MB2889.namprd11.prod.outlook.com> (raw)
In-Reply-To: <1601998842-22089-1-git-send-email-tankut.baris.aktemur@intel.com>

Kindly pinging.

Thanks.
-Baris

On Tuesday, October 6, 2020 5:41 PM, Aktemur, Tankut Baris 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>)]
>   (gdb)
> 
> To fix, also redirect the top-level interpreter's ui-out.
> 
> gdb/ChangeLog:
> 2020-10-06  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
> 
> 	* cli/cli-script.c (execute_control_commands_to_string): Redirect
> 	top level interpreter's ui-out before running the command.
> ---
>  gdb/cli/cli-script.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
> index f8ac610d4d6..21a4065a5f2 100644
> --- a/gdb/cli/cli-script.c
> +++ b/gdb/cli/cli-script.c
> @@ -425,6 +425,10 @@ execute_control_commands_to_string (struct command_line *commands,
>      current_uiout->redirect (&str_file);
>      ui_out_redirect_pop redirect_popper (current_uiout);
> 
> +    ui_out *uiout = top_level_interpreter ()->interp_ui_out ();
> +    uiout->redirect (&str_file);
> +    ui_out_redirect_pop redirect_popper2 (uiout);
> +
>      scoped_restore save_stdout
>        = make_scoped_restore (&gdb_stdout, &str_file);
>      scoped_restore save_stderr
> --
> 2.17.1



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-10-21  6:56 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 [this message]
2020-10-22 16:09 ` Pedro Alves
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=DM6PR11MB2889D6879D60EF8006F12E08C41C0@DM6PR11MB2889.namprd11.prod.outlook.com \
    --to=tankut.baris.aktemur@intel.com \
    --cc=gdb-patches@sourceware.org \
    /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).