This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFAv2 3/6] Add function execute_command_to_ui_file
- From: Philippe Waroquiers <philippe dot waroquiers at skynet dot be>
- To: gdb-patches at sourceware dot org
- Cc: Philippe Waroquiers <philippe dot waroquiers at skynet dot be>
- Date: Fri, 26 Apr 2019 22:11:05 +0200
- Subject: [RFAv2 3/6] Add function execute_command_to_ui_file
- References: <20190426201108.7489-1-philippe.waroquiers@skynet.be>
2019-04-26 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* gdbcmd.h (execute_command_to_ui_file): New declaration.
top.c (execute_command_to_ui_file): New function, mostly a copy
of execute_command_to_string.
(execute_command_to_string): Implement by calling
execute_command_to_ui_file.
---
gdb/gdbcmd.h | 2 ++
gdb/top.c | 33 +++++++++++++++++++++------------
2 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/gdb/gdbcmd.h b/gdb/gdbcmd.h
index 4614ec748c..14c0b80bac 100644
--- a/gdb/gdbcmd.h
+++ b/gdb/gdbcmd.h
@@ -134,6 +134,8 @@ extern struct cmd_list_element *save_cmdlist;
extern void execute_command (const char *, int);
extern std::string execute_command_to_string (const char *p, int from_tty);
+extern void execute_command_to_ui_file (struct ui_file *file,
+ const char *p, int from_tty);
extern void print_command_line (struct command_line *, unsigned int,
struct ui_file *);
diff --git a/gdb/top.c b/gdb/top.c
index 93fed2ed80..bd68ba182b 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -665,12 +665,12 @@ execute_command (const char *p, int from_tty)
cleanup_if_error.release ();
}
-/* Run execute_command for P and FROM_TTY. Capture its output into the
- returned string, do not display it to the screen. BATCH_FLAG will be
+/* Run execute_command for P and FROM_TTY. Sends its output to FILE,
+ do not display it to the screen. BATCH_FLAG will be
temporarily set to true. */
-std::string
-execute_command_to_string (const char *p, int from_tty)
+void
+execute_command_to_ui_file (struct ui_file *file, const char *p, int from_tty)
{
/* GDB_STDOUT should be better already restored during these
restoration callbacks. */
@@ -678,26 +678,35 @@ execute_command_to_string (const char *p, int from_tty)
scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0);
- string_file str_file;
-
{
- current_uiout->redirect (&str_file);
+ current_uiout->redirect (file);
ui_out_redirect_pop redirect_popper (current_uiout);
scoped_restore save_stdout
- = make_scoped_restore (&gdb_stdout, &str_file);
+ = make_scoped_restore (&gdb_stdout, file);
scoped_restore save_stderr
- = make_scoped_restore (&gdb_stderr, &str_file);
+ = make_scoped_restore (&gdb_stderr, file);
scoped_restore save_stdlog
- = make_scoped_restore (&gdb_stdlog, &str_file);
+ = make_scoped_restore (&gdb_stdlog, file);
scoped_restore save_stdtarg
- = make_scoped_restore (&gdb_stdtarg, &str_file);
+ = make_scoped_restore (&gdb_stdtarg, file);
scoped_restore save_stdtargerr
- = make_scoped_restore (&gdb_stdtargerr, &str_file);
+ = make_scoped_restore (&gdb_stdtargerr, file);
execute_command (p, from_tty);
}
+}
+
+/* Run execute_command for P and FROM_TTY. Capture its output into the
+ returned string, do not display it to the screen. BATCH_FLAG will be
+ temporarily set to true. */
+
+std::string
+execute_command_to_string (const char *p, int from_tty)
+{
+ string_file str_file;
+ execute_command_to_ui_file (&str_file, p, from_tty);
return std::move (str_file.string ());
}
--
2.20.1