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.133.124]) by sourceware.org (Postfix) with ESMTPS id E84C73858427 for ; Sun, 6 Feb 2022 14:13:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E84C73858427 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-632-3geM-B0gPFiyBIAzJi58OQ-1; Sun, 06 Feb 2022 09:13:17 -0500 X-MC-Unique: 3geM-B0gPFiyBIAzJi58OQ-1 Received: by mail-ed1-f69.google.com with SMTP id f6-20020a0564021e8600b0040f662b99ffso170943edf.7 for ; Sun, 06 Feb 2022 06:13:17 -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=NPu1soHee9FDVQ0tNPV66BpX8SyAwVlcWmJTbF94Bco=; b=l4o3iBP29QqnnrVevgm6vPauqXX1WMYPyUntHqFBiuDV9c+bV4ShI6J8lBdJZJaHh1 Z5e+ToUQeKysYRmSYjQIaWso34lNJwonUkJpvVgDqxFVz4dhPI27hgVGnklENIHpwqg5 v+gsc5BJTgvjRuYRT1a8k1CWN8sRqSxD7BGXfIaO0OCS6wNAm94wxYnrdzLaUc9b+93r 2wM7FRxbOmiAe7xMvATmVNlmJoEzi54SaELaUVgNYpuPrkh2v9Vj78deOT8i1k55g0lv VqBPnEBwZ+azQ6GVC0hbC0ND1K6UfqCij8ItEBaiVeNLLUiGWfg/JQipNjJFv/qyWZld GC7Q== X-Gm-Message-State: AOAM532t/KfiXtvoeG6dtdcb59crznKUI0BRUG9mg/VtWzS3iGUQd7cd 1KSy7nN/LFAasfkdYPCcD61SrUe2/WCYajuLcYP/06tv265dFGc4GxqPkmW4M6W6Pamo13d0y+v OSJrnOPA1DifmjVUnBJh9AK6mm1U+piK7Ehk/B7AhGb/UxKKGMcq5betICAVGyOlDdbnhI3norw == X-Received: by 2002:a05:6402:3696:: with SMTP id ej22mr7735983edb.146.1644156796062; Sun, 06 Feb 2022 06:13:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPAAYH8l3HlPpJt+FGgwVu80ITC6BRTEysQdV/3fxXK1bG+emC/u+V9pWBMi2sTb7V2br+cA== X-Received: by 2002:a05:6402:3696:: with SMTP id ej22mr7735967edb.146.1644156795812; Sun, 06 Feb 2022 06:13:15 -0800 (PST) Received: from localhost (92.40.178.36.threembb.co.uk. [92.40.178.36]) by smtp.gmail.com with ESMTPSA id j19sm2624391ejm.111.2022.02.06.06.13.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Feb 2022 06:13:15 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 09/15] gdb/tui: avoid fp exception when applying layouts Date: Sun, 6 Feb 2022 14:12:47 +0000 Message-Id: <3df89df1b1848f7377d0f2c4309d3547f0b07fa7.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:20 -0000 Consider: (gdb) tui enable (gdb) layout src (gdb) tui new-layout conly cmd 1 (gdb) layout conly After this, with current master, gdb crashes with a floating-point exception. The problem is that in tui_layout_split::apply, when we switch from 'src' to 'conly', we will try to retain the cmd window height. As such, the cmd window will become a fixed size window, which decreases the available_size, but doesn't count towards the total_weight. As the cmd window is the only window, the total_weight stays at zero, and, when we move into step 2, where we attempt to size the windows, we perform a divide by zero, and crash. After this commit we avoid the divide by zero, and just directly set the window size based on the fixed size. There is still a problem after this commit, when the conly layout is selected the cmd window retains its original height, which will only be part of the terminal. The rest of the terminal is left unused. This issue will be addressed in a later commit, this commit is just about the floating-point exception. --- gdb/testsuite/gdb.tui/new-layout.exp | 3 ++- gdb/tui/tui-layout.c | 30 ++++++++++++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/gdb/testsuite/gdb.tui/new-layout.exp b/gdb/testsuite/gdb.tui/new-layout.exp index d3d34af7439..66048e65238 100644 --- a/gdb/testsuite/gdb.tui/new-layout.exp +++ b/gdb/testsuite/gdb.tui/new-layout.exp @@ -70,7 +70,8 @@ set layouts \ {{0 0 80 15}} ""] \ [list h "{-horizontal asm 1 src 1} 1 status 0 cmd 1" \ {{0 0 40 15} {39 0 41 15}} \ - "$hex
.*21.*return 0"]] + "$hex
.*21.*return 0"] \ + [list cmd_only "cmd 1" {} ""]] # Helper function to verify a list of boxes. proc check_boxes {boxes} { diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index ca901e5c85d..1de34c34e62 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -824,29 +824,37 @@ tui_layout_split::apply (int x_, int y_, int width_, int height_) info[i].share_box = true; } + /* If last_index is set then we have a window that is not of a fixed + size. This window will have its size calculated below, which requires + that the total_weight not be zero (we divide by total_weight, so don't + want a floating-point exception). */ + gdb_assert (last_index == -1 || total_weight > 0); + /* Step 2: Compute the size of each sub-layout. Fixed-sized items are given their fixed size, while others are resized according to their weight. */ int used_size = 0; for (int i = 0; i < m_splits.size (); ++i) { - /* Compute the height and clamp to the allowable range. */ - info[i].size = available_size * m_splits[i].weight / total_weight; - if (info[i].size > info[i].max_size) - info[i].size = info[i].max_size; - if (info[i].size < info[i].min_size) - info[i].size = info[i].min_size; - /* If there is any leftover size, just redistribute it to the - last resizeable window, by dropping it from the allocated - size. We could try to be fancier here perhaps, by - redistributing this size among all windows, not just the - last window. */ if (info[i].min_size != info[i].max_size) { + /* Compute the height and clamp to the allowable range. */ + info[i].size = available_size * m_splits[i].weight / total_weight; + if (info[i].size > info[i].max_size) + info[i].size = info[i].max_size; + if (info[i].size < info[i].min_size) + info[i].size = info[i].min_size; + /* If there is any leftover size, just redistribute it to the + last resizeable window, by dropping it from the allocated + size. We could try to be fancier here perhaps, by + redistributing this size among all windows, not just the + last window. */ used_size += info[i].size; if (info[i].share_box) --used_size; } + else + info[i].size = info[i].min_size; } if (debug_tui) -- 2.25.4