From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH v3 03/21] Turn wrapped_file into a template
Date: Fri, 30 Jan 2026 06:17:17 -0700 [thread overview]
Message-ID: <20260130-pr-28948-logging-5-v3-3-3eec47ef3cba@tromey.com> (raw)
In-Reply-To: <20260130-pr-28948-logging-5-v3-0-3eec47ef3cba@tromey.com>
This turns wrapped_file into a template, specialized by the type of
pointer it holds. This makes it cleaner to have it own the stream it
points to.
---
| 11 +++--------
gdb/tui/tui-io.c | 2 +-
gdb/ui-file.h | 18 +++++++++---------
gdb/ui.c | 2 +-
gdb/utils.c | 2 +-
5 files changed, 15 insertions(+), 20 deletions(-)
--git a/gdb/pager.h b/gdb/pager.h
index 5d64ffcf16c..697134be805 100644
--- a/gdb/pager.h
+++ b/gdb/pager.h
@@ -23,21 +23,16 @@
/* A ui_file that implements output paging and unfiltered output. */
-class pager_file : public wrapped_file
+class pager_file : public wrapped_file<ui_file_up>
{
public:
/* Create a new pager_file. The new object takes ownership of
STREAM. */
- explicit pager_file (ui_file *stream)
- : wrapped_file (stream)
+ explicit pager_file (ui_file_up stream)
+ : wrapped_file (std::move (stream))
{
}
- ~pager_file ()
- {
- delete m_stream;
- }
-
DISABLE_COPY_AND_ASSIGN (pager_file);
void write (const char *buf, long length_buf) override;
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index bf212da92d0..7abe4fa3e81 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -933,7 +933,7 @@ tui_initialize_io (void)
#endif
/* Create tui output streams. */
- tui_stdout = new pager_file (new tui_file (stdout, true));
+ tui_stdout = new pager_file (std::make_unique<tui_file> (stdout, true));
tui_stderr = new tui_file (stderr, false);
tui_stdlog = new timestamped_file (tui_stderr);
tui_out = new cli_ui_out (tui_stdout, 0);
diff --git a/gdb/ui-file.h b/gdb/ui-file.h
index 22badec4abe..231c32deafc 100644
--- a/gdb/ui-file.h
+++ b/gdb/ui-file.h
@@ -416,8 +416,11 @@ class no_terminal_escape_file : public escape_buffering_file
void do_write (const char *buf, long len) override;
};
-/* A base class for ui_file types that wrap another ui_file. */
+/* A base class for ui_file types that wrap another ui_file. The
+ precise underlying ui_file type is a template parameter, so that
+ either owning or non-owning wrappers can be made. */
+template<typename T>
class wrapped_file : public ui_file
{
public:
@@ -451,22 +454,19 @@ class wrapped_file : public ui_file
protected:
- /* Note that this class does not assume ownership of the stream.
- However, a subclass may choose to, by adding a 'delete' to its
- destructor. */
- explicit wrapped_file (ui_file *stream)
- : m_stream (stream)
+ explicit wrapped_file (T stream)
+ : m_stream (std::move (stream))
{
}
/* The underlying stream. */
- ui_file *m_stream;
+ T m_stream;
};
/* A ui_file that optionally puts a timestamp at the start of each
line of output. */
-class timestamped_file : public wrapped_file
+class timestamped_file : public wrapped_file<ui_file *>
{
public:
explicit timestamped_file (ui_file *stream)
@@ -490,7 +490,7 @@ class timestamped_file : public wrapped_file
Note that this only really handles ASCII output correctly. */
-class tab_expansion_file : public wrapped_file
+class tab_expansion_file : public wrapped_file<ui_file *>
{
public:
diff --git a/gdb/ui.c b/gdb/ui.c
index 6d29026117e..647e63d1bde 100644
--- a/gdb/ui.c
+++ b/gdb/ui.c
@@ -48,7 +48,7 @@ ui::ui (FILE *instream_, FILE *outstream_, FILE *errstream_)
errstream (errstream_),
input_fd (fileno (instream)),
m_input_interactive_p (ISATTY (instream)),
- m_gdb_stdout (new pager_file (new stdio_file (outstream))),
+ m_gdb_stdout (new pager_file (std::make_unique<stdio_file> (outstream))),
m_gdb_stdin (new stdio_file (instream)),
m_gdb_stderr (new stderr_file (errstream)),
m_gdb_stdlog (new timestamped_file (m_gdb_stderr)),
diff --git a/gdb/utils.c b/gdb/utils.c
index ceea8317dc5..ef2d0fa0c41 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1838,7 +1838,7 @@ static void
test_pager ()
{
string_file *strfile = new string_file ();
- pager_file pager (strfile);
+ pager_file pager { ui_file_up (strfile) };
/* Make sure the pager is disabled. */
scoped_restore save_enabled
--
2.49.0
next prev parent reply other threads:[~2026-01-30 13:20 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-30 13:17 [PATCH v3 00/21] Rework gdb logging and output redirection Tom Tromey
2026-01-30 13:17 ` [PATCH v3 01/21] Remove unnecessary override of write_async_safe Tom Tromey
2026-01-30 13:17 ` [PATCH v3 02/21] Move stdtarg to ui Tom Tromey
2026-01-30 13:17 ` Tom Tromey [this message]
2026-01-30 13:17 ` [PATCH v3 04/21] Small rewrite of get_unbuffered Tom Tromey
2026-01-30 13:17 ` [PATCH v3 05/21] Move buffered stream to new files Tom Tromey
2026-01-30 13:17 ` [PATCH v3 06/21] Remove TYPE_FN_FIELD_STUB and associated code Tom Tromey
2026-01-30 13:17 ` [PATCH v3 07/21] Change how stdin is handled in the UI Tom Tromey
2026-01-30 13:17 ` [PATCH v3 08/21] Remove gdb_stdtargin Tom Tromey
2026-01-30 13:17 ` [PATCH v3 09/21] Improve fputs_highlighted by using ui_file::write Tom Tromey
2026-01-30 13:17 ` [PATCH v3 10/21] Add stream to buffer_group::output_unit constructor Tom Tromey
2026-01-30 13:17 ` [PATCH v3 11/21] Restore ui_file::can_page Tom Tromey
2026-01-30 13:17 ` [PATCH v3 12/21] Rewrite cli-style.c:do_show Tom Tromey
2026-01-30 13:17 ` [PATCH v3 13/21] Remove m_applied_style from ui_file Tom Tromey
2026-01-30 13:17 ` [PATCH v3 14/21] Add a new logging_file implementation Tom Tromey
2026-01-30 13:17 ` [PATCH v3 15/21] Rewrite output redirection and logging Tom Tromey
2026-01-30 13:17 ` [PATCH v3 16/21] Remove tee_file Tom Tromey
2026-01-30 13:17 ` [PATCH v3 17/21] Warn if log file changed while logging Tom Tromey
2026-01-30 13:17 ` [PATCH v3 18/21] Fix leaks with timestamped_file Tom Tromey
2026-01-30 13:17 ` [PATCH v3 19/21] Use std::make_unique with ui_files Tom Tromey
2026-01-30 13:17 ` [PATCH v3 20/21] Style filenames in cli-logging.c Tom Tromey
2026-01-30 13:17 ` [PATCH v3 21/21] Update gdb.execute documentation Tom Tromey
2026-01-30 13:35 ` Eli Zaretskii
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=20260130-pr-28948-logging-5-v3-3-3eec47ef3cba@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/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