[v2,3/3] GDBServer: add 'monitor set server-output' command
Commit Message
This monitor command, just like the command line option --server-output,
will redirect all of the gdbserver's own output (always sent to stderr)
to a separate file.
gdb/Changelog:
2015-03-25 Cleber Rosa <crosa@redhat.com>
* NEWS: New feature in the GDBserver: monitor set server-output.
gdb/doc/Changelog:
2015-03-25 Cleber Rosa <crosa@redhat.com>
* gdb.texinfo (info): Add documentation about the 'monitor set
server-output' command.
gdb/gdbserver/Changelog:
2015-03-25 Cleber Rosa <crosa@redhat.com>
* server.c (monitor_show_help): Add help message about the
'monitor set server-output' command.
(handle_monitor_command): Respond to 'set server-output' command.
gdb/testsuite/ChangeLog:
2015-03-25 Cleber Rosa <crosa@redhat.com>
* gdb.server/server-mon.exp: Add tests with the 'monitor set
server-output' command succeeding and failing.
---
gdb/NEWS | 2 ++
gdb/doc/gdb.texinfo | 3 +++
gdb/gdbserver/server.c | 24 +++++++++++++++++++++---
gdb/testsuite/gdb.server/server-mon.exp | 8 ++++++++
4 files changed, 34 insertions(+), 3 deletions(-)
@@ -100,6 +100,8 @@ Itanium running HP-UX ia64-*-hpux*
** New option --server-output=file allows users to send the
server output to a separate file.
+ ** New monitor command "monitor set server-output", the monitor
+ command counterpart of command line option --server-output.
*** Changes in GDB 7.9
@@ -19321,6 +19321,9 @@ Include a timestamp in each line of debugging output.
Options are processed in order. Thus, for example, if @option{none}
appears last then no additional information is added to debugging output.
+@item monitor set server-output @var{output_filename}
+Redirect the server output to a file given by @var{output_filename}.
+
@item monitor set libthread-db-search-path [PATH]
@cindex gdbserver, search path for @code{libthread_db}
When this command is issued, @var{path} is a colon-separated list of
@@ -754,9 +754,9 @@ monitor_show_help (void)
monitor_output (" Enable remote protocol debugging messages\n");
monitor_output (" set debug-format option1[,option2,...]\n");
monitor_output (" Add additional information to debugging messages\n");
- monitor_output (" Options: all, none");
- monitor_output (", timestamp");
- monitor_output ("\n");
+ monitor_output (" Options: all, none, timestamp\n");
+ monitor_output (" set server-output output_filename\n");
+ monitor_output (" Redirects the server output to output_filename\n");
monitor_output (" exit\n");
monitor_output (" Quit GDBserver\n");
}
@@ -1105,6 +1105,24 @@ handle_monitor_command (char *mon, char *own_buf)
xfree (error_msg);
}
}
+ else if (strncmp (mon, "set server-output ",
+ sizeof ("set server-output ") -1) == 0)
+ {
+ char *out_filename = mon + (sizeof ("set server-output ") - 1);
+ if (set_server_output (out_filename) == 0) {
+ char *monitor_msg = xstrprintf ("Redirected server output to '%s'\n",
+ out_filename);
+ monitor_output (monitor_msg);
+ xfree (monitor_msg);
+ }
+ else
+ {
+ char *monitor_msg = xstrprintf ("Failed to set server output to '%s'\n",
+ out_filename);
+ monitor_output (monitor_msg);
+ xfree (monitor_msg);
+ }
+ }
else if (strcmp (mon, "help") == 0)
monitor_show_help ();
else if (strcmp (mon, "exit") == 0)
@@ -54,3 +54,11 @@ gdb_test "monitor set debug-format all" \
"All extra debug format options enabled\\."
gdb_test "monitor set debug-format none" \
"All extra debug format options disabled\\."
+
+# Tests the monitor command that sends stderr output to another file
+gdb_test "monitor set server-output /dev/null" \
+ "Redirected server output to '/dev/null'"
+
+# Tests the monitor command that sends stderr output to another file
+gdb_test "monitor set server-output /im/pro/ba/ble/pa/th" \
+ "Failed to set server output to '/im/pro/ba/ble/pa/th'"