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]

Re: [PATCH][TEST-CASE][DOC] Implementation of pipe to pass GDB's command output to the shell.


On Sun, Aug 28, 2011 at 3:41 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>> Date: Sun, 28 Aug 2011 05:50:49 -0400
>> From: Eli Zaretskii <eliz@gnu.org>
>> CC: gdb-patches@sourceware.org, sergiodj@redhat.com, ?jan.kratochvil@redhat.com, tromey@redhat.com, ? pedro@codesourcery.com
>> Reply-to: Eli Zaretskii <eliz@gnu.org>
>>
>> > Date: Sun, 28 Aug 2011 14:21:43 +0530
>> > From: Abhijit Halder <abhijit.k.halder@gmail.com>
>> > Cc: gdb-patches@sourceware.org, sergiodj@redhat.com, jan.kratochvil@redhat.com,
>> > ? ? tromey@redhat.com, pedro@codesourcery.com
>> >
>> > >> +@node Output Redirection
>> > >> +@chapter Redirecting @value{GDBN}'s Command Output to the Shell
>> > >
>> > > I'd rather not make this a new chapter. ?I think a subsection of the
>> > > Input/Output node is a much better place.
>> > >
>> > Actually I could not find such section. Can someone please direct me
>> > to the appropriate section?
>>
>> Search for this:
>>
>> ? @node Input/Output
>> ? @section Your Program's Input and Output
>
> An even better place is this:
>
> ?@node Shell Commands
> ?@section Shell Commands
>
> Sorry that I didn't think about this before.
>

Hi,
I have made the corrections in the doc section. Please review the same.

Thanks,
Abhijit Halder
diff -rup src/gdb/doc/ChangeLog dst/gdb/doc/ChangeLog
--- src/gdb/doc/ChangeLog	2011-08-27 20:35:38.459934029 +0530
+++ dst/gdb/doc/ChangeLog	2011-08-28 16:24:53.024714073 +0530
@@ -1,3 +1,7 @@
+2011-08-29  Abhijit Halder  <abhijit.k.halder@gmail.com>
+
+	* gdb.texinfo (pipe command): New node.
+
 2011-08-25  Andrew Oakley  <andrew@ado.is-a-geek.net>
 
 	* gdb.texinfo (Types In Python): Document 'bitpos' for enums.
diff -rup src/gdb/doc/gdb.texinfo dst/gdb/doc/gdb.texinfo
--- src/gdb/doc/gdb.texinfo	2011-08-26 21:11:39.938354007 +0530
+++ dst/gdb/doc/gdb.texinfo	2011-08-30 18:39:03.200191037 +0530
@@ -1367,6 +1367,53 @@ Execute the @code{make} program with the
 arguments.  This is equivalent to @samp{shell make @var{make-args}}.
 @end table
 
+If you want to process the output of a @value{GDBN} command using some shell
+command or some script, that can be done by using the command @code{pipe}.  You
+don't even need to get a shell for that.  The same could be achieved by
+enabling logging and redirecting the output of @value{GDBN} command to some
+file and then processing the file content by invoking a shell using
+@code{shell} command.  But this incurs higher costs as the explicit invokation
+of shell involves execution of its startup scripts and locating the file
+containing @value{GDBN}'s command output involves directory lookup; even though
+OS may optimize these processes by its cache mechanism.
+
+@table @code
+@item pipe @var{args}
+The @var{args} consists of a delimiter followed by a @value{GDBN} command,
+followed by the same delimiter and finally a shell command.  The delimiter is a
+string of arbitrary length, containing no whitespace and no leading '-', acts
+as a separator between a @value{GDBN} command and a shell command.  The shell
+command should be in compliance with the syntax of the default shell.
+@end table
+
+@smallexample
+(@value{GDBP}) @b{ptype dd_tbl}
+type = struct dd @{
+    int dd_handle;
+    const char *dd_name;
+    int dd_major;
+    int dd_minor;
+    void *dd_code;
+    void *dd_data;
+@} [1024]
+(@value{GDBP}) @b{pipe <br> print dd_tbl <br> sed 's/@}/\n/g' | grep @
+"\.test_dd" | tr ',' '\n'}
+
+  @{dd_handle = 10
+  dd_name = 0x8048538 ".test_dd"
+  dd_major = 100
+  dd_minor = 0
+  dd_code = 0xcc
+  dd_data = 0x80
+@end smallexample
+
+In the above example @samp{@var{<br>}} acts as a delimiter.  The output of
+@samp{print dd_tbl} is passed to the shell command @samp{sed 's/@}/\n/g' | @
+grep ".test_dd" | tr ',' '\n'} for processing.
+
+In the given example the output of @value{GDBN} command is huge and not well
+formated.  The use of shell commands like ``sed'', ``tr'' and ``grep'' ease
+the searching of desired pattern and hence ease debugging.
+
 @node Logging Output
 @section Logging Output
 @cindex logging @value{GDBN} output

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