public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom Tromey <tromey@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Simplify execute_control_commands_to_string
Date: Wed,  5 Jan 2022 17:29:04 +0000 (GMT)	[thread overview]
Message-ID: <20220105172904.B71203858410@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=63a8c05f09703cb30ca7e87e6bacf569ec6a472d

commit 63a8c05f09703cb30ca7e87e6bacf569ec6a472d
Author: Tom Tromey <tom@tromey.com>
Date:   Fri Dec 24 22:05:38 2021 -0700

    Simplify execute_control_commands_to_string
    
    execute_control_commands_to_string can be rewritten in terms of
    execute_fn_to_string, which consolidates some knowledge about which
    streams to redirect.
    
    Regression tested on x86-64 Fedora 34.

Diff:
---
 gdb/cli/cli-script.c | 30 +++++++-----------------------
 1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 1d02d7675db..55248de649b 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -29,6 +29,7 @@
 #include "cli/cli-decode.h"
 #include "cli/cli-script.h"
 #include "cli/cli-style.h"
+#include "gdbcmd.h"
 
 #include "extension.h"
 #include "interps.h"
@@ -423,31 +424,14 @@ std::string
 execute_control_commands_to_string (struct command_line *commands,
 				    int from_tty)
 {
-  /* GDB_STDOUT should be better already restored during these
-     restoration callbacks.  */
-  set_batch_flag_and_restore_page_info save_page_info;
+  std::string result;
 
-  string_file str_file;
-
-  {
-    current_uiout->redirect (&str_file);
-    ui_out_redirect_pop redirect_popper (current_uiout);
-
-    scoped_restore save_stdout
-      = make_scoped_restore (&gdb_stdout, &str_file);
-    scoped_restore save_stderr
-      = make_scoped_restore (&gdb_stderr, &str_file);
-    scoped_restore save_stdlog
-      = make_scoped_restore (&gdb_stdlog, &str_file);
-    scoped_restore save_stdtarg
-      = make_scoped_restore (&gdb_stdtarg, &str_file);
-    scoped_restore save_stdtargerr
-      = make_scoped_restore (&gdb_stdtargerr, &str_file);
-
-    execute_control_commands (commands, from_tty);
-  }
+  execute_fn_to_string (result, [&] ()
+    {
+      execute_control_commands (commands, from_tty);
+    }, false);
 
-  return std::move (str_file.string ());
+  return result;
 }
 
 void


                 reply	other threads:[~2022-01-05 17:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220105172904.B71203858410@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=gdb-cvs@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).