From patchwork Wed Mar 25 20:47:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cleber Rosa X-Patchwork-Id: 5815 Received: (qmail 128508 invoked by alias); 25 Mar 2015 20:48:58 -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 128448 invoked by uid 89); 25 Mar 2015 20:48:57 -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:56 +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 t2PKmtDZ016446 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 25 Mar 2015 16:48:55 -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 t2PKmB3t008768; Wed, 25 Mar 2015 16:48:50 -0400 From: Cleber Rosa 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 17:47:52 -0300 Message-Id: <1427316472-20629-4-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 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 * NEWS: New feature in the GDBserver: monitor set server-output. gdb/doc/Changelog: 2015-03-25 Cleber Rosa * gdb.texinfo (info): Add documentation about the 'monitor set server-output' command. gdb/gdbserver/Changelog: 2015-03-25 Cleber Rosa * 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 * 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'"