From patchwork Wed Jan 25 12:08:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 63661 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3497038582BE for ; Wed, 25 Jan 2023 12:09:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3497038582BE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674648568; bh=ljpvGcx0eP/75eOPtycCmnESm+iBC2Sl+xdvssHgX9A=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Sl7L1TWIEZVq6DxoVSF8zCMpiWjNqz51Q6M64ae6PtrRck8iLnCkmef3DQ0CGbMqc oRpzMa7u9Vhzb8qJbGM2C6hxufrG90nyIy9hArCrEHQ/1/yEIed45+Le7Igcbry5jm X/LjbAxsfz709VNO0gDZTLzXolPtq1oYW+mCyvPE= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id A3D323858C2F for ; Wed, 25 Jan 2023 12:09:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A3D323858C2F Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-499-PmA4qEflMruSXxJm7bGF0w-1; Wed, 25 Jan 2023 07:08:57 -0500 X-MC-Unique: PmA4qEflMruSXxJm7bGF0w-1 Received: by mail-yb1-f200.google.com with SMTP id u186-20020a2560c3000000b007c8e2cf3668so19680867ybb.14 for ; Wed, 25 Jan 2023 04:08:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ljpvGcx0eP/75eOPtycCmnESm+iBC2Sl+xdvssHgX9A=; b=1jLpE2nVXIsjlYCSHy2H5c6wtYXNyCEnlPnETdnG75J+K9M0BIcy4jOQTOQqhh999e C7JeHkzcWFszvU5dTv5xZh1lcEE2KS2GFfm+P7gxqRRZn+trEvzjy+hdxJWkf/kORbqM /uz/hiEPTUJQ/3IvFIW0P0hG4XDYuxpA7R6Ctm/KuVcoglanZlSwYJ7mqxoWHCH289cW 9WDdB5phUBwtsp1VQJKEXvyYFFi3G/5GekWacaNJjU3zlyx7Ac7WP2anyJlmQ9SC5P5N rVSAK5fe2U+CHudYLkvUYsTv1yZchQLUBlOIWsPCu0UVmhRfiuIrb73vyITi5tFGPv2E AaEA== X-Gm-Message-State: AFqh2kp03RU2iNoZvXKzFFwl0KkFTiTy8631K9RljSlCnHbYTL5hNY4s bRtF5XCv5i+o1iBjjrdJ2HnsSwwdhEF0PxU8josJaFrWvLAyBU0RsLCIOf+teVqEOv3db/RCUC3 2IToLETG+I0qV/DvcW9EIqLPWGmX2cTxlCr8xOdpAyw9Xw0zbLN4FIxsIdJhLPPEVtya3yaM+Cg == X-Received: by 2002:a25:ddc4:0:b0:701:8d69:eefb with SMTP id u187-20020a25ddc4000000b007018d69eefbmr17868911ybg.43.1674648537253; Wed, 25 Jan 2023 04:08:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXsk3IkFvHDSaE5FMbwVpHrAmXLQxg4juFXWv9h77HzCDyzyTzB2/kYbtwiXTzKLoYfThlzvYg== X-Received: by 2002:a25:ddc4:0:b0:701:8d69:eefb with SMTP id u187-20020a25ddc4000000b007018d69eefbmr17868890ybg.43.1674648536980; Wed, 25 Jan 2023 04:08:56 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id z20-20020a05620a101400b007056237b41bsm3373779qkj.67.2023.01.25.04.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 04:08:56 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 1/8] gdb/testsuite: fix line feed scrolling in tuiterm.exp Date: Wed, 25 Jan 2023 12:08:41 +0000 Message-Id: <11b615e8de660b1fb12ded842d8fe6aaafc58e38.1674648473.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" In a following commit I managed to trigger the line feed scrolling case in tuiterm.exp. This case is currently unhandled, and this commit fills in this missing functionality. The implementation is pretty simple, just scroll all the content up one line at a time until the cursor is back on the screen (a single line of scroll is all that should be needed). This change is untested in this commit, but is required by the next commit. --- gdb/testsuite/lib/tuiterm.exp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp index c38ccbbdbd7..8a3f7a48acc 100644 --- a/gdb/testsuite/lib/tuiterm.exp +++ b/gdb/testsuite/lib/tuiterm.exp @@ -99,10 +99,24 @@ namespace eval Term { _log_cur "Line feed" { variable _cur_row variable _rows + variable _cols + variable _chars incr _cur_row 1 - if {$_cur_row >= $_rows} { - error "FIXME scroll" + while {$_cur_row >= $_rows} { + # Scroll the display contents. We scroll one line at + # a time here; as _cur_row was only increased by one, + # a single line scroll should be enough to put the + # cursor back on the screen. But we wrap the + # scrolling inside a while loop just to be on the safe + # side. + for {set y 0} {$y < [expr $_rows - 1]} {incr y} { + set next_y [expr $y + 1] + for {set x 0} {$x < $_cols} {incr x} { + set _chars($x,$y) $_chars($x,$next_y) + } + incr _cur_row -1 + } } } } From patchwork Wed Jan 25 12:08:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 63662 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 30F43385B530 for ; Wed, 25 Jan 2023 12:09:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30F43385B530 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674648573; bh=7hjC1ZHtNiRh6ro5asSSLid/ad/hrl4964X0sjtpv5Q=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Nu/c27St5H/NS9H4nldEglukGKGBAPaHAW4nY582IE03LI0hHiqUBkceECoroj5td KrmBEH958+881RkpIltyM2/SW47vaFW0UkVx3k+0+yPBg9iE2QFAzqakvFa1SCnKXf JSxNg9XPb31erOK8P/eZK/2PONO0rWU+4BOSa6DY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 147503858D39 for ; Wed, 25 Jan 2023 12:09:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 147503858D39 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-138-ZL8lLm3BNf2pu6EmE5tbRw-1; Wed, 25 Jan 2023 07:09:00 -0500 X-MC-Unique: ZL8lLm3BNf2pu6EmE5tbRw-1 Received: by mail-qt1-f200.google.com with SMTP id a13-20020ac84d8d000000b003b63a85ae73so7524912qtw.21 for ; Wed, 25 Jan 2023 04:09:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7hjC1ZHtNiRh6ro5asSSLid/ad/hrl4964X0sjtpv5Q=; b=NgZB+x97b0I0vugadwKWU1XakHxlcvxx7FHgVXBalmN3Ht+HB86hkJFhOymRWqZ4Vu RvN4uEsEYfRnxQu/xmTJKPvsJ6+sB9+s0yocDR2Z+hNBG5zsSzVbrZTBGvkZmHnEV3g7 4LaNE2xTdSmj+xetKbgX4ioG0KMlGy2Ow8UV1Frj/CCW9ShJzpsRUOgdbTFsLPY6hPKT ApXM7jE9OpnoPn4/nJM4EtuFcJw3jqrg0o2P6rGXaXBAKFmg9I5SIiPKOs00hDu5O4Pf y5xJYzvFXojM5bJ/aEAR04P4JL9LRwNmpqD05E4+4vQPK6scO3/lpV9s7GLaAU1S+ecO bA2w== X-Gm-Message-State: AO0yUKU4/zgzH/SfW0FhfnkkrxpzPt4kyltzWSINoMk3RsuRAhQJ5b5P zmQlOUjvO47W8b1qw1U2E1UvXEvmfLP+v4f2mchgOIwF6cLTo+BojRVcdg6QcLxCSsJ4z+guBv3 V+7hA60swA8H4gJFIH94+2hfU1XtOprJTHm++GD5lKMjnD1HHv26eBNvhpieeiiiK5xvwGbrJFg == X-Received: by 2002:ac8:5ad0:0:b0:3b6:8ad1:3be9 with SMTP id d16-20020ac85ad0000000b003b68ad13be9mr3560820qtd.32.1674648539488; Wed, 25 Jan 2023 04:08:59 -0800 (PST) X-Google-Smtp-Source: AK7set+ODz5mV5G6YI9b7UlRr4k7wrXhLNTDIgKAty1Z/nOp+ELYpouc4jhhLcVZm7aHrnLcQS7FeQ== X-Received: by 2002:ac8:5ad0:0:b0:3b6:8ad1:3be9 with SMTP id d16-20020ac85ad0000000b003b68ad13be9mr3560761qtd.32.1674648538971; Wed, 25 Jan 2023 04:08:58 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id r4-20020ac84244000000b003b63a734434sm3173221qtm.52.2023.01.25.04.08.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 04:08:58 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 2/8] gdb/tui: improve errors from tui focus command Date: Wed, 25 Jan 2023 12:08:42 +0000 Message-Id: <5ae0067488cd91d1dbf54eac77406c89acab72b2.1674648473.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This commit improves (I think) the errors from the tui focus command. There are a number of errors that can be triggered by the focus command, they include: (1) Window name "NAME" is ambiguous (2) Unrecognized window name "NAME" (3) Window "NAME" cannot be focused Error (1) is triggered when the user gives a partial window name, and the name matches multiple windows in the current layout. It is worth noting that the ambiguity must be within the current layout; if the partial name matches one window in the current layout, and one or more windows not in the current layout, then this is not ambiguous, and focus will shift to the matching window in the current layout. This error was not previous being tested, but in this commit I make use of the Python API to trigger and test this error. Error (3) is simple enough, and was already being tested. This is triggered by something like 'focus status'. The named window needs to be present in the current layout, and non-focusable in order to trigger the error. Error (2) is what I'd like to improve in this commit. This error triggers if the name the user gives doesn't match any window in the current layout. Even if GDB does know about the window, but the window isn't in the current layout, then GDB will say it doesn't recognize the window name. In this commit I propose to to split this error into three different errors. These will be: (a) Unrecognized window name "NAME" (b) No windows matching "NAME" in the current layout (c) Window "NAME" is not in the current layout Error (a) is the same as before, but will now only trigger if GDB doesn't know about window NAME at all. If the window is known, but not in the current layout then one of the other errors will trigger. Error (b) will trigger if NAME is ambiguous for multiple windows that are not in the current layout. If NAME identifies a single window in the current layout then that window will continue to be selected, just as it currently is. Only in the case where NAME doesn't identify a window in the current layout do we then check all the other known windows, if NAME matches multiple of these, then (b) is triggered. Finally, error (c) is used when NAME uniquely identifies a single window that is not in the current layout. The hope with these new errors is that the user will have a better understanding of what went wrong. Instead of GDB claiming to not know about a window, the mention of the current layout will hint to the user that they should first switch layouts. There are tests included for all the new errors. --- gdb/testsuite/gdb.tui/tui-focus.exp | 85 +++++++++++++++++++++++++++-- gdb/tui/tui-layout.c | 15 ++++- gdb/tui/tui-layout.h | 49 +++++++++++++++++ gdb/tui/tui-win.c | 40 +++++++++++++- 4 files changed, 179 insertions(+), 10 deletions(-) diff --git a/gdb/testsuite/gdb.tui/tui-focus.exp b/gdb/testsuite/gdb.tui/tui-focus.exp index 9e2a1cd0935..72f80523af3 100644 --- a/gdb/testsuite/gdb.tui/tui-focus.exp +++ b/gdb/testsuite/gdb.tui/tui-focus.exp @@ -13,12 +13,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# Minimal testcase that just checks that the various "layout $foo" -# commands do not cause gdb to crash. +# Testcase that just checks the tui 'focus' command works as expected. require allow_tui_tests tuiterm_env +load_lib gdb-python.exp standard_testfile @@ -31,7 +31,8 @@ if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} { # Each test specification is a tuple where the first item is the name of a # window, and the second item is a boolean indicating if we expect that # window to be present in the default (src) layout. -foreach spec {{src true} {cmd true} {status true} {regs false} {asm false}} { +foreach spec {{src true} {cmd true} {status true} {regs false} \ + {asm false} {unknown false}} { lassign $spec window valid_p with_test_prefix "window=$window" { @@ -54,8 +55,13 @@ foreach spec {{src true} {cmd true} {status true} {regs false} {asm false}} { "^Focus set to $window window\\.\\s*" } } else { - Term::check_region_contents "check focus error" 0 16 80 1 \ - "^Unrecognized window name \"$window\"\\s*" + if {$window == "unknown"} { + Term::check_region_contents "check focus error" 0 16 80 1 \ + "^Unrecognized window name \"$window\"\\s*" + } else { + Term::check_region_contents "check focus error" 0 16 80 1 \ + "^Window \"$window\" is not in the current layout\\s*" + } } Term::check_box "check src box" 0 0 80 15 @@ -66,3 +72,72 @@ foreach spec {{src true} {cmd true} {status true} {regs false} {asm false}} { Term::command "focus prev" } } + +# Use the Python TUI API to exercise some of the ambigous window name +# handling parts of the 'focus' command. +Term::clean_restart 24 80 $binfile +if {[allow_python_tests]} { + # Create a very simple tui window. + gdb_py_test_silent_cmd \ + [multi_line_input \ + "python" \ + "class TestWindow:" \ + " def __init__(self, win):" \ + " pass" \ + "" \ + " def render(self):" \ + " pass" \ + "end"] \ + "setup dummy window class" \ + true + + # Register the window with a set of similar names. + gdb_test_no_output "python gdb.register_window_type(\"test1\", TestWindow)" + gdb_test_no_output "python gdb.register_window_type(\"test2\", TestWindow)" + gdb_test_no_output "python gdb.register_window_type(\"test3\", TestWindow)" + + # Create a layout containing just one of the above windows. + gdb_test_no_output "tui new-layout example1 test2 1 status 1 cmd 1" + + # Create a layout containing two of the above windows. + gdb_test_no_output "tui new-layout example2 test1 1 test2 1 status 1 cmd 1" + + if {![Term::prepare_for_tui]} { + unsupported "TUI not supported" + return + } + + # Try to focus using an ambiguous, partial window name. This + # should fail as the default layout (src) doesn't include any + # windows matching this name. + Term::command_no_prompt_prefix "focus test" + Term::check_region_contents "check no matching window focus message" \ + 0 16 80 1 \ + "^No windows matching \"test\" in the current layout\\s*" + + # Now select a layout that includes a single window that matches + # the ambiguous, partial name 'test', and disable tui mode. + Term::command "layout example1" + send_gdb "tui disable\n" + + # Reactivate tui mode and try to set focus using the ambiguous, + # partial window name. This should succeed though, as, within the + # current layout, the partial name is not actually ambiguous. + send_gdb "focus test\n" + gdb_assert [Term::wait_for_region_contents 0 19 80 1 \ + "^Focus set to test2 window\\.\\s*"] \ + "check test2 focus message" + + # Now select a layout that includes two windows that matches the + # ambiguous, partial name 'test', and disable tui mode. + Term::command "layout example2" + send_gdb "tui disable\n" + + # Reactivate tui mode and try to set focus using the ambiguous, + # partial window name. This will fail as now the layout includes + # multiple windows that match 'test'. + send_gdb "focus test\n" + gdb_assert [Term::wait_for_region_contents 0 22 80 1 \ + "^Window name \"test\" is ambiguous\\s*"] \ + "check ambiguous focus message" +} diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index 27abee02087..ecdcd4884a7 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -29,7 +29,6 @@ #include "cli/cli-decode.h" #include "cli/cli-utils.h" #include -#include #include #include "tui/tui.h" @@ -351,7 +350,17 @@ make_standard_window (const char *) shut down, causing crashes if any window destruction requires running Python code. */ -static std::unordered_map *known_window_types; +static window_types_map *known_window_types; + +/* See tui-layout.h. */ + +known_window_names_range +all_known_window_names () +{ + auto begin = known_window_names_iterator (known_window_types->begin ()); + auto end = known_window_names_iterator (known_window_types->end ()); + return known_window_names_range (begin, end); +} /* Helper function that returns a TUI window, given its name. */ @@ -377,7 +386,7 @@ tui_get_window_by_name (const std::string &name) static void initialize_known_windows () { - known_window_types = new std::unordered_map; + known_window_types = new window_types_map; known_window_types->emplace (SRC_NAME, make_standard_window /* Values that can be returned when handling a request to adjust a window's size. */ @@ -358,10 +361,56 @@ extern void tui_adjust_window_width (struct tui_win_info *win, typedef std::function window_factory; +/* The type for a data structure that maps a window name to that window's + factory function. */ +typedef std::unordered_map window_types_map; + /* Register a new TUI window type. NAME is the name of the window type. FACTORY is a function that can be called to instantiate the window. */ extern void tui_register_window (const char *name, window_factory &&factory); +/* An iterator class that exposes just the window names from the + known_window_types map in tui-layout.c. This is just a wrapper around + an iterator of the underlying known_window_types map, but this just + exposes the window names. */ + +struct known_window_names_iterator +{ + using known_window_types_iterator = window_types_map::iterator; + + known_window_names_iterator (known_window_types_iterator &&iter) + : m_iter (std::move (iter)) + { /* Nothing. */ } + + known_window_names_iterator &operator++ () + { + ++m_iter; + return *this; + } + + const std::string &operator* () const + { return (*m_iter).first; } + + bool operator!= (const known_window_names_iterator &other) const + { return m_iter != other.m_iter; } + +private: + + /* The underlying iterator. */ + known_window_types_iterator m_iter; +}; + +/* A range adapter that makes it possible to iterate over the names of all + known tui windows. */ + +using known_window_names_range + = iterator_range; + +/* Return a range that can be used to walk over the name of all known tui + windows in a range-for loop. */ + +extern known_window_names_range all_known_window_names (); + #endif /* TUI_TUI_LAYOUT_H */ diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c index 492a5191025..008189eb99b 100644 --- a/gdb/tui/tui-win.c +++ b/gdb/tui/tui-win.c @@ -728,8 +728,44 @@ tui_set_focus_command (const char *arg, int from_tty) else win_info = tui_partial_win_by_name (arg); - if (win_info == NULL) - error (_("Unrecognized window name \"%s\""), arg); + if (win_info == nullptr) + { + /* When WIN_INFO is nullptr this can either mean that the window name + is unknown to GDB, or that the window is not in the current + layout. To try and help the user, give a different error + depending on which of these is the case. */ + std::string matching_window_name; + bool is_ambiguous = false; + + for (const std::string &name : all_known_window_names ()) + { + /* Look through all windows in the current layout, if the window + is in the current layout then we're not interested is it. */ + for (tui_win_info *item : all_tui_windows ()) + if (item->name () == name) + continue; + + if (startswith (name, arg)) + { + if (matching_window_name.empty ()) + matching_window_name = name; + else + is_ambiguous = true; + } + }; + + if (!matching_window_name.empty ()) + { + if (is_ambiguous) + error (_("No windows matching \"%s\" in the current layout"), + arg); + else + error (_("Window \"%s\" is not in the current layout"), + matching_window_name.c_str ()); + } + else + error (_("Unrecognized window name \"%s\""), arg); + } /* If a window is part of the current layout then it will have a tui_win_info associated with it and be visible, otherwise, there will From patchwork Wed Jan 25 12:08:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 63665 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7878F38493DD for ; Wed, 25 Jan 2023 12:10:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7878F38493DD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674648605; bh=UPAOAdFHm+AXrmVqmMPZUmUvSH3YbNaw976fSd1EBnA=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ise63oqAw2957B6CEZl9vBY2V1xtDeR9YLx/Bibr3H16vrAmrOzwwyqjnj+LjFhzh tyXnYCYkt8xdE8sPlx0R8SlRXr61JFkBIYFrmRIIMoZ6SSPccgDv2vWI3FlnOdXrSM UYILsPi75RvrngGINp9ZMmIw+8jUQmzywa7wWeIU= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 3899E3858C2C for ; Wed, 25 Jan 2023 12:09:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3899E3858C2C Received: from mail-yw1-f197.google.com (mail-yw1-f197.google.com [209.85.128.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-662-SFwMv6dHP2WuGTxhWR7tkA-1; Wed, 25 Jan 2023 07:09:02 -0500 X-MC-Unique: SFwMv6dHP2WuGTxhWR7tkA-1 Received: by mail-yw1-f197.google.com with SMTP id 00721157ae682-4ff7c6679f2so152125757b3.12 for ; Wed, 25 Jan 2023 04:09:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UPAOAdFHm+AXrmVqmMPZUmUvSH3YbNaw976fSd1EBnA=; b=YqF9l+zYhoP989H6A8y53myLh7JEX9tpgbhTfopyqkyZ7FxdT5r9RdxvGAcmUKiKVK X/48u9iTR/bbr7iQ0Wb/PQBKAK/rIn7nQSSOs8f6jja9hZRAkx55sSlKoLoA3E43i1CA xgLta2W1vgQW4WIKGh9vkXji7XGjzOwWHlpNPjR0R6/h40c9GFczJ9Gr/UNGWG4lQ0KM RCZsl25x5p6L8T4t9tfnoOxDeKjQcQBezZiwySplAtZnNtrJTOo37BlENLUAiolb0oaj nx/yS58q14nhdy8fBpY+X6xO8QVLSrp+Y0ABy7ECE9YD890bU6FCEgplRnu7xFLdef+A ps1g== X-Gm-Message-State: AO0yUKVddJrD590GDf3sg2K0BkFExNIurlQUdPSTMUnAjkAviMw5OCAN pOAlCPi85IJKoAptrP2tBf7kMIocZUvj3npj23vK5FWbEvv3LefgGVyPXjTJ/M3CTrH69DPB2ts 93nTALQj/HX95a49VqaDi2Oi7xebzRWMEipODK9ptzUTab/y0YS0I14/S3qUR6MG5A/LVr199Lg == X-Received: by 2002:a81:948:0:b0:506:3c33:3335 with SMTP id 69-20020a810948000000b005063c333335mr3865839ywj.11.1674648541528; Wed, 25 Jan 2023 04:09:01 -0800 (PST) X-Google-Smtp-Source: AK7set/u+SL7HJKPwJSOEgeCoVNJuBVXor4a/9EJwiyeZ+4qaNOTdGN7U5DQ3ksh6xHoxzVe2JkkVg== X-Received: by 2002:a81:948:0:b0:506:3c33:3335 with SMTP id 69-20020a810948000000b005063c333335mr3865823ywj.11.1674648541164; Wed, 25 Jan 2023 04:09:01 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id m18-20020ae9e012000000b00704c9015e68sm3308471qkk.116.2023.01.25.04.09.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 04:09:00 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 3/8] gdb/tui: disable tui mode when an assert triggers Date: Wed, 25 Jan 2023 12:08:43 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" When an assert triggers in tui mode the output is not great, the internal backtrace that is generated is printed directly to the file descriptor for gdb_stderr, and, as a result, does not currently format itself correctly - the output uses only '\n' at the end of each line, and so, when the terminal is in raw mode, the cursor does not return to the start of each line after the '\n'. This is mostly fixable, we could update bt-utils.c to use '\r\n' instead of just '\n', and this would fix most of the problems. The one we can't easily fix is if/when GDB is built to use execinfo instead of libbacktrace, in this case we use backtrace_symbols_fd to print the symbols, and this function only uses '\n' as the line terminator. Fixing this would require switching to backtrace_symbols, but that API uses malloc, which is something we're trying to avoid (this code is called when GDB hits an error, so ideally we don't want to rely on malloc). However, the execinfo code is only used when libbacktrace is not available (or the user specifically disables libbacktrace) so maybe we can ignore that problem... ... but there is another problem. When the backtrace is printed in raw mode, it is possible that the backtrace fills the screen. With the terminal in raw mode we don't have the ability to scroll back, which means we loose some of the backtrace, which isn't ideal. In this commit I propose that we should disable tui mode whenever we handle a fatal signal, or when we hit the internal error code path (e.g. when an assert triggers). With this done then we don't need to update the bt-utils.c code, and the execinfo version of the code (using backtrace_symbols_fd) works just fine. We also get the ability to scroll back to view the error message and all of the backtrace, assuming the users terminal supports scrolling back. The only downside I see with this change is if the tui_disable call itself causes an error for some reason, or, if we handle a single at a time when it is not safe to call tui_disable, in these cases the extra tui_disable call might cause GDB to loose the original error. However, I think (just from personal experience) that the above two issues are pretty rare and the benefits from this change far out weighs the possible drawbacks. --- gdb/event-top.c | 8 ++++++++ gdb/utils.c | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index 4a46e1b9346..14984707df1 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -48,6 +48,10 @@ #include "readline/readline.h" #include "readline/history.h" +#ifdef TUI +#include "tui/tui.h" +#endif + /* readline defines this. */ #undef savestring @@ -940,6 +944,10 @@ unblock_signal (int sig) static void ATTRIBUTE_NORETURN handle_fatal_signal (int sig) { +#ifdef TUI + tui_disable (); +#endif + #ifdef GDB_PRINT_INTERNAL_BACKTRACE const auto sig_write = [] (const char *msg) -> void { diff --git a/gdb/utils.c b/gdb/utils.c index 734c5bf7f70..95adbe58e4a 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -29,7 +29,8 @@ #endif /* HAVE_SYS_RESOURCE_H */ #ifdef TUI -#include "tui/tui.h" /* For tui_get_command_dimension. */ +/* For tui_get_command_dimension and tui_disable. */ +#include "tui/tui.h" #endif #ifdef __GO32__ @@ -354,6 +355,10 @@ internal_vproblem (struct internal_problem *problem, } } +#ifdef TUI + tui_disable (); +#endif + /* Create a string containing the full error/warning message. Need to call query with this full string, as otherwize the reason (error/warning) and question become separated. Format using a From patchwork Wed Jan 25 12:08:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 63663 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AB43D385781A for ; Wed, 25 Jan 2023 12:09:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB43D385781A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674648582; bh=jcdgqCCodrkrGvXu/A1dTmdurdyIuJ6uFOGqjP8e6Zc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=aNP/Wp/fnqfN+CEbJN8hv+/xRxaG0d4mZQkwIoeJQemFWY9X5O/qZOUXaZIA/UGQg ab5et9LTlOXL30IX6O9k57vCO7sw/sNxKzgF7nCksOWWBUVToEtpGn6N2mvrw5/p/6 5P+vQL5unb4iku9XlIl8+4e+n5zXe5Y0Kzr1vVQU= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id E2E343858C62 for ; Wed, 25 Jan 2023 12:09:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E2E343858C62 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-205-XbBcfmC9MEGuaSwBHJimnA-1; Wed, 25 Jan 2023 07:09:05 -0500 X-MC-Unique: XbBcfmC9MEGuaSwBHJimnA-1 Received: by mail-qt1-f200.google.com with SMTP id o16-20020ac841d0000000b003b689580725so7534898qtm.22 for ; Wed, 25 Jan 2023 04:09:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jcdgqCCodrkrGvXu/A1dTmdurdyIuJ6uFOGqjP8e6Zc=; b=PA4gwiee+D2z+W8uhg1WjRK/GcnIoWl4Xnob0dtXXrAAt4V96xCdkWLwBl2tQesob9 rBsWcbeE8ktcuFq/Zku5ndGAtlUg8X4bhuE3l9gnNxWIQ8sIMl0GtIz6wmWpluKcadnJ fx6RcLln8hA+ScywUZcmBTrCAoohNCmCS8XpBDqXU9Ul2oEhijLFb3sMSCmLJcFkTzmw fCOYYX98eB6VXHQ3OQqX0oNGtXRe2VpvhfwWVz522IkIA45940L1OfIidV+ToqAoBBaq X9Hr9REaJfpeRZiEuTEcxa2uqUBhNbOq5IqQOwMoZ9dSud1uZXb2Tx+Ki7WyndDTJ03q E7sw== X-Gm-Message-State: AFqh2kqdgYSru6+6ciiuYJhb3pDt1iI0fMWLCZGr/lLzOMs0UoHxFTcN 3XmN+nP7WspCyS2z5LdEFAYxAC83hu1VY/j0jR/B0BqP1Z/hPsCcFb4XWN250gOBZtEHViF2bl5 YyCIWx4KJqilPxgJwmZC1A63FNcrg92Jnxweq23iXcmcqFkaqz2KyFc+B2hMeZLQikGDaKVeGPA == X-Received: by 2002:ac8:425a:0:b0:3b6:43ae:d5a3 with SMTP id r26-20020ac8425a000000b003b643aed5a3mr37553102qtm.26.1674648543582; Wed, 25 Jan 2023 04:09:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXtmwy7U1yaYsViByRt39Lcr5LQ7U6jN8TClY7YQg3wVp+m3Y0mcaRQcyjnsL9pfJa1/AY0J9w== X-Received: by 2002:ac8:425a:0:b0:3b6:43ae:d5a3 with SMTP id r26-20020ac8425a000000b003b643aed5a3mr37553079qtm.26.1674648543291; Wed, 25 Jan 2023 04:09:03 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id x25-20020ac84d59000000b003b5bc7a4512sm3195279qtv.26.2023.01.25.04.09.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 04:09:03 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 4/8] gdb/tui: make m_horizontal_offset private Date: Wed, 25 Jan 2023 12:08:44 +0000 Message-Id: <083a8c7747c5d75c31eb95011b113517d1974b92.1674648473.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I noticed that tui_source_window_base::m_horizontal_offset was protected, but could be made private, so lets do that. This makes more sense in the context of a later commit where I plan to add another member variable that is similar to m_horizontal_offset. The new member variable could also be private. So I had to choose, place the new member variable next to m_horizontal_offset making it protected, but grouping similar variables together, or make m_horizontal_offset private, and then add the new variable as private too. I chose to make m_horizontal_offset private, which is this commit. There should be no user visible changes after this commit. --- gdb/tui/tui-winsource.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h index 7d6d64d35c4..bf0ca96c09b 100644 --- a/gdb/tui/tui-winsource.h +++ b/gdb/tui/tui-winsource.h @@ -124,8 +124,7 @@ struct tui_source_window_base : public tui_win_info /* Redraw the complete line of a source or disassembly window. */ void show_source_line (int lineno); - /* Used for horizontal scroll. */ - int m_horizontal_offset = 0; + /* Where to start generating content from. */ struct tui_line_or_address m_start_line_or_addr; /* Architecture associated with code at this location. */ @@ -179,6 +178,9 @@ struct tui_source_window_base : public tui_win_info private: + /* Used for horizontal scroll. */ + int m_horizontal_offset = 0; + void show_source_content (); /* Called when the user "set style enabled" setting is changed. */ From patchwork Wed Jan 25 12:08:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 63664 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 67471385B515 for ; Wed, 25 Jan 2023 12:09:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 67471385B515 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674648597; bh=kpfGUmwE4MRLMmzMrfUfOTnywGB7zVeXFkw5Kbg9xfQ=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=eUHy3g31QVBzNDwss+uKqinabQ6mumUBBOebrvw7eNoyUpjuplT8dItwF22+Fjgs9 Bt8s0FZCoBbH3anREZnfJFcs+znQf2syBtqSsDzkSmGoo2khPIOMe7vyReMBjyzNmp 6PsXsAt5jO3RupROvw64RRJJSRkk90EYXXevWjxs= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 2612E3858408 for ; Wed, 25 Jan 2023 12:09:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2612E3858408 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-517-O_uBQfsXMkSemdJ3ALqfww-1; Wed, 25 Jan 2023 07:09:06 -0500 X-MC-Unique: O_uBQfsXMkSemdJ3ALqfww-1 Received: by mail-qt1-f197.google.com with SMTP id bs22-20020ac86f16000000b003b686e0ef0bso7473285qtb.19 for ; Wed, 25 Jan 2023 04:09:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kpfGUmwE4MRLMmzMrfUfOTnywGB7zVeXFkw5Kbg9xfQ=; b=tChrD3jpb/iIYahYlJoD2UDc15lgMyRdEgspoXmCnJ9/XZ4/qUCG9hOyvnx83w3tRE sh5PO8O+7wKwC7nXfepqIBsPDtctplAX5BKIPG8/16CLHkQsJmP2zmwfb1RzDVMHr6Zq AJtEtLwVMzUSNVIKGZOQMA48sPK58fFpzeVNJOMQYRLuNOrXgHxL5in3FP4SFJgkP0GS p0PC/b+pai71X8VjwEVyAE6BjmZ8E87oY37bXWX98hl8TYVY4NsKx/vbjL7msTLmJK11 oubGV9pET7Ay8CurMVavR4ixPqkt/cuGBPRwIkjr0TX5DsZci2fVP4FZDxpNeLhe6nv0 w0bw== X-Gm-Message-State: AO0yUKXDuFAagsvmmBNocman7TNFqtHXqITh0OeZhReUt++lRad/RDBj Z5qpXdRyGMuZm+uoq/fVaSVuRBLmbhENB0Gt5CbkpSS0kG/AEGibN+9xlTksHSwoEfl57iQalPf x0brUx6ebFTsyLOuZT8lhLB1YKPtWdWBJh++Nxs4nbd9NbrfNtXoERjjeyuQELCXETNDkV1lUuA == X-Received: by 2002:ac8:5c91:0:b0:3b6:9737:27d8 with SMTP id r17-20020ac85c91000000b003b6973727d8mr3946671qta.28.1674648545991; Wed, 25 Jan 2023 04:09:05 -0800 (PST) X-Google-Smtp-Source: AK7set/u5asI3tTXlpxyTYzpS40Vq20rBRs89qMstO4LU8iyh4qzkcrJhVZJLtZXLE246mQRjhFx9g== X-Received: by 2002:ac8:5c91:0:b0:3b6:9737:27d8 with SMTP id r17-20020ac85c91000000b003b6973727d8mr3946597qta.28.1674648545376; Wed, 25 Jan 2023 04:09:05 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id z18-20020ac86b92000000b003a7eb5baf3csm3144296qts.69.2023.01.25.04.09.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 04:09:05 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 5/8] gdb/tui: rewrite of tui_source_window_base to handle very long lines Date: Wed, 25 Jan 2023 12:08:45 +0000 Message-Id: <86375070d02953136b7be1bdbf6ce3c02d4138ab.1674648473.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This commit addresses an issue that is exposed by the test script gdb.tui/tui-disasm-long-lines.exp, that is, tui_source_window_base does not handle very long lines. The problem can be traced back to the newpad call in tui_source_window_base::show_source_content, this is where we allocate a backing pad to hold the window content. Unfortunately, there appears to be a limit to the size of pad that can be allocated, and the gdb.tui/tui-disasm-long-lines.exp test goes beyond this limit. As a consequence the newpad call fails and returns nullptr. It just so happens that the reset of the tui_source_window_base code can handle the pad being nullptr (this happens anyway when the window is first created, so we already depend on nullptr handling), so all that happens is the source window displays no content. ... well, sort of ... something weird does happen in the command window, we seem to see a whole bunch of blank lines. I've not bothered to track down exactly what's happening there, but it's some consequence of GDB attempting to write content to a WINDOW* that is nullptr. Before explaining my solution, I'll outline how things currently work: Consider we have the following window content to display: aaaaaaaaaa bbbbbbbbbbbbbbbbbbbb ccccccccccccccc the longest line here is 20 characters. If our display window is 10 characters wide, then we will create a pad that is 20 characters wide, and then copy the lines of content into the pad: .--------------------. |aaaaaaaaaa | |bbbbbbbbbbbbbbbbbbbb| |ccccccccccccccc | .--------------------. Now we will copy a 10 character wide view into this pad to the display, our display will then see: .----------. |aaaaaaaaaa| |bbbbbbbbbb| |cccccccccc| .----------. As the user scrolls left and right we adjust m_horizontal_offset and use this to select which part of the pad is copied onto the display. The benefit of this is that we only need to copy the content to the pad once, which includes processing the ansi escape sequences, and then the user can scroll left and right as much as they want relatively cheaply. The problem then, is that if the longest content line is very long, then we try to allocate a very large pad, which can fail. What I propose is that we allow both the pad and the display view to scroll. Once we allow this, then it becomes possible to allocate a pad that is smaller than the longest display line. We then copy part of the content into the pad. As the user scrolls the view left and right GDB will continue to copy content from the pad just as it does right now. But, when the user scrolls to the edge of the pad, GDB will copy a new block of content into the pad, and then update the view as normal. This all works fine so long as the maximum pad size is larger than the current window size - which seems a reasonable restriction, if ncurses can't support a pad of a given size it seems likely it will not support a display window of that size either. If we return to our example above, but this time we assume that the maximum pad size is 15 characters, then initially the pad would be loaded like this: .---------------. |aaaaaaaaaa | |bbbbbbbbbbbbbbb| |ccccccccccccccc| .---------------. Notice that the last 5 characters from the 'b' line are no longer included in the pad. There is still enough content though to fill the 10 character wide display, just as we did before. The pad contents remain unchanged until the user scrolls the display right to this point: .----------. |aaaaa | |bbbbbbbbbb| |cccccccccc| .----------. Now, when the user scrolls right once more GDB spots that the user has reached the end of the pad, and the pad contents are reloaded, like this: .---------------. |aaaaa | |bbbbbbbbbbbbbbb| |cccccccccc | .---------------. The display can now be updated from the pad again just like normal. With this change in place the gdb.tui/tui-disasm-long-lines.exp test now correctly loads the assembler code, and we can scroll around as expected. Most of the changes are pretty mundane, just updating to match the above. One interesting change though is the new member function tui_source_window_base::puts_to_pad_with_skip. This replaces direct calls to tui_puts when copying content to the pad. The content strings contain ansi escape sequences. When these strings are written to the pad these escape sequences are translated into ncurses attribute setting calls. Now however, we sometimes only write a partial string to the pad, skipping some of the leading content. Imagine then that we have a content line like this: "\033[31mABCDEFGHIJKLM\033[0m" Now the escape sequences in this content mean that the actual content (the 'ABCDEFGHIJKLM') will have a red foreground color. If we want to copy this to the pad, but skip the first 3 characters, then what we expect is to have the pad contain 'DEFGHIJKLM', but this text should still have a red foreground color. It is this problem that puts_to_pad_with_skip solves. This function skips some number of printable characters, but processes all the escape sequences. This means that when we do start printing the actual content the content will have the expected attributes. / --- .../gdb.tui/tui-disasm-long-lines.exp | 6 +- gdb/tui/tui-winsource.c | 177 ++++++++++++++++-- gdb/tui/tui-winsource.h | 54 +++++- 3 files changed, 215 insertions(+), 22 deletions(-) diff --git a/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp b/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp index ae19f2e69cb..5d395cd604b 100644 --- a/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp +++ b/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp @@ -41,10 +41,6 @@ if {![Term::prepare_for_tui]} { return } -# Just check the command does not cause gdb to crash. It is worth -# noting that the asm window does infact fail to correctly display the -# disassembler output at this point, but initially we are just -# checking that GDB doesn't crash, fixing the asm display will come -# later. Term::command_no_prompt_prefix "layout asm" Term::check_box "asm box" 0 0 80 15 +Term::check_box_contents "check asm box contents" 0 0 80 15 "
" diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 87099ac26f5..6e22638ec74 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -170,6 +170,7 @@ tui_source_window_base::update_source_window_as_is erase_source_content (); else { + validate_scroll_offsets (); update_breakpoint_info (nullptr, false); show_source_content (); update_exec_info (); @@ -231,6 +232,67 @@ tui_source_window_base::do_erase_source_content (const char *str) } } +/* See tui-winsource.h. */ + +void +tui_source_window_base::puts_to_pad_with_skip (const char *string, int skip) +{ + gdb_assert (m_pad.get () != nullptr); + WINDOW *w = m_pad.get (); + + while (skip > 0) + { + const char *next = strpbrk (string, "\033"); + + /* Print the plain text prefix. */ + size_t n_chars = next == nullptr ? strlen (string) : next - string; + if (n_chars > 0) + { + if (skip > 0) + { + if (skip < n_chars) + { + string += skip; + n_chars -= skip; + skip = 0; + } + else + { + skip -= n_chars; + string += n_chars; + n_chars = 0; + } + } + + if (n_chars > 0) + { + std::string copy (string, n_chars); + tui_puts (copy.c_str (), w); + } + } + + /* We finished. */ + if (next == nullptr) + break; + + gdb_assert (*next == '\033'); + + int n_read; + if (skip_ansi_escape (next, &n_read)) + { + std::string copy (next, n_read); + tui_puts (copy.c_str (), w); + next += n_read; + } + else + gdb_assert_not_reached ("unhandled escape"); + + string = next; + } + + if (*string != '\0') + tui_puts (string, w); +} /* Redraw the complete line of a source or disassembly window. */ void @@ -243,7 +305,8 @@ tui_source_window_base::show_source_line (int lineno) tui_set_reverse_mode (m_pad.get (), true); wmove (m_pad.get (), lineno, 0); - tui_puts (line->line.c_str (), m_pad.get ()); + puts_to_pad_with_skip (line->line.c_str (), m_pad_offset); + if (line->is_exec_point) tui_set_reverse_mode (m_pad.get (), false); } @@ -257,13 +320,25 @@ tui_source_window_base::refresh_window () the screen, potentially creating a flicker. */ wnoutrefresh (handle.get ()); - int pad_width = std::max (m_max_length, width); - int left_margin = 1 + TUI_EXECINFO_SIZE + extra_margin (); - int view_width = width - left_margin - 1; - int pad_x = std::min (pad_width - view_width, m_horizontal_offset); - /* Ensure that an equal number of scrolls will work if the user - scrolled beyond where we clip. */ - m_horizontal_offset = pad_x; + int pad_width = getmaxx (m_pad.get ()); + int left_margin = this->left_margin (); + int view_width = this->view_width (); + int content_width = m_max_length; + int pad_x = m_horizontal_offset - m_pad_offset; + + gdb_assert (m_pad_offset >= 0); + gdb_assert (m_horizontal_offset + view_width + <= std::max (content_width, view_width)); + gdb_assert (pad_x >= 0); + gdb_assert (m_horizontal_offset >= 0); + + /* This function can be called before the pad has been allocated, this + should only occur during the initial startup. In this case the first + condition in the following asserts will not be true, but the nullptr + check will. */ + gdb_assert (pad_width > 0 || m_pad.get () == nullptr); + gdb_assert (pad_x + view_width <= pad_width || m_pad.get () == nullptr); + prefresh (m_pad.get (), 0, pad_x, y + 1, x + left_margin, y + m_content.size (), x + left_margin + view_width - 1); } @@ -275,11 +350,51 @@ tui_source_window_base::show_source_content () check_and_display_highlight_if_needed (); - int pad_width = std::max (m_max_length, width); - if (m_pad == nullptr || pad_width > getmaxx (m_pad.get ()) - || m_content.size () > getmaxy (m_pad.get ())) - m_pad.reset (newpad (m_content.size (), pad_width)); + /* The pad should be at least as wide as the window, but ideally, as wide + as the content, however, for some very wide content this might not be + possible. */ + int required_pad_width = std::max (m_max_length, width); + int required_pad_height = m_content.size (); + + /* If the required pad width is wider than the previously requested pad + width, then we might want to grow the pad. */ + if (required_pad_width > m_pad_requested_width + || required_pad_height > getmaxy (m_pad.get ())) + { + /* The current pad width. */ + int pad_width = m_pad == nullptr ? 0 : getmaxx (m_pad.get ()); + + gdb_assert (pad_width <= m_pad_requested_width); + + /* If the current pad width is smaller than the previously requested + pad width, then this means we previously failed to allocate a + bigger pad. There's no point asking again, so we'll just make so + with the pad we currently have. */ + if (pad_width == m_pad_requested_width + || required_pad_height > getmaxy (m_pad.get ())) + { + pad_width = required_pad_width; + + do + { + /* Try to allocate a new pad. */ + m_pad.reset (newpad (required_pad_height, pad_width)); + + if (m_pad == nullptr) + { + int reduced_width = std::max (pad_width / 2, width); + if (reduced_width == pad_width) + error (_("failed to setup source window")); + pad_width = reduced_width; + } + } + while (m_pad == nullptr); + } + + m_pad_requested_width = required_pad_width; + } + gdb_assert (m_pad != nullptr); werase (m_pad.get ()); for (int lineno = 0; lineno < m_content.size (); lineno++) show_source_line (lineno); @@ -370,6 +485,35 @@ tui_source_window_base::refill () update_source_window_as_is (m_gdbarch, sal); } +/* See tui-winsource.h. */ + +bool +tui_source_window_base::validate_scroll_offsets () +{ + int original_pad_offset = m_pad_offset; + + if (m_horizontal_offset < 0) + m_horizontal_offset = 0; + + int content_width = m_max_length; + int pad_width = getmaxx (m_pad.get ()); + int view_width = this->view_width (); + + if (m_horizontal_offset + view_width > content_width) + m_horizontal_offset = std::max (content_width - view_width, 0); + + if ((m_horizontal_offset + view_width) > (m_pad_offset + pad_width)) + { + m_pad_offset = std::min (m_horizontal_offset, content_width - pad_width); + m_pad_offset = std::max (m_pad_offset, 0); + } + else if (m_horizontal_offset < m_pad_offset) + m_pad_offset = std::max (m_horizontal_offset + view_width - pad_width, 0); + + gdb_assert (m_pad_offset >= 0); + return (original_pad_offset != m_pad_offset); +} + /* Scroll the source forward or backward horizontally. */ void @@ -377,10 +521,11 @@ tui_source_window_base::do_scroll_horizontal (int num_to_scroll) { if (!m_content.empty ()) { - int offset = m_horizontal_offset + num_to_scroll; - if (offset < 0) - offset = 0; - m_horizontal_offset = offset; + m_horizontal_offset += num_to_scroll; + + if (validate_scroll_offsets ()) + show_source_content (); + refresh_window (); } } diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h index bf0ca96c09b..2762afff010 100644 --- a/gdb/tui/tui-winsource.h +++ b/gdb/tui/tui-winsource.h @@ -181,16 +181,68 @@ struct tui_source_window_base : public tui_win_info /* Used for horizontal scroll. */ int m_horizontal_offset = 0; + /* Check that the current values of M_HORIZONTAL_OFFSET and M_PAD_OFFSET + make sense given the current M_MAX_LENGTH (content width), WIDTH + (window size), and window margins. After calling this function + M_HORIZONTAL_OFFSET and M_PAD_OFFSET might have been adjusted to + reduce unnecessary whitespace on the right side of the window. + + If M_PAD_OFFSET is adjusted then this function returns true + indicating that the pad contents need to be reloaded by calling + show_source_content. If M_PAD_OFFSET is not adjusted then this + function returns false, the window contents might still need + redrawing if M_HORIZONTAL_OFFSET was adjusted, but right now, this + function is only called in contexts where the window is going to be + redrawn anyway. */ + bool validate_scroll_offsets (); + + /* Return the size of the left margin space, this is the space used to + display things like breakpoint markers. */ + int left_margin () const + { return 1 + TUI_EXECINFO_SIZE + extra_margin (); } + + /* Return the width of the area that is available for window content. + This is the window width minus the borders and the left margin, which + is used for displaying things like breakpoint markers. */ + int view_width () const + { return width - left_margin () - 1; } + void show_source_content (); + /* Write STRING to the window M_PAD, but skip the first SKIP printable + characters. Any escape sequences within the first SKIP characters are + still processed though. This means if we have this string: + + "\033[31mABCDEFGHIJKLM\033[0m" + + and call this function with a skip value of 3, then we effectively + write this string to M_PAD: + + "\033[31mDEFGHIJKLM\033[0m" + + the initial escape that sets the color will still be applied. */ + void puts_to_pad_with_skip (const char *string, int skip); + /* Called when the user "set style enabled" setting is changed. */ void style_changed (); /* A token used to register and unregister an observer. */ gdb::observers::token m_observable; - /* Pad used to display fixme mumble */ + /* Pad to hold some, or all, of the window contents. Content is then + copied from this pad to the screen as the user scrolls horizontally, + this avoids the need to recalculate the screen contents each time the + user does a horizontal scroll. */ std::unique_ptr m_pad; + + /* When M_PAD was allocated, this holds the width that was initially + asked for. If we ask for a very large pad then the allocation may + fail, and we might instead allocate a narrower pad. */ + int m_pad_requested_width = 0; + + /* If M_PAD is not as wide as the content (so less than M_MAX_LENGTH) + then this value indicates the offset at which the pad contents begin. */ + int m_pad_offset = 0; }; From patchwork Wed Jan 25 12:08:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 63667 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ED7CB3857838 for ; Wed, 25 Jan 2023 12:10:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED7CB3857838 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674648626; bh=kN+TGSrhUsQB6Jmk1CbxK2TEbZTQtMX16sxb/eKGfhc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=lfayHeapw0vzuUCaLQlOQ9mpBmJ2hk7vz6KIA2qL9bt20VlRIawLn9vTe25RhVKFg Dp7G/MXvTEGVklcz1vvsa6kO9KPjOiSCSGFYGXEu3k0RAojaqlEIxOfd38XaXpJS2/ /v34rxoisRnZ8S7V9oqfDq6zXpwP50M/8ZeSiDwk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id B992C3858020 for ; Wed, 25 Jan 2023 12:09:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B992C3858020 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-308-BqgU5x3ZNH6zGFE0GHcURA-1; Wed, 25 Jan 2023 07:09:08 -0500 X-MC-Unique: BqgU5x3ZNH6zGFE0GHcURA-1 Received: by mail-qk1-f197.google.com with SMTP id a3-20020a05620a438300b007069b068069so12705201qkp.2 for ; Wed, 25 Jan 2023 04:09:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kN+TGSrhUsQB6Jmk1CbxK2TEbZTQtMX16sxb/eKGfhc=; b=oiA8fJV7+S2FNpOV1nXMlehuuxhSYyZj+s516UFfaHV0ZWxvjRH77TBRSwLtguFgnU UmMLBCq4Q71whlTTbvthwOPuUa4rddGWooZ2lh+lDqdEUVg3/+5je16YEFXSPwmOvx8Z zF2bhkNHE8tS5PYmGMYjIHsHk9E81SZ0ZZHcJQrGXkdV7GOGp9JTz7IVJS5Zcz/jFeOY Q99WFWvQLKNlFswXZQHffUNcR7+RU3Xbi2jc/bSIuv7bpiu8a0IJXD587bMpt4V3YMS0 PNE393qHpjf3iMbQlxZUilTB35v69ZzOYlznSWr/amWNc7W+yXSHP9BskfqW/oNedpyw ZUzw== X-Gm-Message-State: AFqh2koC+P3sJTvCKB0p8QfpouxrdLmkkk5LSHZ+YkNawtiZ0KsF8odq NTzJZN9ol+wqldQlQ6qVUBiIdqrH4dXEUYVOc9DeSzN59hqn0UkzUcxmxs65uUG9msem0RbKfEH gA/rwdGdBL2bZK7/9jwjjBZTZ/EEQDRWvanB3vQmJxNciOpGUq122a0sjX3+eAc1FdJ+jtgCblQ == X-Received: by 2002:ac8:6659:0:b0:3b6:2c74:b67f with SMTP id j25-20020ac86659000000b003b62c74b67fmr37925290qtp.13.1674648547716; Wed, 25 Jan 2023 04:09:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXu9DzlUGsHT55qs3QTp1CefT+p4PDHoYXmpKwc/7IxL9OOl8ADWPiO5nrskYwPG0xxpjIKVdQ== X-Received: by 2002:ac8:6659:0:b0:3b6:2c74:b67f with SMTP id j25-20020ac86659000000b003b62c74b67fmr37925263qtp.13.1674648547376; Wed, 25 Jan 2023 04:09:07 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id l6-20020ac80786000000b003a530a32f67sm3107642qth.65.2023.01.25.04.09.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 04:09:07 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 6/8] gdb/tui: avoid extra refresh_window on horizontal scroll Date: Wed, 25 Jan 2023 12:08:46 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" While working on the previous patches I noticed that in some cases I was seeing two calls to tui_source_window_base::refresh_window when scrolling the window horizontally. The two calls would trigger in for the tui-disasm-long-lines.exp test when the pad needed to be refilled. The two called both come from tui_source_window_base::show_source_content. The first call is nested within check_and_display_highlight_if_needed, while the second call is done directly at the end of show_source_content. The check_and_display_highlight_if_needed is being used to draw the window box to the window, this is needed here because show_source_content is what gets called when the window needs updating, e.g. after a resize. We could potentially do the boxing in refresh_window, but then we'd be doing it each time we scroll, even though the box doesn't need changing in this case. However, we can move the check_and_display_highlight_if_needed to be the last thing done in show_source_content, this means that we can rely on the refresh_window call within it to be our single refresh call. There should be no user visible changes after this commit. --- gdb/tui/tui-winsource.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 6e22638ec74..50efa80576f 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -348,8 +348,6 @@ tui_source_window_base::show_source_content () { gdb_assert (!m_content.empty ()); - check_and_display_highlight_if_needed (); - /* The pad should be at least as wide as the window, but ideally, as wide as the content, however, for some very wide content this might not be possible. */ @@ -399,7 +397,11 @@ tui_source_window_base::show_source_content () for (int lineno = 0; lineno < m_content.size (); lineno++) show_source_line (lineno); - refresh_window (); + /* Calling check_and_display_highlight_if_needed will call refresh_window + (so long as the current window can be boxed), which will ensure that + the newly loaded window content is copied to the screen. */ + gdb_assert (can_box ()); + check_and_display_highlight_if_needed (); } tui_source_window_base::tui_source_window_base () From patchwork Wed Jan 25 12:08:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 63666 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E836F3858028 for ; Wed, 25 Jan 2023 12:10:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E836F3858028 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674648611; bh=LCbS/a6N3S8MjiAV8GUZ53xUs+FT/s2YaIKlZzSnhuw=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=rqJCwWKLK5ZdGBMcUrufIyBQg1y5da0IiYlAg0+OBcMFAicOt5y6S+qp3J1ol9GBn snXY62ocsF/a2s49yHbn4j22QNB0QDLCkPUfHx/dOrrUidFTTp7LED79JKSUstS/9r ortqBEj7FovPseANDou2g5dZDJEcrAmCESP5h7oA= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id CE026385842E for ; Wed, 25 Jan 2023 12:09:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CE026385842E Received: from mail-yw1-f197.google.com (mail-yw1-f197.google.com [209.85.128.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-450-_XtJcDtiPCamsOp5Xh_s2Q-1; Wed, 25 Jan 2023 07:09:10 -0500 X-MC-Unique: _XtJcDtiPCamsOp5Xh_s2Q-1 Received: by mail-yw1-f197.google.com with SMTP id 00721157ae682-5062f3a2977so70086557b3.21 for ; Wed, 25 Jan 2023 04:09:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LCbS/a6N3S8MjiAV8GUZ53xUs+FT/s2YaIKlZzSnhuw=; b=wpJpZORa7/y3H4839B9hSIxfy+szGOVF9vIXN2qCtWmZVAhHnsGaQ5jQKQ1jyJan90 AYmXATrKaDz6oO6e1LjhhVQtF6ZOIbR3y114mFDiAwLacesLziJdgN9iBypyHo1h8byg +bRx6lr77roqf7cmf5KCNOFOio8OTsaaBMdZMgcpX3tP+q8AGXs5toRazk+JHhHZnXhK fR8040rXhgcdR1x9rQijlk/UWiaOZ7OilEVCRf6VqVUZwGbCil8zk8auZ+QclqXB/Y/m v193gL/RV8YdsLwTnvZKIPKNgj847ViFkmDHKJlnUWuuxDtJRUctBkWpXbbWVJ4UpN1c PQSw== X-Gm-Message-State: AO0yUKXQYYft3ebOsjV7Ap6aoVxsqjsgzTKDnUNJWNmovCKc514DhVC/ eQq0E7veR4FncMle6+qoLoFTtCN72sRHUO9/QWki6zn1Eo1jakIIwpLRsBwppcUjzyBXQedNiPo 9QD6WXF7j/7T7TW19uXjtMULv6kmUABGAYsdT3vg0dLA/9lmWmoyLbMxuZ5hCygKIpMDsvG2yTQ == X-Received: by 2002:a05:690c:d20:b0:506:4342:1a2d with SMTP id cn32-20020a05690c0d2000b0050643421a2dmr3932873ywb.12.1674648549781; Wed, 25 Jan 2023 04:09:09 -0800 (PST) X-Google-Smtp-Source: AK7set+qwJSt6b8HH8XAtlnqohIZqiCj+5RxroiFAFlmKZWEgy9MMfJKdAxutrbu2xaiDe5GbBztLg== X-Received: by 2002:a05:690c:d20:b0:506:4342:1a2d with SMTP id cn32-20020a05690c0d2000b0050643421a2dmr3932854ywb.12.1674648549445; Wed, 25 Jan 2023 04:09:09 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id b5-20020a378005000000b00704a2a40cf2sm3343955qkd.38.2023.01.25.04.09.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 04:09:09 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 7/8] gdb/tui: avoid extra refresh_window on vertical scroll Date: Wed, 25 Jan 2023 12:08:47 +0000 Message-Id: <9ad682de863f902b18660243f5ab0e88c56b1c65.1674648473.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" While working on the previous couple of patches I noticed that when I scroll the src and asm windows vertically, I get two refresh_window calls. The two calls can be traced back to tui_source_window_base::update_source_window_as_is, in here we call show_source_content, which calls refresh_window, and then update_exec_info, which also calls refresh_window. In this commit I propose making the refresh_window call in update_exec_info optional. In update_source_window_as_is I'll then call update_exec_info before calling show_source_content, and pass a flag to update_exec_info to defer the refresh. There are places where update_exec_info is used without any subsequent refresh_window call (e.g. when a breakpoint is updated), so update_exec_info does not to call refresh_window in some cases, which is why I'm using a flag to control the refresh. With this changes I'm now only seeing a single refresh_window call for each vertical scroll. There should be no user visible changes after this commit. --- gdb/tui/tui-winsource.c | 12 ++++++------ gdb/tui/tui-winsource.h | 9 ++++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 50efa80576f..b5b6079a909 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -172,8 +172,8 @@ tui_source_window_base::update_source_window_as_is { validate_scroll_offsets (); update_breakpoint_info (nullptr, false); + update_exec_info (false); show_source_content (); - update_exec_info (); } } @@ -636,11 +636,10 @@ tui_source_window_base::update_breakpoint_info return need_refresh; } -/* Function to initialize the content of the execution info window, - based upon the input window which is either the source or - disassembly window. */ +/* See tui-winsource.h. */ + void -tui_source_window_base::update_exec_info () +tui_source_window_base::update_exec_info (bool refresh_p) { update_breakpoint_info (nullptr, true); for (int i = 0; i < m_content.size (); i++) @@ -668,5 +667,6 @@ tui_source_window_base::update_exec_info () show_line_number (i); } - refresh_window (); + if (refresh_p) + refresh_window (); } diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h index 2762afff010..7370ae95d8b 100644 --- a/gdb/tui/tui-winsource.h +++ b/gdb/tui/tui-winsource.h @@ -148,7 +148,14 @@ struct tui_source_window_base : public tui_win_info virtual bool location_matches_p (struct bp_location *loc, int line_no) = 0; - void update_exec_info (); + /* Fill in the left margin of the current window with execution indicator + information, e.g. breakpoint indicators, and line numbers. When + REFRESH_P is true this function will call refresh_window to ensure + updates are written to the screen, otherwise the refresh is skipped, + which will leave the on screen contents out of date. When passing + false for REFRESH_P you should be planning to call refresh_window + yourself. */ + void update_exec_info (bool refresh_p = true); /* Update the window to display the given location. Does nothing if the location is already displayed. */ From patchwork Wed Jan 25 12:08:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 63668 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E1DD3858035 for ; Wed, 25 Jan 2023 12:10:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E1DD3858035 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674648640; bh=pmk6w1/4OYnPSe5NK3XRH/80PsnaQS0/RDZpEiNljHs=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=aQdIUWoB4+cfyQaKPlfnSCUT3oqfIgmaJXZR13ifVFucS9Vm1hRA+xPIs46nNxJle 3RYPnCkZlxIcasaTQ5yFXJzqZoYaPzPu2swN+Qpt8RU8Tf5ZuGOqnxaQhH1cnHBsAm OLOteR8Ez7xPEvIgbRpaQAXxczIa1A2tg/nqsmVs= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 51FA53858035 for ; Wed, 25 Jan 2023 12:09:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51FA53858035 Received: from mail-vs1-f71.google.com (mail-vs1-f71.google.com [209.85.217.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-639-9llUNU-MO-OSFwa-ap8_4g-1; Wed, 25 Jan 2023 07:09:13 -0500 X-MC-Unique: 9llUNU-MO-OSFwa-ap8_4g-1 Received: by mail-vs1-f71.google.com with SMTP id m63-20020a677142000000b003ce30446ff5so4235434vsc.23 for ; Wed, 25 Jan 2023 04:09:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pmk6w1/4OYnPSe5NK3XRH/80PsnaQS0/RDZpEiNljHs=; b=XHIk0cc/GcByJx96vu94vGRpRpehGkxRoMTzG6C63NqSHuhOxNzNk/cwDwjwo+WpiB LwAxPBoeEWjt2iCW4+UmkfR/SA83BEdeX2j1vxxgInkO403ATV0FNZDYpJRK36Vz2PSy lVdhnzFJ8tSQBwdiNFRvHPUx1XtZwDzIBnqzSkA0dgnqI0nqpx5Dj8Tj+oxaWvJ0pUKA Id1qxLeH/6fvRQ12YWy297tSCGfXRsqV/dLfo4rOPHeo6XMvXZo2XYhf1HlGc9jsd8NT 7VVMOEaco0GV6Ii+Z3KdDFarvOc6ccxsHkqZT2ViU4tN+3NUrR0rPuyqGWSgwhPA/Bkc GsWw== X-Gm-Message-State: AFqh2kq259VOHxYWCjucEl773hw7uWxahDO5rqNI/X4t78Znes6cjgjp 2F5zcyB+xXxYcuv3/Bhd5aMuiObJz7u8T3onzyo0THwor3dUbfIb9jRs2ZAK4+nPD4fFKOs3SAR 7gJzq2OAqA+DPrY/Nmh6OX/jhykATZsScLWy+5LGqTNUFwPnL9DiF8X8qujqo0KD5iDfaOu4IjQ == X-Received: by 2002:a1f:3d93:0:b0:3d3:1c0b:1b05 with SMTP id k141-20020a1f3d93000000b003d31c0b1b05mr18743577vka.16.1674648551774; Wed, 25 Jan 2023 04:09:11 -0800 (PST) X-Google-Smtp-Source: AMrXdXsqXEFzqlf7E7If+zZPkOK8RSBxcGuDM31pS5RfLFaR5D4bMThvvEjTOUmKweuHjCtgaXqmBQ== X-Received: by 2002:a1f:3d93:0:b0:3d3:1c0b:1b05 with SMTP id k141-20020a1f3d93000000b003d31c0b1b05mr18743556vka.16.1674648551464; Wed, 25 Jan 2023 04:09:11 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id m18-20020ae9e012000000b00704c9015e68sm3308721qkk.116.2023.01.25.04.09.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 04:09:11 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 8/8] gdb/tui: more debug output Date: Wed, 25 Jan 2023 12:08:48 +0000 Message-Id: <8135f317a3ce0341b89c864adc0dc38e85703424.1674648473.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Add some additional debug output that I've found really useful while working on the previous set of patches. Unless tui debug is turned on, then there should be no user visible changes with this commit. --- gdb/tui/tui-winsource.c | 21 +++++++++++++++++++++ gdb/tui/tui.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index b5b6079a909..52a0f7af00f 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -316,6 +316,8 @@ tui_source_window_base::show_source_line (int lineno) void tui_source_window_base::refresh_window () { + TUI_SCOPED_DEBUG_START_END ("window `%s`", name ()); + /* tui_win_info::refresh_window would draw the empty background window to the screen, potentially creating a flicker. */ wnoutrefresh (handle.get ()); @@ -326,6 +328,12 @@ tui_source_window_base::refresh_window () int content_width = m_max_length; int pad_x = m_horizontal_offset - m_pad_offset; + tui_debug_printf ("pad_width = %d, left_margin = %d, view_width = %d", + pad_width, left_margin, view_width); + tui_debug_printf ("content_width = %d, pad_x = %d, m_horizontal_offset = %d", + content_width, pad_x, m_horizontal_offset); + tui_debug_printf ("m_pad_offset = %d", m_pad_offset); + gdb_assert (m_pad_offset >= 0); gdb_assert (m_horizontal_offset + view_width <= std::max (content_width, view_width)); @@ -346,6 +354,8 @@ tui_source_window_base::refresh_window () void tui_source_window_base::show_source_content () { + TUI_SCOPED_DEBUG_START_END ("window `%s`", name ()); + gdb_assert (!m_content.empty ()); /* The pad should be at least as wide as the window, but ideally, as wide @@ -390,6 +400,8 @@ tui_source_window_base::show_source_content () } m_pad_requested_width = required_pad_width; + tui_debug_printf ("requested width %d, allocated width %d", + required_pad_width, getmaxx (m_pad.get ())); } gdb_assert (m_pad != nullptr); @@ -431,6 +443,8 @@ tui_source_window_base::update_tab_width () void tui_source_window_base::rerender () { + TUI_SCOPED_DEBUG_START_END ("window `%s`", name ()); + if (!m_content.empty ()) { struct symtab_and_line cursal @@ -492,6 +506,8 @@ tui_source_window_base::refill () bool tui_source_window_base::validate_scroll_offsets () { + TUI_SCOPED_DEBUG_START_END ("window `%s`", name ()); + int original_pad_offset = m_pad_offset; if (m_horizontal_offset < 0) @@ -501,6 +517,11 @@ tui_source_window_base::validate_scroll_offsets () int pad_width = getmaxx (m_pad.get ()); int view_width = this->view_width (); + tui_debug_printf ("pad_width = %d, view_width = %d, content_width = %d", + pad_width, view_width, content_width); + tui_debug_printf ("original_pad_offset = %d, m_horizontal_offset = %d", + original_pad_offset, m_horizontal_offset); + if (m_horizontal_offset + view_width > content_width) m_horizontal_offset = std::max (content_width - view_width, 0); diff --git a/gdb/tui/tui.h b/gdb/tui/tui.h index a9ecd589a70..ca30e7cc65e 100644 --- a/gdb/tui/tui.h +++ b/gdb/tui/tui.h @@ -36,6 +36,9 @@ extern bool debug_tui; #define TUI_SCOPED_DEBUG_ENTER_EXIT \ scoped_debug_enter_exit (debug_tui, "tui") +#define TUI_SCOPED_DEBUG_START_END(fmt, ...) \ + scoped_debug_start_end (debug_tui, "tui", fmt, ##__VA_ARGS__) + struct ui_file; /* Types of error returns. */