From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 09446385841C for ; Sun, 6 Feb 2022 14:13:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 09446385841C Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-441-Ig0-d7SnP2KZa6manM_uGQ-1; Sun, 06 Feb 2022 09:13:19 -0500 X-MC-Unique: Ig0-d7SnP2KZa6manM_uGQ-1 Received: by mail-ed1-f71.google.com with SMTP id l16-20020aa7c3d0000000b004070ea10e7fso6088056edr.3 for ; Sun, 06 Feb 2022 06:13:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DpoKKAYf47rStVu/Yv7KcQFKL12phrB/hptlG87oIb4=; b=NjOJfyCTt2i7/BgGDAV/UmHCOjD4cE9j5JaSOhmlaZhrz0oNLcNcr0OqNpR59baPkq RRVT661n/HJtrC3+qWS6ZkTJWNgYYzsiPol9eW2ZXwmmdST2U0v6YozmAQl+qymzmEwG Iyqz9KO4Mv8w5JWyS9i0b9rG8wv+EsnAv8lMFEJ7MnMyduyQTxcsoya4QGXmGCWmQzZ0 HWixlCC9L1MnF/TjOQCQ5HSVslxVlwgPY2ZoP53DwCRaM2zcGon6UdQ7xXSL7NwgMcaN pZxIeIxH+wlMVZFpw9mv7Z1eJ2fksXKonlQZID5O1VUWMiAIgpD7f6HR2HTYJZdTL/z2 hk1Q== X-Gm-Message-State: AOAM531sz5tlI6FO3X3XkWiK4alQMdkcp5xu1C+4+/cB7WvVkT2J+8Ie kMYq7tXldkTx7aAUyfn5OH5lWlcPxGafAIxZLWTkGIfpQay77q1EQKr4B3wcostGdGhTH2hU9I/ vbquQpD3yNB1OvncDtnrcVNdngDqWOHqBkO1hMttfWGObnEo3+q09WfxMuhs4vUg+y0LhalkGqg == X-Received: by 2002:aa7:dd15:: with SMTP id i21mr6092845edv.198.1644156797937; Sun, 06 Feb 2022 06:13:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJx64S+Drgq5fWKWWhdJ8EvtUxAQYlX8aGTr9DdmXrx1kPL2/4lXCb//d/mD6eiAw50bb3C4vg== X-Received: by 2002:aa7:dd15:: with SMTP id i21mr6092824edv.198.1644156797678; Sun, 06 Feb 2022 06:13:17 -0800 (PST) Received: from localhost (92.40.178.36.threembb.co.uk. [92.40.178.36]) by smtp.gmail.com with ESMTPSA id m7sm2695505edb.16.2022.02.06.06.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Feb 2022 06:13:17 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 10/15] gdb/tui: fairer distribution of excess space during apply Date: Sun, 6 Feb 2022 14:12:48 +0000 Message-Id: <0f4e96b9c174b9a841d8549421cf8d04d8a82b3b.1644156219.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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-10.5 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_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Feb 2022 14:13:23 -0000 When applying layouts gdb computes the size of each window (or rather, each sub-layout within a layout) using integer arithmetic. As this rounds down the results, then, when all sub-layouts are sized, there is the possibility that we have some space left over. Currently, this space is just assigned to an arbitrary sub-layout. This can result in some unbalanced results. Consider this set of steps with current master: (gdb) tui enable (gdb) layout regs (gdb) info win Name Lines Columns Focus regs 7 80 src 9 80 (has focus) status 1 80 cmd 8 80 Notice the weird split between the src and regs windows, the original layout specification has these windows given equal weight. The problem is that, with rounding, both the regs and src windows are initially sized to 7, the extra 2 lines are then arbitrarily added to the src window. In this commit, rather than add all the extra space to one single window, I instead hand out the extra space 1 line at a time, looping over all the sub-layouts. We take care to respect the min/max sizes, and so, we now get this result: (gdb) tui enable (gdb) layout regs (gdb) info win Name Lines Columns Focus regs 8 80 src 8 80 (has focus) status 1 80 cmd 8 80 This looks more natural to me. This is obviously a change in behaviour, and so, lots of the existing tests need to be updated to take this into account. None of the changes are huge, it's just a line or two (or column for width) moved between windows. --- gdb/testsuite/gdb.tui/basic.exp | 4 ++-- gdb/testsuite/gdb.tui/empty.exp | 14 +++++++++----- gdb/testsuite/gdb.tui/regs.exp | 4 ++-- gdb/testsuite/gdb.tui/winwidth.exp | 17 +++++++++-------- gdb/tui/tui-layout.c | 28 ++++++++++++++++++++++++++-- 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/gdb/testsuite/gdb.tui/basic.exp b/gdb/testsuite/gdb.tui/basic.exp index 0e9f2e3eab2..7afb28b0858 100644 --- a/gdb/testsuite/gdb.tui/basic.exp +++ b/gdb/testsuite/gdb.tui/basic.exp @@ -104,5 +104,5 @@ Term::command "layout split" Term::check_contents "split layout contents" \ "$main_line *$main_re.*$hex
" -Term::check_box "source box in split layout" 0 0 80 7 -Term::check_box "asm box in split layout" 0 6 80 9 +Term::check_box "source box in split layout" 0 0 80 8 +Term::check_box "asm box in split layout" 0 7 80 8 diff --git a/gdb/testsuite/gdb.tui/empty.exp b/gdb/testsuite/gdb.tui/empty.exp index ef14fe4dac0..3efa55d812e 100644 --- a/gdb/testsuite/gdb.tui/empty.exp +++ b/gdb/testsuite/gdb.tui/empty.exp @@ -35,26 +35,26 @@ if {![Term::enter_tui]} { set layouts { {src src {{0 0 80 15}} {{0 0 90 26}} {{"no source" "No Source Available"}}} - {regs src-regs {{0 0 80 7} {0 6 80 9}} {{0 0 90 13} {0 12 90 13}} + {regs src-regs {{0 0 80 8} {0 7 80 8}} {{0 0 90 13} {0 12 90 13}} { {"no source" "No Source Available"} {"no regs" "Register Values Unavailable"} }} - {asm asm {{0 0 80 13}} {{0 0 90 26}} + {asm asm {{0 0 80 15}} {{0 0 90 26}} { {"no asm" "No Assembly Available"} }} - {regs asm-regs {{0 0 80 7} {0 6 80 9}} {{0 0 90 13} {0 12 90 13}} + {regs asm-regs {{0 0 80 8} {0 7 80 8}} {{0 0 90 13} {0 12 90 13}} { {"no asm" "No Assembly Available"} {"no regs" "Register Values Unavailable"} }} - {split split {{0 0 80 6} {0 5 80 8}} {{0 0 90 13} {0 12 90 13}} + {split split {{0 0 80 8} {0 7 80 8}} {{0 0 90 13} {0 12 90 13}} { {"no source" "No Source Available"} {"no asm" "No Assembly Available"} }} - {regs split-regs {{0 0 80 6} {0 5 80 8}} {{0 0 90 13} {0 12 90 13}} + {regs split-regs {{0 0 80 8} {0 7 80 8}} {{0 0 90 13} {0 12 90 13}} { {"no asm" "No Assembly Available"} {"no regs" "Register Values Unavailable"} @@ -97,5 +97,9 @@ foreach layout $layouts { check_text $text_list } Term::resize 24 80 + with_test_prefix "80x24 again" { + check_boxes $small_boxes + check_text $text_list + } } } diff --git a/gdb/testsuite/gdb.tui/regs.exp b/gdb/testsuite/gdb.tui/regs.exp index 178eba03f19..2f3482f5d38 100644 --- a/gdb/testsuite/gdb.tui/regs.exp +++ b/gdb/testsuite/gdb.tui/regs.exp @@ -38,8 +38,8 @@ if {![Term::enter_tui]} { Term::check_contents "source at startup" "\\|.*21 *return 0" Term::command "layout regs" -Term::check_box "register box" 0 0 80 7 -Term::check_box "source box in regs layout" 0 6 80 9 +Term::check_box "register box" 0 0 80 8 +Term::check_box "source box in regs layout" 0 7 80 8 set text [Term::get_line 1] # Just check for any register window content at all. diff --git a/gdb/testsuite/gdb.tui/winwidth.exp b/gdb/testsuite/gdb.tui/winwidth.exp index b0a838b578f..1767b25c8d3 100644 --- a/gdb/testsuite/gdb.tui/winwidth.exp +++ b/gdb/testsuite/gdb.tui/winwidth.exp @@ -39,24 +39,25 @@ with_test_prefix "original window sizes" { } with_test_prefix "after src +5" { - Term::check_box "source box" 0 0 44 15 - Term::check_box "asm box" 43 0 37 15 + Term::check_box "source box" 0 0 45 15 + Term::check_box "asm box" 44 0 36 15 Term::command "winwidth asm -5" } with_test_prefix "after asm -5" { - Term::check_box "source box" 0 0 48 15 - Term::check_box "asm box" 47 0 33 15 + Term::dump_screen + Term::check_box "source box" 0 0 50 15 + Term::check_box "asm box" 49 0 31 15 Term::command "winwidth asm +8" } with_test_prefix "after asm +8" { - Term::check_box "source box" 0 0 39 15 - Term::check_box "asm box" 38 0 42 15 + Term::check_box "source box" 0 0 42 15 + Term::check_box "asm box" 41 0 39 15 Term::command "winwidth src -2" } with_test_prefix "after src -2" { - Term::check_box "source box" 0 0 36 15 - Term::check_box "asm box" 35 0 45 15 + Term::check_box "source box" 0 0 40 15 + Term::check_box "asm box" 39 0 41 15 } diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index 1de34c34e62..8ba54a68fab 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -868,9 +868,33 @@ tui_layout_split::apply (int x_, int y_, int width_, int height_) } /* Allocate any leftover size. */ - if (available_size >= used_size && last_index != -1) + if (available_size > used_size && last_index != -1) { - info[last_index].size += available_size - used_size; + /* Loop over all windows until all available space is used up. */ + bool found_window_that_can_grow_p = true; + for (int idx = last_index; + available_size > used_size; + idx = (idx + 1) % m_splits.size ()) + { + /* Once we have visited all of the windows, check that we did + manage to allocate some more space. This prevents us getting + stuck in the loop forever if we can't allocate anything + more. */ + if (idx == last_index) + { + if (!found_window_that_can_grow_p) + break; + found_window_that_can_grow_p = false; + } + + if (available_size > used_size + && info[idx].size < info[idx].max_size) + { + found_window_that_can_grow_p = true; + info[idx].size += 1; + used_size += 1; + } + } if (debug_tui) { -- 2.25.4