From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 916DF385781F; Mon, 28 Mar 2022 20:19:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 916DF385781F 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] Simplify the CLI set_logging logic X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 48ac197b0c209ccf1f2de9704eb6cdf7c5c73a8e X-Git-Newrev: 22f8b65e9bd75ac66d7874da8dc844dd3c42ce8b Message-Id: <20220328201934.916DF385781F@sourceware.org> Date: Mon, 28 Mar 2022 20:19:34 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Mar 2022 20:19:34 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D22f8b65e9bd7= 5ac66d7874da8dc844dd3c42ce8b commit 22f8b65e9bd75ac66d7874da8dc844dd3c42ce8b Author: Tom Tromey Date: Fri Dec 31 11:30:22 2021 -0700 Simplify the CLI set_logging logic =20 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. =20 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, boo= l logging_redirect, saved_output.log =3D gdb_stdlog; saved_output.targ =3D gdb_stdtarg; saved_output.targerr =3D gdb_stdtargerr; - - /* If something is being redirected, then grab logfile. */ - ui_file *logfile_p =3D nullptr; - if (logging_redirect || debug_redirect) - { - logfile_p =3D logfile.get (); - saved_output.file_to_delete =3D logfile_p; - } + gdb_assert (saved_output.file_to_delete =3D=3D nullptr); =20 /* If something is not being redirected, then a tee containing both = the logfile and stdout. */ + ui_file *logfile_p =3D logfile.get (); ui_file *tee =3D nullptr; if (!logging_redirect || !debug_redirect) { tee =3D new tee_file (gdb_stdout, std::move (logfile)); saved_output.file_to_delete =3D 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 !=3D nullptr && saved_output.file_to_delete =3D=3D log= file_p) - logfile.release (); + else + saved_output.file_to_delete =3D logfile.release (); =20 gdb_stdout =3D logging_redirect ? logfile_p : tee; gdb_stdlog =3D debug_redirect ? logfile_p : tee;