From patchwork Thu Nov 17 18:29:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 60793 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3D4E13853D62 for ; Thu, 17 Nov 2022 18:30:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D4E13853D62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668709809; bh=JsZaGGQc8EW50OUuhGR43n/3To/wiVJpbPC9lq9CF1g=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=eZTK+FYQLWmdBCOjJsdjdDd1tigjdF2i1g1cvsUFoLu5BU+qOVjg05eYjqvfrpKir 0oqMtfc21NU/KlI5yWE4DDHffeyb1JE1txsuyVd5elHp4oeYOwYXFv6U5QJMZebwUp TZKde3thxMt6DQX5wNRVC1ylf6VZpNGk8If4VKKc= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by sourceware.org (Postfix) with ESMTPS id 3B7683853D41 for ; Thu, 17 Nov 2022 18:29:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3B7683853D41 Received: by mail-io1-xd31.google.com with SMTP id d123so2027809iof.7 for ; Thu, 17 Nov 2022 10:29:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JsZaGGQc8EW50OUuhGR43n/3To/wiVJpbPC9lq9CF1g=; b=jZs8r0s4Z7lFHrBXmdxM61mtRRHszakLCOwZpWdmkH0sbQfIhjkLZZoGyOleQUDiWI kncc8rETR2sf1hH3lAXL/YEf7Ic8r8cCGfuBL7UYGG613OtOiBAsoMwzxMlz6+TFBsjk DWROwb2oRwpBaYUvGjknJASdNPKQEcybme2pC/rptw6i5XWw/TMNy/BZjI7RBjD9kxT/ 3SeUaqFzOaF/ghcr/k2qBzpdPMwSrcxdChZg8PwVNoeGwky86V62EYrLnGADf1pT+QoE rRt94rEMnOwlZDCaQSrepoPGMXX80dPW1p2BwMGbyWMpYU8XedPUxW0DtC7cZnXwAySD 2IMw== X-Gm-Message-State: ANoB5pkDmOuN20tRZq2NZGDGjJEFGmqVODbNcwxq8/Ce0OaVZBF3mmHM t2VvqSua3/ji8iusJ75oSvdvKHOBz6BPwA== X-Google-Smtp-Source: AA0mqf6QKYeure8LPMQSPdFAuOdE8rVAfOgIJNcQnl5yVSFr9oclbKVgd0W3nSdG1YFjfsPWpq44oA== X-Received: by 2002:a6b:c844:0:b0:6db:fe34:6948 with SMTP id y65-20020a6bc844000000b006dbfe346948mr1890365iof.209.1668709755473; Thu, 17 Nov 2022 10:29:15 -0800 (PST) Received: from localhost.localdomain (97-122-76-186.hlrn.qwest.net. [97.122.76.186]) by smtp.gmail.com with ESMTPSA id g68-20020a025b47000000b00365c1bd9ac7sm469409jab.113.2022.11.17.10.29.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 10:29:15 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/3] Don't let tee_file own a stream Date: Thu, 17 Nov 2022 11:29:03 -0700 Message-Id: <20221117182904.1291713-3-tromey@adacore.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20221117182904.1291713-1-tromey@adacore.com> References: <20221117182904.1291713-1-tromey@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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. --- 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, bool logging_redirect, m_saved_output->targ = gdb_stdtarg; m_saved_output->targerr = gdb_stdtargerr; + ui_file *logfile_p = logfile.get (); + m_saved_output->file_to_delete = std::move (logfile); + /* 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)); - m_saved_output->file_to_delete.reset (tee); + m_saved_output->tee_to_delete.reset + (new tee_file (gdb_stdout, logfile_p)); + tee = m_saved_output->tee_to_delete.get (); } - else - m_saved_output->file_to_delete = std::move (logfile); 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 @@ class cli_interp_base : public interp 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 logging_redirect, { mi->saved_raw_stdout = mi->raw_stdout; - /* If something is being redirected, then grab logfile. */ - ui_file *logfile_p = nullptr; - if (logging_redirect || debug_redirect) - { - logfile_p = logfile.get (); - mi->saved_raw_file_to_delete = logfile_p; - } + ui_file *logfile_p = logfile.get (); + mi->saved_raw_file_to_delete = logfile.release (); /* If something is not being redirected, then a tee containing both the logfile and stdout. */ ui_file *tee = nullptr; if (!logging_redirect || !debug_redirect) { - tee = new tee_file (mi->raw_stdout, std::move (logfile)); - mi->saved_raw_file_to_delete = tee; + tee = new tee_file (mi->raw_stdout, logfile_p); + mi->saved_tee_to_delete = tee; } mi->raw_stdout = logging_redirect ? logfile_p : tee; @@ -1297,9 +1292,11 @@ mi_interp::set_logging (ui_file_up logfile, bool logging_redirect, else { delete mi->saved_raw_file_to_delete; + delete mi->saved_tee_to_delete; 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 d89439f54c5..d118ffb41e5 100644 --- a/gdb/mi/mi-interp.h +++ b/gdb/mi/mi-interp.h @@ -57,7 +57,7 @@ class mi_interp final : public interp done. */ struct ui_file *saved_raw_stdout; struct ui_file *saved_raw_file_to_delete; - + struct ui_file *saved_tee_to_delete; /* 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) -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) {} 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 @@ class stderr_file : public stdio_file 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; void write (const char *buf, long length_buf) override; @@ -364,7 +364,7 @@ class tee_file : public ui_file private: /* The two underlying ui_files. */ ui_file *m_one; - ui_file_up m_two; + ui_file *m_two; }; /* A ui_file implementation that filters out terminal escape