This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v2 2/3] GDBServer: introduce --server-output command line option


This command line option will redirect all of the gdbserver's own
output (always sent to stderr) to a separate file.  This feature makes
it possible to distinguish between the inferior process stderr and
gdbserver's own stderr.  Example use case:

 $ gdbserver --server-output=log :2222 bin >bin.out 2>bin.err

Server output will be sent to file named "log", and the inferior
output and error messages will be on files "bin.out" and "bin.err",
respectively.

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

	* NEWS: New feature in the GDBserver: --server-output.

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

	* gdb.texinfo (info): Added section on command line and monitor
	commands.
	(gdbserver man): Added section on new command line option.

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

	* server.c (set_server_output): New utility function.
	(gdbserver_usage): Add help on '--server-output' option.
	(captured_main): Add command line option parsing for
	'--server-output'.
---
 gdb/NEWS               |  5 +++++
 gdb/doc/gdb.texinfo    | 17 +++++++++++++++++
 gdb/gdbserver/server.c | 28 +++++++++++++++++++++++++++-
 3 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 3fa33c9..22044c2 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -96,6 +96,11 @@ vFile:fstat:
 HP/PA running HP-UX           hppa*-*-hpux*
 Itanium running HP-UX         ia64-*-hpux*
 
+* New features in the GDBserver
+
+  ** New option --server-output=file allows users to send the
+     server output to a separate file.
+
 *** Changes in GDB 7.9
 
 * GDB now supports hardware watchpoints on x86 GNU Hurd.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index c03ecb0..454f51f 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -19204,6 +19204,20 @@ The @option{--remote-debug} option tells @code{gdbserver} to display
 remote protocol debug output.  These options are intended for
 @code{gdbserver} development and for bug reports to the developers.
 
+@cindex @option{--server-output}, @code{gdbserver} option
+The @option{--server-output=@var{file}} option tells @code{gdbserver} to send
+all its output to a file given by @var{file}.  This can be useful, for instance,
+if you need to collect the server output and/or the inferior output, but want
+to keep them separate:
+
+@smallexample
+$ gdbserver --server-output=log :2222 bin >bin.out 2>bin.err
+@end smallexample
+
+Server output will be sent to file named @var{log}, and the inferior
+output and error messages will be on files @var{bin.out} and
+@var{bin.err}, respectively.
+
 @cindex @option{--debug-format}, @code{gdbserver} option
 The @option{--debug-format=option1[,option2,...]} option tells
 @code{gdbserver} to include additional information in each output.
@@ -40892,6 +40906,9 @@ Instruct @code{gdbserver} to include extra information in each line
 of debugging output.
 @xref{Other Command-Line Arguments for gdbserver}.
 
+@item --server-output=file
+Instruct @code{gdbserver} to redirect its own output to @var{file}.
+
 @item --wrapper
 Specify a wrapper to launch programs
 for debugging.  The option should be followed by the name of the
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 73f9f6c..b4a715f 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -723,6 +723,25 @@ get_features_xml (const char *annex)
   return NULL;
 }
 
+/* Opens a file and redirects the server's own output to it  */
+
+static int
+set_server_output (char *output_filename)
+{
+  FILE *tmp;
+
+  tmp = fopen (output_filename, "w");
+  if (tmp == NULL)
+    {
+      fprintf (stderr,
+	       "Could not open server output file '%s': %s\n",
+	       output_filename, strerror(errno));
+      return -1;
+    }
+  server_output = tmp;
+  return 0;
+}
+
 void
 monitor_show_help (void)
 {
@@ -3009,6 +3028,7 @@ gdbserver_usage (FILE *stream)
 	   "                            none\n"
 	   "                            timestamp\n"
 	   "  --remote-debug        Enable remote protocol debugging output.\n"
+	   "  --server-output=FILE  Redirect server's output to FILE.\n"
 	   "  --version             Display version information and exit.\n"
 	   "  --wrapper WRAPPER --  Run WRAPPER to start new programs.\n"
 	   "  --once                Exit after the first connection has "
@@ -3178,7 +3198,13 @@ captured_main (int argc, char *argv[])
 
   while (*next_arg != NULL && **next_arg == '-')
     {
-      if (strcmp (*next_arg, "--version") == 0)
+      if (strncmp (*next_arg, "--server-output=",
+		   sizeof ("--server-output=") - 1) == 0)
+	{
+	  char *out_filename = *next_arg + (sizeof ("--server-output=") - 1);
+	  set_server_output (out_filename);
+	}
+      else if (strcmp (*next_arg, "--version") == 0)
 	{
 	  gdbserver_version ();
 	  exit (0);
-- 
1.9.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]