From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by sourceware.org (Postfix) with ESMTPS id 013E73857713 for ; Wed, 19 Jul 2023 15:24:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 013E73857713 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-io1-xd34.google.com with SMTP id ca18e2360f4ac-783546553ddso291930339f.0 for ; Wed, 19 Jul 2023 08:24:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1689780290; x=1692372290; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=lg2K1iMmOQgjkMzcckAFYFF9NVxDq3bHvRQokGyBrzY=; b=TKV79ZqTTVsyY+7fn9uJNuIiwyPQ4M+KYatpRkXNjh8BvrV5iQMFbNRnCfcyu0Fm2H m1311dT24wVJmEWoQI6pAWKFr6qKJTmDDioCK7PdVb5tkTTWCeoJtq7zXcAkI56JpO4C 1nbWL+v+qCNMtKAZDjnUXyiX+EcSo209cuymMw2hFp75I2AnnOTPIkzrsChXyeNvZDnp zhozV39FhNMZ+eD/ModxPT3zTZ1KQiaDh+qeHSn/3ebH341pLc+nMNkXM/zRlGAAnPfo MfOgnD8S8LaTCE6oi99F+BXG5UVA9DkzK5kAxpsU42Q26tLvt3YbmBnNFd5QEkvNQLYK AsQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689780290; x=1692372290; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lg2K1iMmOQgjkMzcckAFYFF9NVxDq3bHvRQokGyBrzY=; b=kmt4nOh+CGcb0txZZkZpqQAhZK4c1LpyLuf/Ailt7bo0YThi0plE1a3l28+2fUYlbO iCvegIentfhnTbBXdUqdcBwNNG5TwWlh6VZ1G3Y+zQXeD1+hLDTnzAWjoQfEKewjP2SS oouPeq8uhgxlyyqP2qPuxvL7aCVX9Nm815AdCN/oX+ArkqTtAVsa/lXvHla4memKStlO 44Mmhp8VRokZRgpQetzaFJ+awSkxJP8pZsh1iQLX8bEXeGTv/PAmLIVAYz5YbUSOBeMA yf+TKIk1Mk+ztq7QfXXcVaxKEaouOlJLIb5Cdig7lrwpdtSrZS61V1J1sJ2jZjqNNDrM kb1A== X-Gm-Message-State: ABy/qLakqkoq/GcxkdS8TnahDNuaQQApb4J960X5/J5HkDJ0VI//wC/f du5zKi+9edKMkfMo052pZJ8Cc8K0Ixx4R8JtWehTFQ== X-Google-Smtp-Source: APBJJlG7M4BN6UIXrOVM/HErGvpXgnF8bme9M/bvjFHSam0IdsNTsjBgeeDQO5ERNDJpxayOsqkXzw== X-Received: by 2002:a5d:9d4c:0:b0:787:8d2:e52 with SMTP id k12-20020a5d9d4c000000b0078708d20e52mr5893999iok.5.1689780290063; Wed, 19 Jul 2023 08:24:50 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id e12-20020a5d924c000000b00786582eb9fbsm1408575iol.15.2023.07.19.08.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 08:24:49 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix bug in fixed-point handling Date: Wed, 19 Jul 2023 09:24:42 -0600 Message-Id: <20230719152442.67508-1-tromey@adacore.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Alexandre Oliva found a bug in gdb's handling of fixed-point -- a certain Ada fixed-point type would be misintepreted. The bug was that the DW_AT_small looked like: <1><13cd>: Abbrev Number: 16 (DW_TAG_constant) <13ce> DW_AT_GNU_numerator: 1 <13cf> DW_AT_GNU_denominator: 0x8000000000000000 ... but gdb interpreted the denominator as a negative value. --- gdb/dwarf2/read.c | 2 ++ gdb/testsuite/gdb.ada/fixed_points.exp | 3 +++ gdb/testsuite/gdb.ada/fixed_points/fixed_points.adb | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 3508f2c29ee..c198f6c5857 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -14867,6 +14867,8 @@ get_mpz (struct dwarf2_cu *cu, gdb_mpz *value, struct attribute *attr) ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE, true); } + else if (attr->form_is_unsigned ()) + *value = gdb_mpz (attr->as_unsigned ()); else *value = gdb_mpz (attr->constant_value (1)); } diff --git a/gdb/testsuite/gdb.ada/fixed_points.exp b/gdb/testsuite/gdb.ada/fixed_points.exp index ed61cab4bec..2edc63f4071 100644 --- a/gdb/testsuite/gdb.ada/fixed_points.exp +++ b/gdb/testsuite/gdb.ada/fixed_points.exp @@ -91,4 +91,7 @@ foreach_with_prefix scenario {all minimal} { if {$scenario == "minimal" && [test_compiler_info {gcc-11-*}]} { gdb_test "print fp5_var" " = 3e-19" } + + gdb_test "p Float(Another_Fixed) = Float(Another_Delta * 5)" "true" \ + "value of another_fixed" } diff --git a/gdb/testsuite/gdb.ada/fixed_points/fixed_points.adb b/gdb/testsuite/gdb.ada/fixed_points/fixed_points.adb index 67d38f2770b..edcbac80ef9 100644 --- a/gdb/testsuite/gdb.ada/fixed_points/fixed_points.adb +++ b/gdb/testsuite/gdb.ada/fixed_points/fixed_points.adb @@ -57,6 +57,13 @@ procedure Fixed_Points is FP5_Var : FP5_Type := 3 * Delta5; + + Another_Delta : constant := 1.0/(2**63); + type Another_Type is delta Another_Delta range -1.0 .. (1.0 - Another_Delta); + for Another_Type'small use Another_Delta; + for Another_Type'size use 64; + Another_Fixed : Another_Type := Another_Delta * 5; + begin Base_Object := 1.0/16.0; -- Set breakpoint here Subtype_Object := 1.0/16.0; @@ -67,4 +74,5 @@ begin Do_Nothing (FP3_Var'Address); Do_Nothing (FP4_Var'Address); Do_Nothing (FP5_Var'Address); + Do_Nothing (Another_Fixed'Address); end Fixed_Points; -- 2.40.1