This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 2/3] Unbuffer stdout and stderr on windows

This is the V2.  We have some changes in V2:

 - Replace '_WIN32' with '__MINGW32__'.
 - Check flag 'cygwin_tty'.
 - Postpone setting stdout/stderr until the option is parsed.

This patch is to disable the buffering on windows host, 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

It is not the first time this patch show up here.  Daniel posted it and Joel
preferred it as the exact same piece of code is in their tree as well
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.


2013-07-25  Joseph Myers  <>

	* main.c (captured_main) [__MINGW32__]: Set stdout and stderr
	unbuffered on Windows.
 gdb/main.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/gdb/main.c b/gdb/main.c
index 029f365..4777286 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -750,6 +750,18 @@ captured_main (void *data)
       quiet = 1;
+#ifdef __MINGW32__
+  if (cygwin_tty)
+    {
+      /* A Cygwin session may not look like a terminal to the Windows
+	 runtime; ensure unbuffered output.  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);
+    }
   /* Initialize all files.  Give the interpreter a chance to take
      control of the console via the deprecated_init_ui_hook ().  */
   gdb_init (gdb_program_name);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]