From patchwork Wed May 1 17:22:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32474 Received: (qmail 105619 invoked by alias); 1 May 2019 17:22:50 -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 105527 invoked by uid 89); 1 May 2019 17:22:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.0 required=5.0 tests=AWL, 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.1 spammy=pager, HContent-Transfer-Encoding:8bit X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 01 May 2019 17:22:47 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 9486E1173B3; Wed, 1 May 2019 13:22:45 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id UzejLEvsnHwj; Wed, 1 May 2019 13:22:45 -0400 (EDT) Received: from murgatroyd.Home (97-122-168-123.hlrn.qwest.net [97.122.168.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 408FF117385; Wed, 1 May 2019 13:22:45 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 8.3] Fix style bug when paging Date: Wed, 1 May 2019 11:22:40 -0600 Message-Id: <20190501172240.30569-1-tromey@adacore.com> MIME-Version: 1.0 Philippe pointed out a styling bug that would occur in some conditions when paging: https://sourceware.org/ml/gdb-patches/2019-04/msg00101.html I was finally able to reproduce this, and this patch fixes the bug. The problem occurred when text overflowed the line, causing a pagination prompt, but when no wrap column had been set. In this case, the current style was reset to show the prompt, but then not reset back to the previously applied style before emitting the rest of the line. The fix is to record the applied style in this case, and re-apply it afterward -- but only if the pager prompt was emitted, something that the existing style.exp pointed out on the first, more naive, version of the patch. Tested on x86-64 Fedora 29. gdb/ChangeLog 2019-05-01 Tom Tromey * utils.c (fputs_maybe_filtered): Reset style after paging, even when no wrap column is set. --- gdb/ChangeLog | 5 +++++ gdb/utils.c | 24 +++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/gdb/utils.c b/gdb/utils.c index dd686fa8aa2..83ddc23a914 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1808,10 +1808,20 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream, { unsigned int save_chars = chars_printed; + /* If we change the style, below, we'll want to reset it + before continuing to print. If there is no wrap + column, then we'll only reset the style if the pager + prompt is given; and to avoid emitting style + sequences in the middle of a run of text, we track + this as well. */ + ui_file_style save_style; + bool did_paginate = false; + chars_printed = 0; lines_printed++; if (wrap_column) { + save_style = wrap_style; if (can_emit_style_escape (stream)) emit_style_escape (ui_file_style (), stream); /* If we aren't actually wrapping, don't output @@ -1821,21 +1831,27 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream, fputc_unfiltered ('\n', stream); } else - flush_wrap_buffer (stream); + { + save_style = applied_style; + flush_wrap_buffer (stream); + } /* Possible new page. Note that PAGINATION_DISABLED_FOR_COMMAND might be set during this loop, so we must continue to check it here. */ if (lines_printed >= lines_per_page - 1 && !pagination_disabled_for_command) - prompt_for_continue (); + { + prompt_for_continue (); + did_paginate = true; + } /* Now output indentation and wrapped string. */ if (wrap_column) { fputs_unfiltered (wrap_indent, stream); if (can_emit_style_escape (stream)) - emit_style_escape (wrap_style, stream); + emit_style_escape (save_style, stream); /* FIXME, this strlen is what prevents wrap_indent from containing tabs. However, if we recurse to print it and count its chars, we risk trouble if wrap_indent is @@ -1846,6 +1862,8 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream, + (save_chars - wrap_column); wrap_column = 0; /* And disable fancy wrap */ } + else if (did_paginate && can_emit_style_escape (stream)) + emit_style_escape (save_style, stream); } }