public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Simplify the CLI set_logging logic
@ 2022-03-28 20:19 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-03-28 20:19 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=22f8b65e9bd75ac66d7874da8dc844dd3c42ce8b

commit 22f8b65e9bd75ac66d7874da8dc844dd3c42ce8b
Author: Tom Tromey <tom@tromey.com>
Date:   Fri Dec 31 11:30:22 2021 -0700

    Simplify the CLI set_logging logic
    
    The CLI's set_logging logic seemed unnecessarily complicated to me.
    This patch simplifies it, with an eye toward changing it to use RAII
    objects in a subsequent patch.
    
    I did not touch the corresponding MI code.  That code seems incorrect
    (nothing ever uses raw_stdlog, and nothing ever sets
    saved_raw_stdlog).  I didn't attempt to fix this, because I question
    whether this is even useful for MI.

Diff:
---
 gdb/cli/cli-interp.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 0190b4d32bc..b310ef2b050 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -413,31 +413,19 @@ cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect,
       saved_output.log = gdb_stdlog;
       saved_output.targ = gdb_stdtarg;
       saved_output.targerr = gdb_stdtargerr;
-
-      /* If something is being redirected, then grab logfile.  */
-      ui_file *logfile_p = nullptr;
-      if (logging_redirect || debug_redirect)
-	{
-	  logfile_p = logfile.get ();
-	  saved_output.file_to_delete = logfile_p;
-	}
+      gdb_assert (saved_output.file_to_delete == nullptr);
 
       /* If something is not being redirected, then a tee containing both the
 	 logfile and stdout.  */
+      ui_file *logfile_p = logfile.get ();
       ui_file *tee = nullptr;
       if (!logging_redirect || !debug_redirect)
 	{
 	  tee = new tee_file (gdb_stdout, std::move (logfile));
 	  saved_output.file_to_delete = tee;
 	}
-
-      /* Make sure that the call to logfile's dtor does not delete the
-         underlying pointer if we still keep a reference to it.  If
-         logfile_p is not referenced as the file_to_delete, then either
-         the logfile is not used (no redirection) and it should be
-         deleted, or a tee took ownership of the pointer. */
-      if (logfile_p != nullptr && saved_output.file_to_delete == logfile_p)
-	logfile.release ();
+      else
+	saved_output.file_to_delete = logfile.release ();
 
       gdb_stdout = logging_redirect ? logfile_p : tee;
       gdb_stdlog = debug_redirect ? logfile_p : tee;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-28 20:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-28 20:19 [binutils-gdb] Simplify the CLI set_logging logic Tom Tromey

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).