From patchwork Tue Feb 5 15:10:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 31313 Received: (qmail 84335 invoked by alias); 5 Feb 2019 15:10:35 -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 84317 invoked by uid 89); 5 Feb 2019 15:10:35 -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, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=spot X-HELO: mail-wr1-f65.google.com Received: from mail-wr1-f65.google.com (HELO mail-wr1-f65.google.com) (209.85.221.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Feb 2019 15:10:33 +0000 Received: by mail-wr1-f65.google.com with SMTP id q18so3981476wrx.9 for ; Tue, 05 Feb 2019 07:10:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id; bh=ZO2oXoYrJ+mLhh5Ms9XYGC1bANsT66Wie6rO7xOJYC0=; b=Rpv56dcUI5OL7d65deeVjTouPfNxuNCivHekUNqSERfj/JizH26llPlBqsRwVMnj44 BhekxfsdXdrb38UDSOZ4SyURaOe+TMzhbd8NRSUPmBzubrB5fK09XILi3THkyTnbg+S2 ZF9xDgq/hCI6JhA3pCYpPwmRPxIsWW8QcyUqqPiCuI/tg02nSbLUrPhsE2FlfaFtN1l4 7fMKr4Iyxtgz4EQ8/WvYHg5TWFTqLZ+AiWoRfm6Pt5WUadw5XzP3CYctFXGbpvQclEzK HCr4U5Q0fftcN2SyM4cykkHJcE206OjnOe4e1MRJrQ5Tmm4X1jGUovUI+FtcBNM1F9tQ rWyQ== Return-Path: Received: from localhost (cust64-dsl91-135-5.idnet.net. [91.135.5.64]) by smtp.gmail.com with ESMTPSA id m15sm22477478wrr.95.2019.02.05.07.10.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Feb 2019 07:10:29 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Tom Tromey , Andrew Burgess Subject: [PATCH] gdb: Don't flush line wrap buffer before adding newline Date: Tue, 5 Feb 2019 15:10:16 +0000 Message-Id: <20190205151016.2127-1-andrew.burgess@embecosm.com> X-IsSubscribed: yes A bug was introduced in commit: commit cbe5657196d0d3acbeca39973f93f333ecedacda Date: Mon Sep 3 22:56:33 2018 -0600 Add output styles to gdb As GDB produces output, the output is stored in a temporary buffer. In this way GDB can spot when a line wrap occurs, and can insert a newline before flushing the contents of the temporary buffer out. The bug was that the temporary buffer was being flushed out _before_ the newline was added to the output stream, this resulted in incorrect line wrapping. Here is an example from how GDB announces that a breakpoint has been hit, first with the bug: Breakpoint 1, function () at /a/long/pa th/to/the/source/file.c:123 Now with the bug fixed (this matches the behaviour before the offending commit): Breakpoint 1, function () at /a/long/path/to/the/source/file.c:123 There are some other issues with line wrapping in current HEAD of GDB, but these are caused by an unrelated bug. gdb/ChangeLog: * utils.c (fputs_maybe_filtered): Don't flush the line wrap buffer before inserting a newline for line-wrapping. gdb/testsuite/ChangeLog: * gdb.base/line-wrapping.c: New file. * gdb.base/line-wrapping.exp: New file. --- gdb/ChangeLog | 5 ++++ gdb/testsuite/ChangeLog | 5 ++++ gdb/testsuite/gdb.base/line-wrapping.c | 28 ++++++++++++++++++++++ gdb/testsuite/gdb.base/line-wrapping.exp | 41 ++++++++++++++++++++++++++++++++ gdb/utils.c | 1 - 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.base/line-wrapping.c create mode 100644 gdb/testsuite/gdb.base/line-wrapping.exp diff --git a/gdb/testsuite/gdb.base/line-wrapping.c b/gdb/testsuite/gdb.base/line-wrapping.c new file mode 100644 index 00000000000..5fdb4462e65 --- /dev/null +++ b/gdb/testsuite/gdb.base/line-wrapping.c @@ -0,0 +1,28 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2019 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +some_rather_long_function_name () +{ + return 0; +} + +int +main () +{ + return some_rather_long_function_name (); +} diff --git a/gdb/testsuite/gdb.base/line-wrapping.exp b/gdb/testsuite/gdb.base/line-wrapping.exp new file mode 100644 index 00000000000..94b8bc6ea13 --- /dev/null +++ b/gdb/testsuite/gdb.base/line-wrapping.exp @@ -0,0 +1,41 @@ +# Copyright 2019 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This tests some line-wrapping cases in GDB. + +standard_testfile + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} { + return -1 +} + +gdb_test_no_output "set width 55" + +if ![runto_main] then { + fail "can't run to main" + return 0 +} + +# Use GDB_TEST here not GDB_CONTINUE_TO_BREAKPOINT as we want to check +# specifically that the lines are broken at the correct place, and the +# correct whitespace is added before the "at". +gdb_breakpoint "some_rather_long_function_name" +gdb_test "continue" \ + [multi_line \ + "Breakpoint 2, some_rather_long_function_name \\(\\)" \ + " at \[^\r\n\]+$srcfile:$decimal" \ + "$decimal\[^\r\n\]+"] \ + "line wrapping at a breakpoint" + diff --git a/gdb/utils.c b/gdb/utils.c index 6fb5736abb5..7bcc4b97b7c 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1788,7 +1788,6 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream, if (wrap_column) { emit_style_escape (ui_file_style ()); - flush_wrap_buffer (stream); fputc_unfiltered ('\n', stream); }