Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: palves@redhat.com, gdb-patches@sourceware.org,
	brobecker@adacore.com,        yao@codesourcery.com,
	Eli Zaretskii <eliz@gnu.org>
Subject: Re: [PATCH] Unbuffer stdout and stderr on windows
Date: Fri, 16 Aug 2013 11:46:00 -0000	[thread overview]
Message-ID: <520E1109.7000304@redhat.com> (raw)
In-Reply-To: <20130815175940.GD6955@ednor.casa.cgf.cx>

Sorry for chiming in so late...

On 08/15/2013 06:59 PM, Christopher Faylor wrote:
> On Thu, Aug 15, 2013 at 08:44:43PM +0300, Eli Zaretskii wrote:
>> On Thu, 15 Aug 2013 13:36:18 -0400, Christopher Faylor wrote:
>>> I thought that "unbuffered" normally means something like "every output
>>> operation gets immediately sent as a block" rather than "flush after
>>> every character".
>>
>> AFAIK, unbuffered always meant the latter.
>>
>>> 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
>>
>> It does mean that.  Doesn't it work like that in Cygwin?
> 
> Cygwin uses newlib which, AFAICT, writes a block at a time without
> storing the block in a buffer first.
> 
> So:
> 
>    fwrite (foo, 27, 1, stdout);
> 
> writes 27 bytes to stdout in one shot, without buffering.
> 
> I only got this from looking at the code so I could be wrong.
> 
>>> 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?
>>
>> That's what I suggested, but Yao says that using line buffering still
>> fails some tests.
> 
> Sorry, I missed that you'd already suggested that.

Quoting that part of previous discussion:

On 08/01/2013 09:05 AM, Yao Qi wrote:
> On 07/29/2013 11:42 PM, Eli Zaretskii wrote:

>>>> +      setvbuf (stdout, NULL, _IONBF, BUFSIZ);
>>>> +      setvbuf (stderr, NULL, _IONBF, BUFSIZ);
>> How about using line buffering instead on both streams?  Or at least
>> leave stdout line-buffered?  Did you try that, and if so, did that
>> have the same problems that triggered these patches?
>
> I tried line-buffering for stdout, but get some regressions in python
> related testing,

That's because there's no such thing as line-buffering on Windows.
See <http://msdn.microsoft.com/en-us/library/86cebhfs%28v=vs.71%29.aspx>

  _IOLBF
      For some systems, this provides line buffering. However, for Win32, the behavior
      is the same as _IOFBF - Full Buffering.


Also, ISO C (C99/TC3/N1256, 7.19.3 Files, point 7) says:

  "As initially opened, the standard error stream is not fully buffered;
  the standard input and standard output streams are fully buffered if
  and only if the stream can be determined not to refer to an interactive
  device."

Note that stderr might be either unbuffered or line buffered,
but _never_ fully buffered.  And most implementations default to leaving
stderr always unbuffered (so that error output comes out immediately).

However, the Windows runtime, in its infinite wisdom, makes stderr
fully buffered if connected to a pipe.

So all this makes me very much question the desire to detect
if a native Win32 GDB is running under Cygwin.

IMO, stderr should _always_ be forced to unbuffered.

I can't really imagine that leaving stdout fully buffered to
ever be good (which the cygwin detection seems to want to preserve),
even for frontends, given GDB is an interactive program, and even
MI is text/line based.

So I think the "in cygwin" detection is really not necessary
or desirable, and this patch should go back to its original form:

+#ifdef _WIN32
+  /* A Cygwin ssh session may not look like a terminal to the Windows
+     runtime; ensure unbuffered output.  */
+  setvbuf (stdout, NULL, _IONBF, BUFSIZ);
+  setvbuf (stderr, NULL, _IONBF, BUFSIZ);
+#endif

-- 
Pedro Alves


  parent reply	other threads:[~2013-08-16 11:46 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-22  3:07 Yao Qi
2013-07-22 15:41 ` Eli Zaretskii
2013-07-23  6:35   ` Yao Qi
2013-07-23 17:52     ` Eli Zaretskii
2013-07-29 19:26       ` Christopher Faylor
2013-07-29 19:30         ` Eli Zaretskii
2013-07-29 19:51           ` Pedro Alves
2013-07-31  3:40             ` Christopher Faylor
2013-08-12 21:11               ` Joel Brobecker
2013-08-13 17:28                 ` Christopher Faylor
2013-08-13 18:08                 ` Eli Zaretskii
2013-08-14  0:05                   ` Joel Brobecker
2013-08-15 17:36                   ` Christopher Faylor
2013-08-15 17:44                     ` Eli Zaretskii
2013-08-15 17:59                       ` Christopher Faylor
2013-08-15 18:44                         ` Eli Zaretskii
2013-08-16 11:46                         ` Pedro Alves [this message]
2013-08-16 12:34                           ` Yao Qi
2013-08-16 13:20                             ` Eli Zaretskii
2013-08-16 13:37                             ` Pedro Alves
2013-08-16 14:03                               ` Eli Zaretskii
2013-08-16 14:21                                 ` Pedro Alves
2013-08-16 14:57                                   ` Eli Zaretskii
2013-08-16 15:10                                     ` Pedro Alves
2013-08-16 15:24                                       ` Pedro Alves
2013-08-16 15:43                                         ` Eli Zaretskii
2013-08-16 16:41                                           ` Christopher Faylor
2013-08-16 15:41                                       ` Eli Zaretskii
2013-08-22  6:14                                       ` Yao Qi
2013-08-22 14:18                                         ` Joel Brobecker
2013-08-23  2:20                                           ` Yao Qi
2013-08-23 13:38                                             ` Joel Brobecker
2013-08-27 20:39                                             ` Pedro Alves
2013-08-28  7:23                                               ` Yao Qi
2013-08-28  9:39                                                 ` Pedro Alves
2013-08-28 12:25                                                   ` Yao Qi
2013-08-16 13:17                           ` Eli Zaretskii
2013-08-16 13:30                             ` Pedro Alves
2013-08-16 13:42                               ` Eli Zaretskii
2013-08-16 14:13                                 ` Pedro Alves
2013-08-16 14:44                                   ` Eli Zaretskii
2013-08-16 15:05                                     ` Pedro Alves
2013-08-16 15:13                                       ` Eli Zaretskii
2013-07-29 19:30         ` Christopher Faylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=520E1109.7000304@redhat.com \
    --to=palves@redhat.com \
    --cc=brobecker@adacore.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=yao@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox