[PATCH 4/4] GDBServer: add 'monitor set server-stderr' command

Cleber Rosa
2015-03-21T02:35:27Z

This monitor command, just like the command line option --server-stderr,
will redirect all of the gdbserver's own output (always sent to stderr)
to a separate file.

gdb/doc/Changelog:
2015-03-20 Cleber Rosa <crosa@redhat.com>

* gdb.texinfo (info): Add documentation about the 'monitor set
server-stderr' command

gdb/gdbserver/Changelog:
2015-03-20 Cleber Rosa <crosa@redhat.com>

* server.c (monitor_show_help): Add help message about the
'monitor set server-stderr' command
(handle_monitor_command): Respond to 'set server-stderr' command

gdb/testsuite/ChangeLog:
2015-03-20 Cleber Rosa <crosa@redhat.com>

* gdb.server/server-mon.exp: Add tests with the 'monitor set
server-stderr' command succeeding and failing
---
gdb/doc/gdb.texinfo | 3 +++
gdb/gdbserver/server.c | 22 +++++++++++++++++++---
gdb/testsuite/gdb.server/server-mon.exp | 8 ++++++++
3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 2834794..3a6bbde 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -19314,6 +19314,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-stderr [PATH]
+Redirect the server stderr to a file given by @var{path}.
+
@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
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index db26f24..afa7aed 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -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-stderr <path>\n");
+ monitor_output (" Redirects the server stderr content to another file\n");
monitor_output (" exit\n");
monitor_output (" Quit GDBserver\n");
}
@@ -1105,6 +1105,22 @@ handle_monitor_command (char *mon, char *own_buf)
xfree (error_msg);
}
}
+ else if (strncmp (mon, "set server-stderr ",
+ sizeof ("set server-stderr ") -1) == 0)
+ {
+ char *path = mon + (sizeof ("set server-stderr ") - 1);
+ if (set_server_stderr (path) == 0) {
+ char *monitor_msg = xstrprintf ("Redirected server stderr to '%s'\n", path);
+ monitor_output (monitor_msg);
+ xfree (monitor_msg);
+ }
+ else
+ {
+ char *monitor_msg = xstrprintf ("Failed to set server stderr to '%s'\n", path);
+ monitor_output (monitor_msg);
+ xfree (monitor_msg);
+ }
+ }
else if (strcmp (mon, "help") == 0)
monitor_show_help ();
else if (strcmp (mon, "exit") == 0)
diff --git a/gdb/testsuite/gdb.server/server-mon.exp b/gdb/testsuite/gdb.server/server-mon.exp
index a4c03ee..34cd1ce 100644
--- a/gdb/testsuite/gdb.server/server-mon.exp
+++ b/gdb/testsuite/gdb.server/server-mon.exp
@@ -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-stderr /dev/null" \
+ "Redirected server stderr to '/dev/null'"
+
+# Tests the monitor command that sends stderr output to another file
+gdb_test "monitor set server-stderr /im/pro/ba/ble/pa/th" \
+ "Failed to set server stderr to '/im/pro/ba/ble/pa/th'"
--
1.9.3