public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 1/4] Simplify the CLI set_logging logic
Date: Fri, 31 Dec 2021 13:18:58 -0700	[thread overview]
Message-ID: <20211231201901.1567610-2-tom@tromey.com> (raw)
In-Reply-To: <20211231201901.1567610-1-tom@tromey.com>

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.
---
 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 47d1eff0547..3094775c9f5 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -412,31 +412,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;
-- 
2.31.1


  reply	other threads:[~2021-12-31 20:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-31 20:18 [PATCH 0/4] Change how stdlog timestamps are written Tom Tromey
2021-12-31 20:18 ` Tom Tromey [this message]
2021-12-31 20:18 ` [PATCH 2/4] Use unique_ptr in CLI logging code Tom Tromey
2021-12-31 20:19 ` [PATCH 3/4] Add new timestamped_file class Tom Tromey
2021-12-31 20:19 ` [PATCH 4/4] Switch gdb_stdlog to use timestamped_file Tom Tromey
2022-03-24 16:21 ` [PATCH 0/4] Change how stdlog timestamps are written Tom Tromey
2022-03-28 20:12   ` Tom Tromey

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=20211231201901.1567610-2-tom@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).