From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gproxy1-pub.mail.unifiedlayer.com (gproxy1-pub.mail.unifiedlayer.com [69.89.25.95]) by sourceware.org (Postfix) with ESMTPS id 1BAB13864858 for ; Tue, 5 Apr 2022 14:25:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1BAB13864858 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw12.mail.unifiedlayer.com (unknown [10.0.90.127]) by progateway3.mail.pro1.eigbox.com (Postfix) with ESMTP id 62ABD100478CD for ; Tue, 5 Apr 2022 14:25:32 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id bk7gniTyhb2WGbk7gn23iQ; Tue, 05 Apr 2022 14:25:32 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=V/a4bcri c=1 sm=1 tr=0 ts=624c515c a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=z0gMJWrwH1QA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=zstS-IiYAAAA:8 a=WKOaTH8r-8-750JGLMMA:9 a=4G6NA9xxw8l3yy4pmD5M:22 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=FJoCstZswVs1Q8EU/a/ZGbbzRZnE72+hMAXE5BE/BUw=; b=kbsmu13Tj4rZ+6bKEasM6jfH+Z CyAxuOxSMTrsm0Ah/tEklg0TFALsBvnxFABwMLQPYEGiohy8tto4xDz604m0+6dQaqv0gEtx5KzC2 as/c6XfhPPZOCfIr906hOpm3F; Received: from 71-211-154-204.hlrn.qwest.net ([71.211.154.204]:55428 helo=murgatroyd) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nbk7f-001ddh-HY; Tue, 05 Apr 2022 08:25:31 -0600 From: Tom Tromey To: Simon Marchi Cc: Tom Tromey , Simon Marchi via Gdb-patches Subject: Re: [PATCH] gdb: make timestamped_file implement can_emit_style_escape References: <20220331173220.2536607-1-simon.marchi@polymtl.ca> <87czhwkczk.fsf@tromey.com> <58e348e8-8d76-eda8-dd70-eb4ee889b4fe@polymtl.ca> X-Attribution: Tom Date: Tue, 05 Apr 2022 08:25:30 -0600 In-Reply-To: (Simon Marchi's message of "Mon, 4 Apr 2022 18:02:40 -0400") Message-ID: <87k0c3fvz9.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.154.204 X-Source-L: No X-Exim-ID: 1nbk7f-001ddh-HY X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-154-204.hlrn.qwest.net (murgatroyd) [71.211.154.204]:55428 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3030.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Tue, 05 Apr 2022 14:25:34 -0000 Simon> I'm thinking that isatty and flush should be implemented, since their Simon> default behavior from ui_file is probably not adequate? How about the appended? Tom commit b490690480b50918b1b4f5533e6391e9fb1e8072 Author: Tom Tromey Date: Tue Apr 5 07:44:59 2022 -0600 Introduce wrapped_file Simon pointed out that timestamped_file probably needed to implement a few more methods. This patch introduces a new file-wrapping file that forwards most of its calls, making it simpler to implement new such files. It also converts timestamped_file and pager_file to use it. Regression tested on x86-64 Fedora 34. diff --git a/gdb/pager.h b/gdb/pager.h index 0151a283629..d2a3a2b8ec8 100644 --- a/gdb/pager.h +++ b/gdb/pager.h @@ -23,16 +23,21 @@ /* A ui_file that implements output paging and unfiltered output. */ -class pager_file : public ui_file +class pager_file : public wrapped_file { public: /* Create a new pager_file. The new object takes ownership of STREAM. */ explicit pager_file (ui_file *stream) - : m_stream (stream) + : wrapped_file (stream) { } + ~pager_file () + { + delete m_stream; + } + DISABLE_COPY_AND_ASSIGN (pager_file); void write (const char *buf, long length_buf) override; @@ -44,31 +49,11 @@ class pager_file : public ui_file m_stream->write_async_safe (buf, length_buf); } - bool term_out () override - { - return m_stream->term_out (); - } - - bool isatty () override - { - return m_stream->isatty (); - } - - bool can_emit_style_escape () override - { - return m_stream->can_emit_style_escape (); - } - void emit_style_escape (const ui_file_style &style) override; void reset_style () override; void flush () override; - int fd () const override - { - return m_stream->fd (); - } - void wrap_here (int indent) override; void puts_unfiltered (const char *str) override @@ -98,9 +83,6 @@ class pager_file : public ui_file /* The style applied at the time that wrap_here was called. */ ui_file_style m_wrap_style; - /* The unfiltered output stream. */ - ui_file_up m_stream; - /* This is temporarily set when paging. This will cause some methods to change their behavior to ignore the wrap buffer. */ bool m_paging = false; diff --git a/gdb/ui-file.h b/gdb/ui-file.h index bffdeaa28c4..3af769e7ae6 100644 --- a/gdb/ui-file.h +++ b/gdb/ui-file.h @@ -391,32 +391,92 @@ class no_terminal_escape_file : public stdio_file } }; -/* A ui_file that optionally puts a timestamp at the start of each - line of output. */ +/* A base class for ui_file types that that wrap another ui_file. */ -class timestamped_file : public ui_file +class wrapped_file : public ui_file { public: - explicit timestamped_file (ui_file *stream) - : m_stream (stream) + + bool isatty () override + { + return m_stream->isatty (); + } + + bool term_out () override { + return m_stream->term_out (); } bool can_emit_style_escape () override - { return m_stream->can_emit_style_escape (); } + { + return m_stream->can_emit_style_escape (); + } + + void flush () override + { + m_stream->flush (); + } + + void wrap_here (int indent) override + { + m_stream->wrap_here (indent); + } + + void emit_style_escape (const ui_file_style &style) override + { + m_stream->emit_style_escape (style); + } + + /* Rest the current output style to the empty style. */ + void reset_style () override + { + m_stream->reset_style (); + } + + int fd () const override + { + return m_stream->fd (); + } + + void puts_unfiltered (const char *str) override + { + m_stream->puts_unfiltered (str); + } void write_async_safe (const char *buf, long length_buf) override { return m_stream->write_async_safe (buf, length_buf); } +protected: + + /* Note that this class does not assume ownership of the stream. + However, a subclass may choose to, by adding a 'delete' to its + destructor. */ + explicit wrapped_file (ui_file *stream) + : m_stream (stream) + { + } + + /* The underlying stream. */ + ui_file *m_stream; +}; + +/* A ui_file that optionally puts a timestamp at the start of each + line of output. */ + +class timestamped_file : public wrapped_file +{ +public: + explicit timestamped_file (ui_file *stream) + : wrapped_file (stream) + { + } + DISABLE_COPY_AND_ASSIGN (timestamped_file); void write (const char *buf, long len) override; private: - /* Output is sent here. */ - ui_file *m_stream; - /* True if the next output should be timestamped. */ bool m_needs_timestamp = true; };