From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iI9INtWEJmK2GgAAWB0awg (envelope-from ) for ; Mon, 07 Mar 2022 17:19:01 -0500 Received: by simark.ca (Postfix, from userid 112) id DC6631F3CA; Mon, 7 Mar 2022 17:19:01 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 471331EDF0 for ; Mon, 7 Mar 2022 17:19:01 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F1DCB385AC09 for ; Mon, 7 Mar 2022 22:19:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F1DCB385AC09 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1646691541; bh=9hBVKoIdImuwfTtxIlfMRhcp+DCX2g8Nw9Squ0QoC1A=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=cr/7CSoVIEhNQKjOYKNf0mI3bkFoCTePhfL5GfllsBLnY4mLNdQM7x1GDABqoZ+fe INE3gsVmqqBmTnTD2jHU6cNpz+ywGbqkTY2B+Eu45MGFMRK0FrRgKmSLRj0hMziGxi SoOQJyvCQt4ju1mlkmSEO4YnN8NLSek4PnG4Yyy0= 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 1CAE13857404 for ; Mon, 7 Mar 2022 22:14:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1CAE13857404 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-473-QBgYRNy2NHaR_6UQVa_O4g-1; Mon, 07 Mar 2022 17:14:04 -0500 X-MC-Unique: QBgYRNy2NHaR_6UQVa_O4g-1 Received: by mail-wr1-f69.google.com with SMTP id c5-20020adffb05000000b001edbbefe96dso4936224wrr.8 for ; Mon, 07 Mar 2022 14:14:04 -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=9hBVKoIdImuwfTtxIlfMRhcp+DCX2g8Nw9Squ0QoC1A=; b=yBmtpFS2oW2p6Dv41FEScJGKZBRVfFD5l8yqWcVLwyGQqunlONvviwagnRUyHuUhYA BHo3YYmWXnFY+wTXAY9pvrsgCttsmhMpBkNnnP8qEwbku38M0vbYDgQL/UObfuED62i3 IajyJkFHRzGelxSHRgWoc0hbh0LFATgJi/xtxWI6FzU5WBLh6k/lFLEi4rPJVKyvV1Yj tmrZn3nWDvjXK6b0eGjzB2KZhKWViJCkv7DK4SawqexLe2qNjfooRPQ7xNkqg63vtYkS IsnjRpSqBqNU4mGH4pzl4NXucRfEgBf++n9L/3Ma0KtfD3IKthcT8HSKe4iWRVhc5uq1 96OA== X-Gm-Message-State: AOAM533XjnrfQNhppqlL1fvvEqfE+qKXNzed/3AmpgkmzUIMDc6X0rvY 8IAlpv30IpHajxt2Be1vJ2pM+jQOCLYSGBWMKr7g8MhWxZNLpwCqBT0hkPKiXFscx8tLnCTK64Q ui3Q7St+7OBPGOVgyD5KCCUbZtHKaTHPyV/ye0ooIJBaBBWzHOaoL0PgZJZg8NB/j0QFtTd9jcQ == X-Received: by 2002:a5d:684b:0:b0:1f1:fc5d:d91c with SMTP id o11-20020a5d684b000000b001f1fc5dd91cmr3894830wrw.266.1646691243085; Mon, 07 Mar 2022 14:14:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJzWNB6AuWLtpXv7/FDxeBQSW5AqfGAIn1IJl9la3aITTDivShXNMK69qtHwOuiWYyUAeueI8Q== X-Received: by 2002:a5d:684b:0:b0:1f1:fc5d:d91c with SMTP id o11-20020a5d684b000000b001f1fc5dd91cmr3894819wrw.266.1646691242737; Mon, 07 Mar 2022 14:14:02 -0800 (PST) Received: from localhost (host86-134-151-205.range86-134.btcentralplus.com. [86.134.151.205]) by smtp.gmail.com with ESMTPSA id 11-20020a05600c22cb00b00382a960b17csm488079wmg.7.2022.03.07.14.14.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 14:14:02 -0800 (PST) To: gdb-patches@sourceware.org Subject: [PATCHv3 09/15] gdb/tui: avoid fp exception when applying layouts Date: Mon, 7 Mar 2022 22:13:41 +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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" 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: , From: Andrew Burgess via Gdb-patches Reply-To: Andrew Burgess Cc: Andrew Burgess Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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 3e1c5804460..8758bfe70e7 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -790,29 +790,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