public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix bug in fixed-point handling
@ 2023-07-19 15:24 Tom Tromey
  2023-07-31 16:38 ` Tom Tromey
  0 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2023-07-19 15:24 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-08-02 16:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-19 15:24 [PATCH] Fix bug in fixed-point handling Tom Tromey
2023-07-31 16:38 ` Tom Tromey
2023-07-31 21:41   ` Tom de Vries
2023-08-01 14:35     ` Tom Tromey
2023-08-02  0:02       ` Tom de Vries
2023-08-02 15:10         ` Tom Tromey
2023-08-02 15:25           ` Tom de Vries
2023-08-02 16:10             ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).