public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/cli: if redirecting output, also redirect top-level interpreter's ui-out
@ 2020-10-06 15:40 Tankut Baris Aktemur
  2020-10-21  6:56 ` Aktemur, Tankut Baris
  2020-10-22 16:09 ` Pedro Alves
  0 siblings, 2 replies; 4+ messages in thread
From: Tankut Baris Aktemur @ 2020-10-06 15:40 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-27 13:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-06 15:40 [PATCH] gdb/cli: if redirecting output, also redirect top-level interpreter's ui-out 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 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).