From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id A78DA385B1AB; Mon, 28 Nov 2022 20:41:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A78DA385B1AB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669668101; bh=+PTxRRiObu27OIJM/WsE7mpvrNal4g2WL8ePYQz6iWg=; h=From:To:Subject:Date:From; b=GcT14W8+sL/w9nmIL0kIM88s+rs8vCVue1LlcrG0h/vz3t/B2qmD7Kl64TCbAjVqX bkrNdpF56MAbs5Oqh7PRaH72aPRAMNb2wGR8qlbSaCyHs43R0A29wcng3dkjZ32EDl mVLAINGC1TuXbQhphwg45sbCPTXni5hT0gAlFygY= 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] Don't let tee_file own a stream X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 19622df10dd5a8d3567e79d0661770029e4fbcfe X-Git-Newrev: 2b141965f2ddef8cf3e79d357768a98c8703a5df Message-Id: <20221128204141.A78DA385B1AB@sourceware.org> Date: Mon, 28 Nov 2022 20:41:41 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D2b141965f2dd= ef8cf3e79d357768a98c8703a5df commit 2b141965f2ddef8cf3e79d357768a98c8703a5df Author: Tom Tromey Date: Thu Nov 17 09:09:59 2022 -0700 Don't let tee_file own a stream =20 Right now, tee_file owns the second stream it writes to. This is done for the convenience of the users. In a subsequent patch, this will no longer be convenient, so this patch moves the responsibility for ownership to the users of tee_file. Diff: --- gdb/cli/cli-interp.c | 11 ++++++----- gdb/cli/cli-interp.h | 1 + gdb/mi/mi-interp.c | 15 ++++++--------- gdb/mi/mi-interp.h | 2 +- gdb/ui-file.c | 4 ++-- gdb/ui-file.h | 8 ++++---- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c index 8c2fb207486..2e8f6135405 100644 --- a/gdb/cli/cli-interp.c +++ b/gdb/cli/cli-interp.c @@ -386,17 +386,18 @@ cli_interp_base::set_logging (ui_file_up logfile, boo= l logging_redirect, m_saved_output->targ =3D gdb_stdtarg; m_saved_output->targerr =3D gdb_stdtargerr; =20 + ui_file *logfile_p =3D logfile.get (); + m_saved_output->file_to_delete =3D std::move (logfile); + /* 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)); - m_saved_output->file_to_delete.reset (tee); + m_saved_output->tee_to_delete.reset + (new tee_file (gdb_stdout, logfile_p)); + tee =3D m_saved_output->tee_to_delete.get (); } - else - m_saved_output->file_to_delete =3D std::move (logfile); =20 m_saved_output->log_to_delete.reset (new timestamped_file (debug_redirect ? logfile_p : tee)); diff --git a/gdb/cli/cli-interp.h b/gdb/cli/cli-interp.h index 3c233c0a229..fa007d78621 100644 --- a/gdb/cli/cli-interp.h +++ b/gdb/cli/cli-interp.h @@ -41,6 +41,7 @@ private: ui_file *log; ui_file *targ; ui_file *targerr; + ui_file_up tee_to_delete; ui_file_up file_to_delete; ui_file_up log_to_delete; }; diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c index af242208a0b..482166ea3a5 100644 --- a/gdb/mi/mi-interp.c +++ b/gdb/mi/mi-interp.c @@ -1275,21 +1275,16 @@ mi_interp::set_logging (ui_file_up logfile, bool lo= gging_redirect, { mi->saved_raw_stdout =3D mi->raw_stdout; =20 - /* If something is being redirected, then grab logfile. */ - ui_file *logfile_p =3D nullptr; - if (logging_redirect || debug_redirect) - { - logfile_p =3D logfile.get (); - mi->saved_raw_file_to_delete =3D logfile_p; - } + ui_file *logfile_p =3D logfile.get (); + mi->saved_raw_file_to_delete =3D logfile.release (); =20 /* If something is not being redirected, then a tee containing both = the logfile and stdout. */ ui_file *tee =3D nullptr; if (!logging_redirect || !debug_redirect) { - tee =3D new tee_file (mi->raw_stdout, std::move (logfile)); - mi->saved_raw_file_to_delete =3D tee; + tee =3D new tee_file (mi->raw_stdout, logfile_p); + mi->saved_tee_to_delete =3D tee; } =20 mi->raw_stdout =3D logging_redirect ? logfile_p : tee; @@ -1297,9 +1292,11 @@ mi_interp::set_logging (ui_file_up logfile, bool log= ging_redirect, else { delete mi->saved_raw_file_to_delete; + delete mi->saved_tee_to_delete; mi->raw_stdout =3D mi->saved_raw_stdout; mi->saved_raw_stdout =3D nullptr; mi->saved_raw_file_to_delete =3D nullptr; + mi->saved_tee_to_delete =3D nullptr; } =20 mi->out->set_raw (mi->raw_stdout); diff --git a/gdb/mi/mi-interp.h b/gdb/mi/mi-interp.h index d89439f54c5..d118ffb41e5 100644 --- a/gdb/mi/mi-interp.h +++ b/gdb/mi/mi-interp.h @@ -57,7 +57,7 @@ public: done. */ struct ui_file *saved_raw_stdout; struct ui_file *saved_raw_file_to_delete; - + struct ui_file *saved_tee_to_delete; =20 /* MI's builder. */ struct ui_out *mi_uiout; diff --git a/gdb/ui-file.c b/gdb/ui-file.c index 47044e42a67..3343b6b8fc5 100644 --- a/gdb/ui-file.c +++ b/gdb/ui-file.c @@ -384,9 +384,9 @@ stderr_file::stderr_file (FILE *stream) =20 =0C =20 -tee_file::tee_file (ui_file *one, ui_file_up &&two) +tee_file::tee_file (ui_file *one, ui_file *two) : m_one (one), - m_two (std::move (two)) + m_two (two) {} =20 tee_file::~tee_file () diff --git a/gdb/ui-file.h b/gdb/ui-file.h index e33ae79e753..4a006bbba4c 100644 --- a/gdb/ui-file.h +++ b/gdb/ui-file.h @@ -329,9 +329,9 @@ public: class tee_file : public ui_file { public: - /* Create a file which writes to both ONE and TWO. ONE will remain - open when this object is destroyed; but TWO will be closed. */ - tee_file (ui_file *one, ui_file_up &&two); + /* Create a file which writes to both ONE and TWO. Ownership of + both files is up to the user. */ + tee_file (ui_file *one, ui_file *two); ~tee_file () override; =20 void write (const char *buf, long length_buf) override; @@ -364,7 +364,7 @@ public: private: /* The two underlying ui_files. */ ui_file *m_one; - ui_file_up m_two; + ui_file *m_two; }; =20 /* A ui_file implementation that filters out terminal escape