From patchwork Thu Apr 25 14:26:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32411 Received: (qmail 60357 invoked by alias); 25 Apr 2019 14:27:04 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 60349 invoked by uid 89); 25 Apr 2019 14:27:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=tee X-HELO: gateway32.websitewelcome.com Received: from gateway32.websitewelcome.com (HELO gateway32.websitewelcome.com) (192.185.145.102) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 25 Apr 2019 14:27:01 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 8561310E667 for ; Thu, 25 Apr 2019 09:27:00 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id JfL2hbAc9dnCeJfL2hMQt2; Thu, 25 Apr 2019 09:27:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ogcwOCxuNFcjJVHpNRWVtZSmJqX7fsbjec16e75l844=; b=EDwy3QbojNxpK1aOijCiJv/z7G So1zMkvYYKULj5bzo/dQ5lXuQCTqH0SNIL5lXHemgMt9xWbz4M5QfFwGLnRiN6pulVtGRUmdaRlnx AXdW3F/HcZklNPUkY9NwSPEDS; Received: from 97-122-168-123.hlrn.qwest.net ([97.122.168.123]:56282 helo=murgatroyd) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1hJfL2-000ORn-8B; Thu, 25 Apr 2019 09:27:00 -0500 From: Tom Tromey To: Alan Hayward Cc: "gdb-patches\@sourceware.org" , nd Subject: Re: [PATCH 1/4] Add debug redirect option References: <20190423130624.94781-1-alan.hayward@arm.com> <20190423130624.94781-2-alan.hayward@arm.com> Date: Thu, 25 Apr 2019 08:26:59 -0600 In-Reply-To: <20190423130624.94781-2-alan.hayward@arm.com> (Alan Hayward's message of "Tue, 23 Apr 2019 13:06:30 +0000") Message-ID: <87pnpacg98.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 >>>>> "Alan" == Alan Hayward writes: Alan> Add the option to redirect debug output seperately to normal Alan> output, using the cli command: Alan> set logging debugredirect on [...] Alan> [ Alan> An alternative would be to add an extra option to the original Alan> redirect command: Alan> set logging redirect on|off|debug Alan> This method is less flexible, but may be more intuative - setting to Alan> debug would cause just debug to be redirected. It would break Alan> existing scripts that enable using "set logging redirect 1" instead Alan> of "set logging redirect on". Alan> ] I think the choice you implemented here is fine. Alan> [ I'm also a little unsure if I have the "release" logic correct. ] One way to improve this code would be to change tee_file to use ui_file_up. That way the call to the constructor wouldn't need to use release(), just std::move. See the appended. Tom diff --git a/gdb/cli/cli-logging.c b/gdb/cli/cli-logging.c index 3a5e14de3c7..8e34bfc12bc 100644 --- a/gdb/cli/cli-logging.c +++ b/gdb/cli/cli-logging.c @@ -97,13 +97,7 @@ make_logging_output (ui_file *curr_output, ui_file_up logfile, if (logging_redirect) return logfile.release (); else - { - /* Note that the "tee" takes ownership of the log file. */ - ui_file *out = new tee_file (curr_output, false, - logfile.get (), true); - logfile.release (); - return out; - } + return new tee_file (curr_output, std::move (logfile)); } /* This is a helper for the `set logging' command. */ diff --git a/gdb/ui-file.c b/gdb/ui-file.c index 77f6b31ce4b..f18738af624 100644 --- a/gdb/ui-file.c +++ b/gdb/ui-file.c @@ -283,20 +283,13 @@ stderr_file::stderr_file (FILE *stream) -tee_file::tee_file (ui_file *one, bool close_one, - ui_file *two, bool close_two) +tee_file::tee_file (ui_file *one, ui_file_up &&two) : m_one (one), - m_two (two), - m_close_one (close_one), - m_close_two (close_two) + m_two (std::move (two)) {} tee_file::~tee_file () { - if (m_close_one) - delete m_one; - if (m_close_two) - delete m_two; } void diff --git a/gdb/ui-file.h b/gdb/ui-file.h index 6e6ca1c9cdc..a932f215416 100644 --- a/gdb/ui-file.h +++ b/gdb/ui-file.h @@ -243,11 +243,9 @@ public: class tee_file : public ui_file { public: - /* Create a file which writes to both ONE and TWO. CLOSE_ONE and - CLOSE_TWO indicate whether the original files should be closed - when the new file is closed. */ - tee_file (ui_file *one, bool close_one, - ui_file *two, bool close_two); + /* 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); ~tee_file () override; void write (const char *buf, long length_buf) override; @@ -258,10 +256,9 @@ public: void flush () override; private: - /* The two underlying ui_files, and whether they should each be - closed on destruction. */ - ui_file *m_one, *m_two; - bool m_close_one, m_close_two; + /* The two underlying ui_files. */ + ui_file *m_one; + ui_file_up m_two; }; #endif