From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id KYzkIE8q6mqu/gsAWB0awg (envelope-from ) for ; Tue, 03 Nov 2026 13:39:11 -0500 Received: by simark.ca (Postfix, from userid 112) id 82B651E043; Tue, 03 Nov 2026 13:39:11 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id CA7D51E043 for ; Tue, 03 Nov 2026 13:39:10 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF7164BA798B for ; Tue, 3 Nov 2026 18:39:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF7164BA798B Received: from zmcc-4-mx.zmailcloud.com (zmcc-4-mx.zmailcloud.com [34.203.170.87]) by sourceware.org (Postfix) with ESMTPS id 5C0B54BA23D8 for ; Tue, 3 Nov 2026 18:38:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C0B54BA23D8 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=symas.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=symas.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5C0B54BA23D8 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=34.203.170.87 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793731126; cv=none; b=ooG9TXIs5O+r/rOQml9xuQy6WZsc1izAm9oMg3H3rCctWsPvXOUZ1dBzrpwOjHBANbmq4ZLY7pApQzh+ym5VnyuWvg6LS4j4IlNxczhS0+xchCyhhJtVtrNJqTaH+gFt5iauRkzTKTXXBF4jhqHP0opDhXXlyjuOQgPphT6E3QI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793731126; c=relaxed/simple; bh=ko9JYaz9ara9C+ju30JNvLVUWSXfpn7KJS64qfGUv5Q=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=WU/ysXx/CEQ7hJPjFzwopVV1GLgiEonhCgRe1T7sQJPw8685qDuvNLkU+nmkMFSJMPQYlb5DIu6ljp7WAnxFgCOyvopmUisfeAh/msIOOPHk5rt7rZjd2ZQZ/A/T+34jliEk2eRB/d3APWpjULz2KNQhFcIENAcCULmw1vzpUCI= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C0B54BA23D8 Received: from zmcc-3.zmailcloud.com (ec2-3-15-255-223.us-east-2.compute.amazonaws.com [3.15.255.223]) (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 zmcc-4-mx.zmailcloud.com (Postfix) with ESMTPS id 0D61F7801DA3; Tue, 3 Nov 2026 12:38:46 -0600 (CST) Received: from zmcc-3.zmailcloud.com (localhost [127.0.0.1]) by zmcc-3-mta-1.zmailcloud.com (Postfix) with ESMTPS id DB9CF1043EBC; Tue, 3 Nov 2026 12:38:45 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by zmcc-3-mta-1.zmailcloud.com (Postfix) with ESMTP id C2BF1104F24A; Tue, 3 Nov 2026 12:38:45 -0600 (CST) Received: from zmcc-3.zmailcloud.com ([127.0.0.1]) by localhost (zmcc-3-mta-1.zmailcloud.com [127.0.0.1]) (amavis, port 10026) with ESMTP id ta6K_IVJUs52; Tue, 3 Nov 2026 12:38:45 -0600 (CST) Received: from zmcc-3-mailbox-1.zmailcloud.com (zmcc-3-mailbox-1.zmailcloud.com [172.31.18.168]) by zmcc-3-mta-1.zmailcloud.com (Postfix) with ESMTP id 835BB1043EBC; Tue, 3 Nov 2026 12:38:45 -0600 (CST) From: Robert Dubner To: Cc: "'Rohr, Stephan'" Subject: [PATCH] gdb: Preserve neighboring bits when writing floating-point fields Thread-Topic: [PATCH] gdb: Preserve neighboring bits when writing floating-point fields Date: Tue, 3 Nov 2026 12:38:45 -0600 (CST) Message-ID: <039301dd6bc2$8fbb09d0$af311d70$@symas.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 X-Mailer: Zimbra 10.1.21_GA_4899 (Zimbra-ZCO/1951 (10.0.26200 en-US) P4838 T2870 R4182) Thread-Index: Ad1rwEAWD3alBsi5RpmFBWn7jPF2PA== Content-Language: en-us X-Zimbra-Message-Verification: hash=SHA256; guid=Yzc1ZTkyMGEzNzUwNGEzY2RkYzRjOTc2Mzk0ZDAyMTc5ZTE0ZGE5ZGJiNDI3MTEyYmE0YzIwZjg5ZDZlNmY0MQ== X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org >From 2c1ada5e34da71f2575d7857ae78db559a972126 Mon Sep 17 00:00:00 2001 From: Robert Dubner Date: Tue, 3 Nov 2026 13:12:57 -0500 Subject: [PATCH] gdb: Preserve neighboring bits when writing floating-point fields put_field can clear bits outside the requested field when the field fits within part of a byte. For IEEE binary16, writing the exponent can clear the adjacent sign bit, turning a negative value positive. Limit both clearing and setting to the requested field width. Derive the mask from cur_bitshift so it accounts for the little-endian adjustment for formats whose total size is not a multiple of eight bits. Also correct the function comment to describe lengths in bits and storing into the buffer, and document that STUFF_TO_PUT must fit in LEN bits. With a volatile _Float16 variable f16, before this change: (gdb) set var f16 = -1.5 (gdb) print f16 $1 = 1.5 After this change: (gdb) set var f16 = -1.5 (gdb) print f16 $1 = -1.5 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34927 --- gdb/target-float.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gdb/target-float.c b/gdb/target-float.c index b278295138e..bf86a158fa0 100644 --- a/gdb/target-float.c +++ b/gdb/target-float.c @@ -229,8 +229,9 @@ get_field (const bfd_byte *data, enum floatformat_byteorders order, return result; } -/* Set a field which starts at START and is LEN bytes long. DATA and - TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */ +/* Set a field which starts at START and is LEN bits long. DATA is the + buffer we are storing into, with TOTAL_LEN bits in byteorder ORDER. + STUFF_TO_PUT must fit in LEN bits. */ static void put_field (unsigned char *data, enum floatformat_byteorders order, unsigned int total_len, unsigned int start, unsigned int len, @@ -260,11 +261,11 @@ put_field (unsigned char *data, enum floatformat_byteorders order, } if (cur_bitshift > -FLOATFORMAT_CHAR_BIT) { - *(data + cur_byte) &= - ~(((1 << ((start + len) % FLOATFORMAT_CHAR_BIT)) - 1) - << (-cur_bitshift)); - *(data + cur_byte) |= - (stuff_to_put & ((1 << FLOATFORMAT_CHAR_BIT) - 1)) << (-cur_bitshift); + unsigned int bits + = std::min (len, (unsigned int) (FLOATFORMAT_CHAR_BIT + cur_bitshift)); + unsigned int mask = ((1 << bits) - 1) << (-cur_bitshift); + *(data + cur_byte) &= ~mask; + *(data + cur_byte) |= (stuff_to_put << (-cur_bitshift)) & mask; } cur_bitshift += FLOATFORMAT_CHAR_BIT; if (order == floatformat_little) -- 2.34.1