From patchwork Sat Mar 21 02:34:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cleber Rosa X-Patchwork-Id: 5746 Received: (qmail 47184 invoked by alias); 21 Mar 2015 02:35:22 -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 47102 invoked by uid 89); 21 Mar 2015 02:35:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 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; Sat, 21 Mar 2015 02:35:19 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2L2ZIHN009217 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 20 Mar 2015 22:35:18 -0400 Received: from x220.homelab.tallawa.org.com ([10.3.112.4]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2L2YppO029072; Fri, 20 Mar 2015 22:35:14 -0400 From: Cleber Rosa To: gdb-patches@sourceware.org Cc: crosa@redhat.com, areis@redhat.com Subject: [PATCH 3/4] GDBServer: introduce --server-stderr command line option Date: Fri, 20 Mar 2015 23:34:24 -0300 Message-Id: <1426905265-8495-4-git-send-email-crosa@redhat.com> In-Reply-To: <1426905265-8495-1-git-send-email-crosa@redhat.com> References: <1426905265-8495-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. gdb/doc/ChangeLog: 2015-03-20 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-20 Cleber Rosa * server.c (set_server_stderr): New utility function. (gdbserver_usage): Add help on '--server-stderr' option. (captured_main): Add command line option parsing for '--server-stderr'. Replace stderr with gdbserver's own stderr. --- gdb/doc/gdb.texinfo | 10 ++++++++++ gdb/gdbserver/server.c | 28 +++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 552da31..2834794 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -19205,6 +19205,12 @@ 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-stderr}, @code{gdbserver} option +The @option{--server-stderr} option tells @code{gdbserver} that any content +that it would normally generate itself to its own @code{stderr} should be +redirected to another file. This is useful if you want to keep the +inferior @code{stderr} separate from the one generated by @code{gdbserver}. + @cindex @option{--debug-format}, @code{gdbserver} option The @option{--debug-format=option1[,option2,...]} option tells @code{gdbserver} to include additional information in each output. @@ -40886,6 +40892,10 @@ Instruct @code{gdbserver} to include extra information in each line of debugging output. @xref{Other Command-Line Arguments for gdbserver}. +@item --server-stderr +Instruct @code{gdbserver} to redirect its own @code{stderr} to another +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 9dec972..db26f24 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 own stderr to it */ + +static int +set_server_stderr (char *path) +{ + FILE *tmp; + + tmp = fopen (path, "w"); + if (tmp == NULL) + { + fprintf (stderr, + "Could not open server stderr file '%s': %s\n", + path, strerror(errno)); + return -1; + } + server_stderr = tmp; + return 0; +} + void monitor_show_help (void) { @@ -3017,6 +3036,7 @@ gdbserver_usage (FILE *stream) " none\n" " timestamp\n" " --remote-debug Enable remote protocol debugging output.\n" + " --server-stderr=PATH Redirect server's STDERR to file at PATH.\n" " --version Display version information and exit.\n" " --wrapper WRAPPER -- Run WRAPPER to start new programs.\n" " --once Exit after the first connection has " @@ -3186,7 +3206,13 @@ captured_main (int argc, char *argv[]) while (*next_arg != NULL && **next_arg == '-') { - if (strcmp (*next_arg, "--version") == 0) + if (strncmp (*next_arg, "--server-stderr=", + sizeof ("--server-stderr=") - 1) == 0) + { + char *path = *next_arg + (sizeof ("--server-stderr=") - 1); + set_server_stderr (path); + } + else if (strcmp (*next_arg, "--version") == 0) { gdbserver_version (); exit (0);