From: Yao Qi <yao@codesourcery.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: Pedro Alves <palves@redhat.com>, Eli Zaretskii <eliz@gnu.org>,
<gdb-patches@sourceware.org>
Subject: Re: [PATCH] Unbuffer stdout and stderr on windows
Date: Fri, 23 Aug 2013 02:20:00 -0000 [thread overview]
Message-ID: <5216C6B0.90906@codesourcery.com> (raw)
In-Reply-To: <20130822141756.GB5221@adacore.com>
Thanks for the review, Joel.
On 08/22/2013 10:17 PM, Joel Brobecker wrote:
>> +#ifdef __MINGW32__
>> >+ /* Ensure stderr is unbuffered. */
>> >+ setvbuf (stderr, NULL, _IONBF, BUFSIZ);
>> >+#endif
> Can you also document the reason why you make stderr unbuffered here?
> If we capture most of what was discussed, it'll help anyone trying
> to understand the code later on...
>
Sure, comment is added.
>> > gdb_stdout = stdio_fileopen (stdout);
>> > gdb_stderr = stdio_fileopen (stderr);
>> >+#ifdef __MINGW32__
>> >+ /* There is no real line-buffering on Windows, see
>> >+http://msdn.microsoft.com/en-us/library/86cebhfs%28v=vs.71%29.aspx
>> >+ so the stdout is either fully-buffered or non-buffered. We can't
>> >+ make stdout non-buffered, because of two concerns,
>> >+ 1. non-buffering hurts performance,
>> >+ 2. non-buffering may change GDB's behavior when it is interacting
>> >+ with front-end, such as Emacs.
>> >+
>> >+ We decide to leave stdout as fully buffered, but flush it first
> decided
Fixed.
>> >+ when something is written to stderr. */
>> >+ update_stderr_ui_file (gdb_stderr);
>> >+#endif
> Just a question: Would it be possible to emulate line buffering
> as well? In my experience, the size of the buffer is fairly big,
> and causes the output to appear only at fairly large intervals,
> and in fairly large blobs.
>
I am not sure. The goal of this patch is to keep the order of outputs
from stdout and stderr correct, so I don't think much on emulating
line buffering for stdout. IMO, it can be addressed by a separated
patch.
>
>> >+
>> > gdb_stdlog = gdb_stderr; /* for moment */
>> > gdb_stdtarg = gdb_stderr; /* for moment */
>> > gdb_stdin = stdio_fileopen (stdin);
>> >diff --git a/gdb/ui-file.c b/gdb/ui-file.c
>> >index cf5a86d..649d892 100644
>> >--- a/gdb/ui-file.c
>> >+++ b/gdb/ui-file.c
>> >@@ -654,6 +654,32 @@ stdio_file_fseek (struct ui_file *file, long offset, int whence)
>> > return fseek (stdio->file, offset, whence);
>> > }
>> >
>> >+static void
>> >+stderr_file_write (struct ui_file *file, const char *buf, long length_buf)
> Please, document every new function, no matter how trivial. That way,
> there is no discussion about whether the function should be documented
> or not.
OK, documented in the updated patch.
--
Yao (é½å°§)
gdb:
2013-08-23 Yao Qi <yao@codesourcery.com>
* main.c (captured_main) [__MINGW32__]: Set stderr unbuffered.
and all update_stderr_ui_file.
* ui-file.c (stderr_file_write): New function.
(stderr_file_fputs): New function.
(update_stderr_ui_file): New function.
* ui-file.h (update_stderr_ui_file): Declare.
---
gdb/main.c | 20 ++++++++++++++++++++
gdb/ui-file.c | 32 ++++++++++++++++++++++++++++++++
gdb/ui-file.h | 3 +++
3 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/gdb/main.c b/gdb/main.c
index 1c240e4..332df9e 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -375,8 +375,28 @@ captured_main (void *data)
saved_command_line[0] = '\0';
instream = stdin;
+#ifdef __MINGW32__
+ /* Ensure stderr is unbuffered. A Cygwin pty or pipe is implemented
+ as a Windows pipe, and Windows buffers on pipes. */
+ setvbuf (stderr, NULL, _IONBF, BUFSIZ);
+#endif
+
gdb_stdout = stdio_fileopen (stdout);
gdb_stderr = stdio_fileopen (stderr);
+#ifdef __MINGW32__
+ /* There is no real line-buffering on Windows, see
+ http://msdn.microsoft.com/en-us/library/86cebhfs%28v=vs.71%29.aspx
+ so the stdout is either fully-buffered or non-buffered. We can't
+ make stdout non-buffered, because of two concerns,
+ 1. non-buffering hurts performance,
+ 2. non-buffering may change GDB's behavior when it is interacting
+ with front-end, such as Emacs.
+
+ We decided to leave stdout as fully buffered, but flush it first
+ when something is written to stderr. */
+ update_stderr_ui_file (gdb_stderr);
+#endif
+
gdb_stdlog = gdb_stderr; /* for moment */
gdb_stdtarg = gdb_stderr; /* for moment */
gdb_stdin = stdio_fileopen (stdin);
diff --git a/gdb/ui-file.c b/gdb/ui-file.c
index cf5a86d..4b26b78 100644
--- a/gdb/ui-file.c
+++ b/gdb/ui-file.c
@@ -654,6 +654,38 @@ stdio_file_fseek (struct ui_file *file, long offset, int whence)
return fseek (stdio->file, offset, whence);
}
+/* This is the implementation of ui_file method to_write for stderr.
+ gdb_stdout is flushed before writing to gdb_stderr. */
+
+static void
+stderr_file_write (struct ui_file *file, const char *buf, long length_buf)
+{
+ gdb_flush (gdb_stdout);
+ stdio_file_write (file, buf, length_buf);
+}
+
+/* This is the implementation of ui_file method to_fputs for stderr.
+ gdb_stdout is flushed before writing to gdb_stderr. */
+
+static void
+stderr_file_fputs (const char *linebuffer, struct ui_file *file)
+{
+ gdb_flush (gdb_stdout);
+ stdio_file_fputs (linebuffer, file);
+}
+
+/* Overwrite UI_FILE's methods 'to_write' and 'to_fputs' by function
+ in which gdb_stdout is flushed. */
+
+void
+update_stderr_ui_file (struct ui_file *ui_file)
+{
+ /* Method 'to_write_async_safe' is not overwritten, because it is
+ only used on linux host. */
+ set_ui_file_write (ui_file, stderr_file_write);
+ set_ui_file_fputs (ui_file, stderr_file_fputs);
+}
+
/* Like fdopen(). Create a ui_file from a previously opened FILE. */
struct ui_file *
diff --git a/gdb/ui-file.h b/gdb/ui-file.h
index 9fef68c..6d96c0b 100644
--- a/gdb/ui-file.h
+++ b/gdb/ui-file.h
@@ -129,6 +129,9 @@ extern struct ui_file *mem_fileopen (void);
/* Open/create a STDIO based UI_FILE using the already open FILE. */
extern struct ui_file *stdio_fileopen (FILE *file);
+extern void update_stderr_ui_file (struct ui_file *ui_file);
+
+
/* Open NAME returning an STDIO based UI_FILE. */
extern struct ui_file *gdb_fopen (const char *name, const char *mode);
--
1.7.7.6
next prev parent reply other threads:[~2013-08-23 2:20 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
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 [this message]
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=5216C6B0.90906@codesourcery.com \
--to=yao@codesourcery.com \
--cc=brobecker@adacore.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.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