public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Minor redirection changes
@ 2022-11-28 21:28 Tom Tromey
  2022-11-28 21:28 ` [PATCH 1/2] Rename fields of cli_interp_base::saved_output_files Tom Tromey
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tom Tromey @ 2022-11-28 21:28 UTC (permalink / raw)
  To: gdb-patches

This short series implements the redirection changes suggested by
Simon in a recent review.

Regression tested on x86-64 Fedora 34.

Tom



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] Rename fields of cli_interp_base::saved_output_files
  2022-11-28 21:28 [PATCH 0/2] Minor redirection changes Tom Tromey
@ 2022-11-28 21:28 ` Tom Tromey
  2022-11-28 21:28 ` [PATCH 2/2] Use ui_file_up in mi_interp Tom Tromey
  2022-11-29  2:55 ` [PATCH 0/2] Minor redirection changes Simon Marchi
  2 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2022-11-28 21:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This renames the fields of cli_interp_base::saved_output_files, as
requested by Simon.  I tried to choose names that more obviously
reflect what the field is used for.  I also added a couple of
comments.
---
 gdb/cli/cli-interp.c | 14 +++++++-------
 gdb/cli/cli-interp.h | 11 +++++++----
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 3254efc3581..dbe46402c2b 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -387,7 +387,7 @@ cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect,
       m_saved_output->targerr = gdb_stdtargerr;
 
       ui_file *logfile_p = logfile.get ();
-      m_saved_output->file_to_delete = std::move (logfile);
+      m_saved_output->logfile_holder = std::move (logfile);
 
       /* The new stdout and stderr only depend on whether logging
 	 redirection is being done.  */
@@ -395,19 +395,19 @@ cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect,
       ui_file *new_stderr = logfile_p;
       if (!logging_redirect)
 	{
-	  m_saved_output->tee_to_delete.reset
+	  m_saved_output->stdout_holder.reset
 	    (new tee_file (gdb_stdout, logfile_p));
-	  new_stdout = m_saved_output->tee_to_delete.get ();
-	  m_saved_output->stderr_to_delete.reset
+	  new_stdout = m_saved_output->stdout_holder.get ();
+	  m_saved_output->stderr_holder.reset
 	    (new tee_file (gdb_stderr, logfile_p));
-	  new_stderr = m_saved_output->stderr_to_delete.get ();
+	  new_stderr = m_saved_output->stderr_holder.get ();
 	}
 
-      m_saved_output->log_to_delete.reset
+      m_saved_output->stdlog_holder.reset
 	(new timestamped_file (debug_redirect ? logfile_p : new_stderr));
 
       gdb_stdout = new_stdout;
-      gdb_stdlog = m_saved_output->log_to_delete.get ();
+      gdb_stdlog = m_saved_output->stdlog_holder.get ();
       gdb_stderr = new_stderr;
       gdb_stdtarg = new_stderr;
       gdb_stdtargerr = new_stderr;
diff --git a/gdb/cli/cli-interp.h b/gdb/cli/cli-interp.h
index 978e7f291e4..ad2167e0e1f 100644
--- a/gdb/cli/cli-interp.h
+++ b/gdb/cli/cli-interp.h
@@ -36,15 +36,18 @@ class cli_interp_base : public interp
 private:
   struct saved_output_files
   {
+    /* Saved gdb_stdout, gdb_stderr, etc.  */
     ui_file *out;
     ui_file *err;
     ui_file *log;
     ui_file *targ;
     ui_file *targerr;
-    ui_file_up tee_to_delete;
-    ui_file_up stderr_to_delete;
-    ui_file_up file_to_delete;
-    ui_file_up log_to_delete;
+    /* When redirecting, some or all of these may be non-null
+       depending on the logging mode.  */
+    ui_file_up stdout_holder;
+    ui_file_up stderr_holder;
+    ui_file_up stdlog_holder;
+    ui_file_up logfile_holder;
   };
 
   /* These hold the pushed copies of the gdb output files.  If NULL
-- 
2.34.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] Use ui_file_up in mi_interp
  2022-11-28 21:28 [PATCH 0/2] Minor redirection changes Tom Tromey
  2022-11-28 21:28 ` [PATCH 1/2] Rename fields of cli_interp_base::saved_output_files Tom Tromey
@ 2022-11-28 21:28 ` Tom Tromey
  2022-11-29  2:55 ` [PATCH 0/2] Minor redirection changes Simon Marchi
  2 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2022-11-28 21:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes mi_interp to use ui_file_up rather than explicit
management.
---
 gdb/mi/mi-interp.c | 10 ++++------
 gdb/mi/mi-interp.h |  4 ++--
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index 482166ea3a5..3cc2462f672 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -1276,7 +1276,7 @@ mi_interp::set_logging (ui_file_up logfile, bool logging_redirect,
       mi->saved_raw_stdout = mi->raw_stdout;
 
       ui_file *logfile_p = logfile.get ();
-      mi->saved_raw_file_to_delete = logfile.release ();
+      mi->logfile_holder = std::move (logfile);
 
       /* If something is not being redirected, then a tee containing both the
 	 logfile and stdout.  */
@@ -1284,19 +1284,17 @@ mi_interp::set_logging (ui_file_up logfile, bool logging_redirect,
       if (!logging_redirect || !debug_redirect)
 	{
 	  tee = new tee_file (mi->raw_stdout, logfile_p);
-	  mi->saved_tee_to_delete = tee;
+	  mi->stdout_holder.reset (tee);
 	}
 
       mi->raw_stdout = logging_redirect ? logfile_p : tee;
     }
   else
     {
-      delete mi->saved_raw_file_to_delete;
-      delete mi->saved_tee_to_delete;
+      mi->logfile_holder.reset ();
+      mi->stdout_holder.reset ();
       mi->raw_stdout = mi->saved_raw_stdout;
       mi->saved_raw_stdout = nullptr;
-      mi->saved_raw_file_to_delete = nullptr;
-      mi->saved_tee_to_delete = nullptr;
     }
 
   mi->out->set_raw (mi->raw_stdout);
diff --git a/gdb/mi/mi-interp.h b/gdb/mi/mi-interp.h
index d118ffb41e5..6b6e1f70220 100644
--- a/gdb/mi/mi-interp.h
+++ b/gdb/mi/mi-interp.h
@@ -56,8 +56,8 @@ class mi_interp final : public interp
      file which we need to delete, so we can restore correctly when
      done.  */
   struct ui_file *saved_raw_stdout;
-  struct ui_file *saved_raw_file_to_delete;
-  struct ui_file *saved_tee_to_delete;
+  ui_file_up logfile_holder;
+  ui_file_up stdout_holder;
 
   /* MI's builder.  */
   struct ui_out *mi_uiout;
-- 
2.34.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] Minor redirection changes
  2022-11-28 21:28 [PATCH 0/2] Minor redirection changes Tom Tromey
  2022-11-28 21:28 ` [PATCH 1/2] Rename fields of cli_interp_base::saved_output_files Tom Tromey
  2022-11-28 21:28 ` [PATCH 2/2] Use ui_file_up in mi_interp Tom Tromey
@ 2022-11-29  2:55 ` Simon Marchi
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Marchi @ 2022-11-29  2:55 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches



On 11/28/22 16:28, Tom Tromey via Gdb-patches wrote:
> This short series implements the redirection changes suggested by
> Simon in a recent review.
> 
> Regression tested on x86-64 Fedora 34.

Thanks, both patches LGTM:

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-29  2:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-28 21:28 [PATCH 0/2] Minor redirection changes Tom Tromey
2022-11-28 21:28 ` [PATCH 1/2] Rename fields of cli_interp_base::saved_output_files Tom Tromey
2022-11-28 21:28 ` [PATCH 2/2] Use ui_file_up in mi_interp Tom Tromey
2022-11-29  2:55 ` [PATCH 0/2] Minor redirection changes Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).