From patchwork Tue Feb 5 15:55:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 31314 Received: (qmail 38391 invoked by alias); 5 Feb 2019 15:55:52 -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 38380 invoked by uid 89); 5 Feb 2019 15:55:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Possible X-HELO: mail-wm1-f68.google.com Received: from mail-wm1-f68.google.com (HELO mail-wm1-f68.google.com) (209.85.128.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Feb 2019 15:55:50 +0000 Received: by mail-wm1-f68.google.com with SMTP id t200so4259636wmt.0 for ; Tue, 05 Feb 2019 07:55:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=VN3eMzZpRPkhlBSZmN1oBhiehTEqnVqYsNFVs77ZbsQ=; b=ZJfOhFQmQmV0I3JN56TxsFDVpN3c+QryFlPhX0VjGv7BY1+VZrFP4/N2Kc8DzYQ0Y6 TI+eO65xiHAEROv9MT3DZCTg92tRUul+4irUvXNQOsuuSiXra7wVg3oK94192L9h5LGS 3ngo0Z62d8iWT7xo8gxzSUPw+5o3RMYYjl+5Gik8BIfJ73yqZ94x88AkMwjGZ7X47jJX B7QZ+9+qOoY6uKUoVykC03dx5CiIxgQ7wpmpKym/AzP1NqsH5jfG6VWjn5Z0u5UkVbYx XOiPG7ImO5w3HgtcLrXkxs0HPAx7gCE3jQaSDpNRu9Wg++ciU8WbWCxsKBYnDYIMsiV6 0KrA== Return-Path: Received: from localhost (cust64-dsl91-135-5.idnet.net. [91.135.5.64]) by smtp.gmail.com with ESMTPSA id j24sm23152810wrd.86.2019.02.05.07.55.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Feb 2019 07:55:47 -0800 (PST) Date: Tue, 5 Feb 2019 15:55:46 +0000 From: Andrew Burgess To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] gdb: Don't flush line wrap buffer before adding newline Message-ID: <20190205155545.GC2829@embecosm.com> References: <20190205151016.2127-1-andrew.burgess@embecosm.com> <87womentlq.fsf@tromey.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <87womentlq.fsf@tromey.com> X-Fortune: I'll show you MY telex number if you show me YOURS ... X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes * Tom Tromey [2019-02-05 08:27:29 -0700]: > >>>>> "Andrew" == Andrew Burgess writes: > > Andrew> * utils.c (fputs_maybe_filtered): Don't flush the line wrap buffer > Andrew> before inserting a newline for line-wrapping. > > Thanks, this is ok. Really, I was just teasing - this patch is rubbish :-/ (Not really, I spotted my mistake immediately after hitting send.) The code used to look like this: if (wrap_column) { emit_style_escape (ui_file_style ()); flush_wrap_buffer (stream); fputc_unfiltered ('\n', stream); } The problem is that 'emit_style_escape' sends the escape string to the wrap_buffer, while the newline is sent directly to the console. This means that GDB is still styled when the newline is sent, which I think means that if we hit a pager prompt this could be styled. I did consider having a second version of 'emit_style_escape' that by-passed the wrap_buffer, but I worried that this might be too open to incorrect use. Instead I thought a better approach would be backup and clear the wrap_buffer before calling 'emit_style_escape' in the above code, the 'flush_wrap_buffer' can then be used safely. The patch below shows a new proposal for utils.c. Do you agree with the issues I see above? What do you think of the new approach? Thanks, Andrew diff --git a/gdb/utils.c b/gdb/utils.c index 6fb5736abb5..153de6cd0f8 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1787,9 +1787,12 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream, anyway; if it's wrong, let us keep going. */ if (wrap_column) { + std::string tmp = wrap_buffer; + wrap_buffer.clear (); emit_style_escape (ui_file_style ()); flush_wrap_buffer (stream); fputc_unfiltered ('\n', stream); + wrap_buffer = tmp; } /* Possible new page. Note that