aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-12-24 22:05:38 -0700
committerTom Tromey <tom@tromey.com>2022-01-05 10:19:45 -0700
commit63a8c05f09703cb30ca7e87e6bacf569ec6a472d (patch)
tree441e2c66812c03e9e1061e3af506fbbebd8fef83
parentffcc2b69d1a516f55ede0e12a8847913651ea588 (diff)
downloadgdb-63a8c05f09703cb30ca7e87e6bacf569ec6a472d.zip
gdb-63a8c05f09703cb30ca7e87e6bacf569ec6a472d.tar.gz
gdb-63a8c05f09703cb30ca7e87e6bacf569ec6a472d.tar.bz2
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.
-rw-r--r--gdb/cli/cli-script.c30
1 files changed, 7 insertions, 23 deletions
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 1d02d76..55248de 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