From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id D5F793858D39; Wed, 31 Aug 2022 17:15:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D5F793858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1661966100; bh=Ttq/Thkc/xnyAwZ0Er2HqoSoqQubB0069Hdebfym8gw=; h=From:To:Subject:Date:From; b=rch+dZM1/Gf0cLSssudDc47ivcrmrPAPeYg9XgD+zBXmckyINC79ktlFLgzyxz4nU L/fZRtyc4ZnZEwDzHlmL5lyiMXSnIh4+0lyVsofC5fYpr4dfaV/lA0IFDx1Y5UjY0O C6nAJ3ePLOEXtYm/raNem46yJb07yWOzNuLAw1r0= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] TUI stdout buffering cleanup X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: b8043d27217ff89abba733476cb71c3656f5722a X-Git-Newrev: 90621f6922ec7da513a2af46234bb5ae11a663ae Message-Id: <20220831171500.D5F793858D39@sourceware.org> Date: Wed, 31 Aug 2022 17:15:00 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D90621f6922ec= 7da513a2af46234bb5ae11a663ae commit 90621f6922ec7da513a2af46234bb5ae11a663ae Author: Tom Tromey Date: Thu Aug 11 14:03:55 2022 -0600 TUI stdout buffering cleanup =20 The TUI checks against gdb_stdout to decide when to buffer. It seems much cleaner to me to simply record this as an attribute of the stream itself. Diff: --- gdb/tui/tui-file.c | 23 +++-------------------- gdb/tui/tui-file.h | 10 +++++++++- gdb/tui/tui-io.c | 4 ++-- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/gdb/tui/tui-file.c b/gdb/tui/tui-file.c index 49dafce112c..3cf3dbc171a 100644 --- a/gdb/tui/tui-file.c +++ b/gdb/tui/tui-file.c @@ -22,24 +22,11 @@ #include "tui/tui-command.h" #include "tui.h" =20 -tui_file::tui_file (FILE *stream) - : stdio_file (stream) -{} - -/* All TUI I/O sent to the *_filtered and *_unfiltered functions - eventually ends up here. The fputs_unfiltered_hook is primarily - used by GUIs to collect all output and send it to the GUI, instead - of the controlling terminal. Only output to gdb_stdout and - gdb_stderr are sent to the hook. Everything else is sent on to - fputs to allow file I/O to be handled appropriately. */ - void tui_file::puts (const char *linebuffer) { tui_puts (linebuffer); - /* gdb_stdout is buffered, and the caller must gdb_flush it at - appropriate times. Other streams are not so buffered. */ - if (this !=3D gdb_stdout) + if (!m_buffered) tui_refresh_cmd_win (); } =20 @@ -47,18 +34,14 @@ void tui_file::write (const char *buf, long length_buf) { tui_write (buf, length_buf); - /* gdb_stdout is buffered, and the caller must gdb_flush it at - appropriate times. Other streams are not so buffered. */ - if (this !=3D gdb_stdout) + if (!m_buffered) tui_refresh_cmd_win (); } =20 void tui_file::flush () { - /* gdb_stdout is buffered. Other files are always flushed on - every write. */ - if (this =3D=3D gdb_stdout) + if (m_buffered) tui_refresh_cmd_win (); stdio_file::flush (); } diff --git a/gdb/tui/tui-file.h b/gdb/tui/tui-file.h index 1b28780c51b..ff60ded71c1 100644 --- a/gdb/tui/tui-file.h +++ b/gdb/tui/tui-file.h @@ -26,11 +26,19 @@ class tui_file : public stdio_file { public: - explicit tui_file (FILE *stream); + tui_file (FILE *stream, bool buffered) + : stdio_file (stream), + m_buffered (buffered) + {} =20 void write (const char *buf, long length_buf) override; void puts (const char *) override; void flush () override; + +private: + + /* True if this stream is buffered. */ + bool m_buffered; }; =20 #endif /* TUI_TUI_FILE_H */ diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c index 9f27f8bcc01..0efaf69335c 100644 --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -904,8 +904,8 @@ tui_initialize_io (void) #endif =20 /* Create tui output streams. */ - tui_stdout =3D new pager_file (new tui_file (stdout)); - tui_stderr =3D new tui_file (stderr); + tui_stdout =3D new pager_file (new tui_file (stdout, true)); + tui_stderr =3D new tui_file (stderr, false); tui_stdlog =3D new timestamped_file (tui_stderr); tui_out =3D new tui_ui_out (tui_stdout);