From patchwork Wed Mar 25 20:47:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cleber Rosa X-Patchwork-Id: 5814 Received: (qmail 127884 invoked by alias); 25 Mar 2015 20:48:52 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 127830 invoked by uid 89); 25 Mar 2015 20:48:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 25 Mar 2015 20:48:49 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2PKmm4L019535 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 25 Mar 2015 16:48:48 -0400 Received: from x220.homelab.tallawa.org.com (ovpn-112-23.phx2.redhat.com [10.3.112.23]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2PKmB3s008768; Wed, 25 Mar 2015 16:48:44 -0400 From: Cleber Rosa To: gdb-patches@sourceware.org Cc: crosa@redhat.com, areis@redhat.com Subject: [PATCH v2 2/3] GDBServer: introduce --server-output command line option Date: Wed, 25 Mar 2015 17:47:51 -0300 Message-Id: <1427316472-20629-3-git-send-email-crosa@redhat.com> In-Reply-To: <1427316472-20629-1-git-send-email-crosa@redhat.com> References: <1427316472-20629-1-git-send-email-crosa@redhat.com> 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 * NEWS: New feature in the GDBserver: --server-output. gdb/doc/ChangeLog: 2015-03-25 Cleber Rosa * 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 * 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);