Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Cleber Rosa <crosa@redhat.com>
To: gdb-patches@sourceware.org
Cc: crosa@redhat.com, areis@redhat.com
Subject: [PATCH v2 3/3] GDBServer: add 'monitor set server-output' command
Date: Wed, 25 Mar 2015 20:48:00 -0000	[thread overview]
Message-ID: <1427316472-20629-4-git-send-email-crosa@redhat.com> (raw)
In-Reply-To: <1427316472-20629-1-git-send-email-crosa@redhat.com>

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(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 22044c2..d8e74bb 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -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
 
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 454f51f..b3442b1 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -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
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index b4a715f..51251f9 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-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)
diff --git a/gdb/testsuite/gdb.server/server-mon.exp b/gdb/testsuite/gdb.server/server-mon.exp
index a4c03ee..a19bc11 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-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'"
-- 
1.9.3


  reply	other threads:[~2015-03-25 20:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-25 20:48 [PATCH v2 0/3] GDBServer: introduce a dedicated output stream Cleber Rosa
2015-03-25 20:48 ` Cleber Rosa [this message]
2015-03-25 20:48 ` [PATCH v2 2/3] GDBServer: introduce --server-output command line option Cleber Rosa
2015-03-25 20:55   ` Eli Zaretskii
2015-03-25 21:08     ` Cleber Rosa
2015-03-25 20:48 ` [PATCH v2 1/3] GDBServer: introduce a stream dedicated to the server Cleber Rosa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1427316472-20629-4-git-send-email-crosa@redhat.com \
    --to=crosa@redhat.com \
    --cc=areis@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox