+/* See cli-script.h. */
+
+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;
+
+ 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);
+ }
+
+ return std::move (str_file.string ());
+}
+
+void
+execute_user_command (struct cmd_list_element *c, const char *args)
+{
+ counted_command_line cmdlines_copy;
+
+ /* Ensure that the user commands can't be deleted while they are
+ executing. */
+ cmdlines_copy = c->user_commands;
+ if (cmdlines_copy == 0)
+ /* Null command */
+ return;
+ struct command_line *cmdlines = cmdlines_copy.get ();
+
+ scoped_user_args_level push_user_args (args);
+
+ if (user_args_stack.size () > max_user_call_depth)
+ error (_("Max user call depth exceeded -- command aborted."));
+
+ execute_control_commands (cmdlines, 0);
+}
+