Re: [PATCH] Unbuffer stdout and stderr on windows

Christopher Faylor
2013-08-15T17:36:27Z

On Tue, Aug 13, 2013 at 09:08:38PM +0300, Eli Zaretskii wrote:
>> Date: Mon, 12 Aug 2013 14:11:05 -0700
>> From: Joel Brobecker <brobecker@adacore.com>
>>
>> > We had a somewhat heated debate in the cygwin list about using the
>> > techniques in winpty and eventually abandoned the idea because the way
>> > things like winpty create consoles is not foolproof. Since it relies on
>> > polling, it is theoretically possible to lose data.
>> >
>> > I'll bet that, in practice you'd never see any data loss, though.
>> > And, from that observation, you can see which side of the argument
>> > I was on. :-)
>>
>> FWIW, many frontends also implements communication with GDB using
>> pipes on Windows, and running MinGW-gdb inside cygwin window/shell
>> is just a very very common practice, regardless of whether officially
>> supported or not. How does Emacs do, for instance? IIRC when I looked
>> at the code, that's what it did.
>
>Yes, Emacs does that. But it is never a problem in that case, because
>it's the user who looks at the results, not a program that wants to
>interpret them.
>
>> Having the stdout/stderr output mixed up is very confusing and breaks
>> testing as well, so we applied the same approach as Yao's at AdaCore.
>
>Making GDB output unbuffered is not a good idea for Emacs, because it
>will cause it read single characters, which is (a) inefficient, and
>(b) error-prone, because a single CR character could dupe the text
>decoding routines into thinking the EOL format is from Mac.

I thought that "unbuffered" normally means something like "every output
operation gets immediately sent as a block" rather than "flush
after every character". If the mingw "unbuffered" mode means that
everything is o n e c h a r a c t e r a t a t i m e, then that
would obviously not be an acceptable solution. Or, maybe this is just
the way emacs itself works.

The other alternative would be to use line buffering for gdb. I don't
see why cygwin pipes (whether they are "ptys" or actual pipes) are a
special case here. stdout is usually line buffered isn't it? Why not
just force that behavior for gdb?

cgf