From patchwork Thu May 30 14:21:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 32923 Received: (qmail 38898 invoked by alias); 30 May 2019 14:21:28 -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 38790 invoked by uid 89); 30 May 2019 14:21:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mailsec108.isp.belgacom.be Received: from mailsec108.isp.belgacom.be (HELO mailsec108.isp.belgacom.be) (195.238.20.104) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 30 May 2019 14:21:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1559226085; x=1590762085; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OaTD6J4K1VGKmNpzKs3A0rv041AIIFUdwrrAPmtgUek=; b=N+QTh24JiDTTS7cKqqLgkt16Auks+7YwvcUIjJbXS1jElokLWCh0KiFi 3x1k+Djy4SEfYq8xuGxACUN6qwUF1g==; Received: from 161.32-242-81.adsl-dyn.isp.belgacom.be (HELO md.home) ([81.242.32.161]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 30 May 2019 16:21:15 +0200 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFAv4 5/5] NEWS and documentation for | (pipe) command. Date: Thu, 30 May 2019 16:21:06 +0200 Message-Id: <20190530142106.25487-6-philippe.waroquiers@skynet.be> In-Reply-To: <20190530142106.25487-1-philippe.waroquiers@skynet.be> References: <20190530142106.25487-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes gdb/ChangeLog * NEWS: Mention new pipe command and new convenience variables. gdb/doc/ChangeLog * gdb.texinfo (Shell Commands): Document pipe command. (Logging Output): Add a reference to pipe command. (Convenience Variables): Document $_shell_exitcode and $_shell_exitstatus. --- gdb/NEWS | 19 +++++++++++ gdb/doc/gdb.texinfo | 79 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index ab582c036d..2ae6896bfb 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -27,8 +27,27 @@ 'array_indexes', 'symbols', 'unions', 'deref_refs', 'actual_objects', 'static_members', 'max_elements', 'repeat_threshold', and 'format'. +* New built-in convenience variables $_shell_exitcode and $_shell_exitsignal + provide the exitcode or exit status of the shell commands launched by + GDB commands such as "shell", "pipe" and "make". + * New commands +| [COMMAND] | SHELL_COMMAND +| -d DELIM COMMAND DELIM SHELL_COMMAND +pipe [COMMAND] | SHELL_COMMAND +pipe -d DELIM COMMAND DELIM SHELL_COMMAND + Executes COMMAND and sends its output to SHELL_COMMAND. + With no COMMAND, repeat the last executed command + and send its output to SHELL_COMMAND. + +set print max-depth +show print max-depth + Allows deeply nested structures to be simplified when printing by + replacing deeply nested parts (beyond the max-depth) with ellipses. + The default max-depth is 20, but this can be set to unlimited to get + the old behavior back. + set may-call-functions [on|off] show may-call-functions This controls whether GDB will attempt to call functions in diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index f2d8710d7d..79c22d0774 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -1454,6 +1454,68 @@ Execute the @code{make} program with the specified arguments. This is equivalent to @samp{shell make @var{make-args}}. @end table +@table @code +@kindex pipe +@kindex | +@cindex send the output of a gdb command to a shell command +@anchor{pipe} +@item pipe [@var{command}] | @var{shell_command} +@itemx | [@var{command}] | @var{shell_command} +@itemx pipe -d @var{delim} @var{command} @var{delim} @var{shell_command} +@itemx | -d @var{delim} @var{command} @var{delim} @var{shell_command} +Executes @var{command} and sends its output to @var{shell_command}. +Note that no space is needed around @code{|}. +If no @var{command} is provided, the last command executed is repeated. + +In case the @var{command} contains a @code{|}, the option @code{-d @var{delim}} +can be used to specify an alternate delimiter string @var{delim} that separates +the @var{command} from the @var{shell_command}. + +Example: +@smallexample +@group +(gdb) p var +$1 = @{ + black = 144, + red = 233, + green = 377, + blue = 610, + white = 987 +@} +@end group +@group +(gdb) pipe p var|wc + 7 19 80 +(gdb) |p var|wc -l +7 +@end group +@group +(gdb) p /x var +$4 = @{ + black = 0x90, + red = 0xe9, + green = 0x179, + blue = 0x262, + white = 0x3db +@} +(gdb) ||grep red + red => 0xe9, +@end group +@group +(gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/' +this contains a PIPE char +(gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/' +this contains a PIPE char! +(gdb) +@end group +@end smallexample +@end table + +The convenience variables @code{$_shell_exitcode} and @code{$_shell_exitsignal} +can be used to examine the exit status of the last shell command launched +by @code{shell}, @code{make}, @code{pipe} and @code{|}. +@xref{Convenience Vars,, Convenience Variables}. + @node Logging Output @section Logging Output @cindex logging @value{GDBN} output @@ -1485,6 +1547,8 @@ Set @code{debugredirect} if you want debug output to go only to the log file. Show the current values of the logging settings. @end table +You can also redirect the output of a @value{GDBN} command to a +shell command. @xref{pipe}. @node Commands @chapter @value{GDBN} Commands @@ -11304,6 +11368,21 @@ the value 12 for @code{$_gdb_minor}. These variables allow you to write scripts that work with different versions of @value{GDBN} without errors caused by features unavailable in some of those versions. + +@item $_shell_exitcode +@itemx $_shell_exitsignal +@vindex $_shell_exitcode@r{, convenience variable} +@vindex $_shell_exitsignal@r{, convenience variable} +@cindex shell command, exit code +@cindex shell command, exit signal +@cindex exit status of shell commands +@value{GDBN} commands such as @code{shell} and @code{|} are launching +shell commands. When a launched command terminates, @value{GDBN} +automatically maintains the variables @code{$_shell_exitcode} +and @code{$_shell_exitsignal} according to the exit status of the last +launched command. These variables are set and used similarly to +the variables @code{$_exitcode} and @code{$_exitsignal}. + @end table @node Convenience Funs