[RFC,08/17] Introduce and use flush_streams

Message ID 20190224165153.5062-9-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Feb. 24, 2019, 4:51 p.m. UTC
  Code in common can't call gdb_flush, so this introduces a new
"flush_streams" function that must be supplied by the client.

Note that the similar gdb_flush_out_err exists, but it isn't defined
in quite the same way, so it wasn't clear to me whether the two could
be merged.

gdb/ChangeLog
2019-02-24  Tom Tromey  <tom@tromey.com>

	* utils.c (flush_streams): New function.
	* event-loop.c (gdb_wait_for_event): Call flush_streams.
	* common/errors.h (flush_streams): Declare.
---
 gdb/ChangeLog       | 6 ++++++
 gdb/common/errors.h | 4 ++++
 gdb/event-loop.c    | 3 +--
 gdb/utils.c         | 9 +++++++++
 4 files changed, 20 insertions(+), 2 deletions(-)
  

Patch

diff --git a/gdb/common/errors.h b/gdb/common/errors.h
index 8dbc6cff5f6..d7738337082 100644
--- a/gdb/common/errors.h
+++ b/gdb/common/errors.h
@@ -87,4 +87,8 @@  extern void perror_with_name (const char *string) ATTRIBUTE_NORETURN;
 
 extern void malloc_failure (long size) ATTRIBUTE_NORETURN;
 
+/* Flush stdout and stderr.  Must be provided by the client.  */
+
+extern void flush_streams ();
+
 #endif /* COMMON_ERRORS_H */
diff --git a/gdb/event-loop.c b/gdb/event-loop.c
index caa910c9f82..b9d9e7e098e 100644
--- a/gdb/event-loop.c
+++ b/gdb/event-loop.c
@@ -727,8 +727,7 @@  gdb_wait_for_event (int block)
   int num_found = 0;
 
   /* Make sure all output is done before getting another event.  */
-  gdb_flush (gdb_stdout);
-  gdb_flush (gdb_stderr);
+  flush_streams ();
 
   if (gdb_notifier.num_fds == 0)
     return -1;
diff --git a/gdb/utils.c b/gdb/utils.c
index e7fde4942ec..a9aef0031b7 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -730,6 +730,15 @@  malloc_failure (long size)
     }
 }
 
+/* See common/errors.h.  */
+
+void
+flush_streams ()
+{
+  gdb_flush (gdb_stdout);
+  gdb_flush (gdb_stderr);
+}
+
 /* My replacement for the read system call.
    Used like `read' but keeps going if `read' returns too soon.  */