[4/4] GDBServer: add 'monitor set server-stderr' command
Commit Message
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(-)
Comments
> From: Cleber Rosa <crosa@redhat.com>
> Cc: crosa@redhat.com, areis@redhat.com
> Date: Fri, 20 Mar 2015 23:34:25 -0300
>
> gdb/doc/Changelog:
> 2015-03-20 Cleber Rosa <crosa@redhat.com>
>
> * gdb.texinfo (info): Add documentation about the 'monitor set
> server-stderr' command
Don't forget the period at the end of the sentence.
> +@item monitor set server-stderr [PATH]
You want "[@var{path}]" instead. And please don't call this "path",
for the reasons I explained in my other message.
> +Redirect the server stderr to a file given by @var{path}.
Same comments as in my other message: instead of referencing "stderr",
reference the server's output.
Thanks.
On 03/21/2015 05:29 AM, Eli Zaretskii wrote:
>> From: Cleber Rosa <crosa@redhat.com>
>> Cc: crosa@redhat.com, areis@redhat.com
>> Date: Fri, 20 Mar 2015 23:34:25 -0300
>>
>> gdb/doc/Changelog:
>> 2015-03-20 Cleber Rosa <crosa@redhat.com>
>>
>> * gdb.texinfo (info): Add documentation about the 'monitor set
>> server-stderr' command
> Don't forget the period at the end of the sentence.
>
>> +@item monitor set server-stderr [PATH]
> You want "[@var{path}]" instead. And please don't call this "path",
> for the reasons I explained in my other message.
Sure! BTW, I mistakenly added [PATH] as an optional parameter, and it
should be mandatory. Because of that, this is the new version:
@item monitor set server-output @var{output_filename}
Redirect the server output to a file given by @var{output_filename}.
Also, FIY, the server behavior when the "output_filename" parameter is
not passed in, is currently the same as when a parameter is missing from
another commands such as "monitor set remote-debug":
(gdb) monitor set server-output
Unknown monitor command.
...
Protocol error with Rcmd
(gdb) monitor set remote-debug
Unknown monitor command.
...
Protocol error with Rcmd
It looks like this is an area that can receive some improvement, but
it's obviously outside the scope of the changes proposed/worked here.
>
>> +Redirect the server stderr to a file given by @var{path}.
> Same comments as in my other message: instead of referencing "stderr",
> reference the server's output.
>
> Thanks.
Sure! I should really have learned that lesson by now!
Thanks a million!
@@ -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
@@ -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)
@@ -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'"