This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] An implementation of pipe to make I/O communication between gdb and shell.
On Sat, Aug 13, 2011 at 10:53 PM, Jan Kratochvil
<jan.kratochvil@redhat.com> wrote:
> On Fri, 05 Aug 2011 11:41:09 +0200, Abhijit Halder wrote:
>> On Fri, Aug 5, 2011 at 1:59 PM, Jan Kratochvil <jan.kratochvil@redhat.com> wrote:
>> > I would prefer to also redirect gdb_stderr, gdb_stdlog, gdb_stdtarg and
>> > gdb_stdtargerr like set_logging_redirect does. ?This is like if one
>> > uses |& instead of | . ?I understand someone may have a different opinion.
>> > In such case there even may be some option of the command pipe for it.
>> I understand your point here, but this will break out very basic
>> assumption that delimiter is single character.
>> Can we skip this at this point? Or simply we can redirect gdb_stderror
>> to pipe as in most of the cases that will be equivalent to gdb_stdout.
>> (My understanding was that the error from gdb can be captured anyway
>> by error logging mechanism, the use-case of using pipe, I believe, is
>> when the gdb output is huge and one wants to process that huge
>> output.) Please suggest.
>
> The reason for redirecting also errors I find that when you type:
>
> $ ls /tmp bar|less
>
> you happilly see the content of /tmp but the message
>
> ls: cannot access bar: No such file or directory
>
> gets completely lost. ?This is why I find |& safer for normal use cases.
>
> (One can argue also the other way, that standard shell pipe | also does not
> automatically redirect stderr, though.)
>
I have also redirected the gdb_stderr to pipe.
+ fp = stdio_fileopen (pipe->handle);
+ make_cleanup_ui_file_delete (fp);
+ make_cleanup_restore_ui_file (&gdb_stdout);
+ make_cleanup_restore_ui_file (&gdb_stderr);
+ make_cleanup_restore_ui_file (&gdb_stdlog);
+ make_cleanup_restore_ui_file (&gdb_stdtarg);
+ make_cleanup_restore_ui_file (&gdb_stdtargerr);
+
+ if (ui_out_redirect (uiout, fp) < 0)
+ warning (_("Current output protocol does not support redirection"));
+ else
+ make_cleanup_ui_out_redirect_pop (uiout);
+
+ gdb_stdout = fp;
+ gdb_stderr = fp;
+ gdb_stdlog = fp;
+ gdb_stdtarg = fp;
+ gdb_stdtargerr = fp;
+ execute_command (pipe->gdb_cmd, from_tty);
But the error is still coming on screen.
(gdb) pipe | print xxx | vim -
Vim: Reading from stdin...
No symbol table is loaded. Use the "file" command.
(gdb) pipe | print 2 | vim -
Vim: Reading from stdin...
(gdb)
>
> Thanks,
> Jan
>