This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 2/3] Unbuffer stdout and stderr in cygwin
- From: Yao Qi <yao at codesourcery dot com>
- To: <gdb-patches at sourceware dot org>
- Date: Tue, 13 Aug 2013 17:34:27 +0800
- Subject: [PATCH 2/3] Unbuffer stdout and stderr in cygwin
- References: <1376386468-26249-1-git-send-email-yao at codesourcery dot com>
Hi,
This patch is to set the buffering of stdout and stderr properly on
mingw32 host when it is running in cygwin pty, because the error
message and gdb prompt come out in different orders, which causes a
lot of test fails.
We call setvbuf this place, because it is a place "before any other
operation is performed". See the doc below:
"The setvbuf() function may be used after the stream pointed to by
stream is associated with an open file but before any other operation
(other than an unsuccessful call to setvbuf()) is performed on the
stream."
It is not the first time this patch show up here. Daniel posted it
http://sourceware.org/ml/gdb-patches/2009-06/msg00433.html and Joel
preferred it as the exact same piece of code is in their tree as well
http://sourceware.org/ml/gdb-patches/2009-06/msg00434.html
Eli wanted to check this patch didn't interfere with Emacs 23 GDB
interface on Windows, which is probably the last question to this
patch. The discussion stopped there. I build native mingw32 gdb
with buffering disabled, and use it with Emacs 24.3 in Windows
cmd.exe. Emacs+GDB behave correctly.
gdb:
2013-08-13 Joseph Myers <joseph@codesourcery.com>
Yao Qi <yao@codesourcery.com>
* main.c (captured_main) [__MINGW32__]: Set stdout
and stderr unbuffered if GDB is using Cygwin pty.
---
gdb/main.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/gdb/main.c b/gdb/main.c
index 1c240e4..0174992 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -375,6 +375,18 @@ captured_main (void *data)
saved_command_line[0] = '\0';
instream = stdin;
+#ifdef __MINGW32__
+ if (using_cygwin_pty ())
+ {
+ /* A Cygwin session may not look like a terminal to the Windows
+ runtime; ensure stdout and stderr is unbuffered. Note that
+ setvbuf may be used after the file is opened but before any
+ other operation is performed. */
+ setvbuf (stdout, NULL, _IONBF, BUFSIZ);
+ setvbuf (stderr, NULL, _IONBF, BUFSIZ);
+ }
+#endif
+
gdb_stdout = stdio_fileopen (stdout);
gdb_stderr = stdio_fileopen (stderr);
gdb_stdlog = gdb_stderr; /* for moment */
--
1.7.7.6