From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id 37943385E005 for ; Sun, 8 Nov 2020 06:31:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 37943385E005 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=brobecke@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 170BF56161; Sun, 8 Nov 2020 01:31:02 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id RUpocxlxDpQ3; Sun, 8 Nov 2020 01:31:02 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id 073F6117EE5; Sun, 8 Nov 2020 01:31:02 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4233) id 0642D103; Sun, 8 Nov 2020 01:31:02 -0500 (EST) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Joel Brobecker Subject: [PATCH 9/9] Add support for fixed-point type comparison operators Date: Sun, 8 Nov 2020 01:30:17 -0500 Message-Id: <1604817017-25807-10-git-send-email-brobecker@adacore.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1604817017-25807-1-git-send-email-brobecker@adacore.com> References: <1604817017-25807-1-git-send-email-brobecker@adacore.com> X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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, 08 Nov 2020 06:31:03 -0000 This patch adds support for binary comparison operators with fixed-point type values. gdb/ChangeLog: * valarith.c (fixed_point_binop): Add BINOP_EQUAL and BINOP_LESS handling. (value_less): Add fixed-point handling. gdb/testsuite/ChangeLog: * gdb.ada/fixed_cmp.exp: Add -fgnat-encodings=minimal testing. * gdb.dwarf2/dw2-fixed-point.c (pck__fp1_var2): New global. (main): Add reference to pck__fp1_var2. * gdb.dwarf2/dw2-fixed-point.exp: Add comparison operator testing. --- gdb/testsuite/gdb.ada/fixed_cmp.exp | 2 +- gdb/testsuite/gdb.dwarf2/dw2-fixed-point.c | 7 ++ gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp | 102 +++++++++++++++++++++++++++ gdb/valarith.c | 15 +++- 4 files changed, 124 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/gdb.ada/fixed_cmp.exp b/gdb/testsuite/gdb.ada/fixed_cmp.exp index 10e2c9a..4b2e89b 100644 --- a/gdb/testsuite/gdb.ada/fixed_cmp.exp +++ b/gdb/testsuite/gdb.ada/fixed_cmp.exp @@ -19,7 +19,7 @@ if { [skip_ada_tests] } { return -1 } standard_ada_testfile fixed -foreach_with_prefix scenario {all} { +foreach_with_prefix scenario {all minimal} { set flags [list debug additional_flags=-fgnat-encodings=$scenario] if {[gdb_compile_ada "${srcfile}" "${binfile}" executable $flags] != "" } { diff --git a/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.c b/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.c index d9c811c..971a7a8 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.c +++ b/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.c @@ -23,6 +23,12 @@ int8_t pck__fp1_var = 4; /* Simulate an Ada variable declared inside package Pck as follow: + type FP1_Type is delta 0.1 range -1.0 .. +1.0; + FP1_Var2 : FP1_Type := 0.50; + Basically, the same as FP1_Var, but with a different value. */ +int8_t pck__fp1_var2 = 8; + +/* Simulate an Ada variable declared inside package Pck as follow: type FP2_Type is delta 0.01 digits 14; FP2_Var : FP2_Type := -0.01; */ int32_t pck__fp2_var = -1; @@ -41,6 +47,7 @@ int main (void) { pck__fp1_var++; + pck__fp1_var2++; pck__fp2_var++; pck__fp3_var++; pck__fp1_range_var++; diff --git a/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp b/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp index a3c8ff1..cb00ce9 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp @@ -49,6 +49,15 @@ Dwarf::assemble $asm_file { {external 1 flag} } + DW_TAG_variable { + {DW_AT_name pck__fp1_var2} + {DW_AT_type :$fp1_base_type} + {DW_AT_location { + DW_OP_addr [gdb_target_symbol pck__fp1_var2] + } SPECIAL_expr} + {external 1 flag} + } + fp2_base_type: DW_TAG_base_type { {DW_AT_byte_size 1 DW_FORM_sdata} {DW_AT_encoding @DW_ATE_signed_fixed} @@ -161,6 +170,99 @@ gdb_test "print pck.fp1_range_var - 0.5" \ gdb_test "print -pck.fp1_var" \ " = -0.25" +gdb_test "print pck.fp1_var = pck.fp1_var" \ + " = true" + +gdb_test "print pck.fp1_var = pck.fp1_var2" \ + " = false" + +gdb_test "print pck.fp1_var /= pck.fp1_var" \ + " = false" + +gdb_test "print pck.fp1_var /= pck.fp1_var2" \ + " = true" + +gdb_test "print pck.fp1_var < pck.fp1_var" \ + " = false" + +gdb_test "print pck.fp1_var < pck.fp1_var2" \ + " = true" + +gdb_test "print pck.fp1_var <= pck.fp1_var2" \ + " = true" + +gdb_test "print pck.fp1_var <= pck.fp1_var" \ + " = true" + +gdb_test "print pck.fp1_var > pck.fp1_var2" \ + " = false" + +gdb_test "print pck.fp1_var2 > pck.fp1_var" \ + " = true" + +gdb_test "print pck.fp1_var >= pck.fp1_var" \ + " = true" + +gdb_test "print pck.fp1_var >= pck.fp1_var2" \ + " = false" + +# Same as above, but with litterals... + +gdb_test "print pck.fp1_var = 0.25" \ + " = true" + +gdb_test "print pck.fp1_var = 0.5" \ + " = false" + +gdb_test "print pck.fp1_var = 1" \ + " = false" + +gdb_test "print pck.fp1_var /= 0.25" \ + " = false" + +gdb_test "print pck.fp1_var /= 0.5" \ + " = true" + +gdb_test "print pck.fp1_var /= 1" \ + " = true" + +gdb_test "print pck.fp1_var < 0.25" \ + " = false" + +gdb_test "print pck.fp1_var < 0.5" \ + " = true" + +gdb_test "print pck.fp1_var < 1" \ + " = true" + +gdb_test "print pck.fp1_var <= 0.25" \ + " = true" + +gdb_test "print pck.fp1_var <= 0.5" \ + " = true" + +gdb_test "print pck.fp1_var <= 1" \ + " = true" + +gdb_test "print pck.fp1_var > 0.25" \ + " = false" + +gdb_test "print pck.fp1_var > 0.5" \ + " = false" + +gdb_test "print pck.fp1_var > 1" \ + " = false" + +gdb_test "print pck.fp1_var >= 0.25" \ + " = true" + +gdb_test "print pck.fp1_var >= 0.5" \ + " = false" + +gdb_test "print pck.fp1_var >= 1" \ + " = false" + + # Set the language to LANG and do a ptype test on pck__fp1_var, # pck__fp2_var and pck__fp3_var, verifying that the output matches # FP1_RE, FP2_RE, FP2_RE (resp.). diff --git a/gdb/valarith.c b/gdb/valarith.c index 65a6f13..f4497cd 100644 --- a/gdb/valarith.c +++ b/gdb/valarith.c @@ -890,7 +890,9 @@ fixed_point_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) { struct type *type1 = check_typedef (value_type (arg1)); struct type *type2 = check_typedef (value_type (arg2)); + const struct language_defn *language = current_language; + struct gdbarch *gdbarch = get_type_arch (type1); struct value *val; gdb_assert (is_fixed_point_type (type1) || is_fixed_point_type (type2)); @@ -952,6 +954,16 @@ fixed_point_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) INIT_VAL_WITH_FIXED_POINT_VAL (res); break; + case BINOP_EQUAL: + val = value_from_ulongest (language_bool_type (language, gdbarch), + mpq_cmp (v1.val, v2.val) == 0 ? 1 : 0); + break; + + case BINOP_LESS: + val = value_from_ulongest (language_bool_type (language, gdbarch), + mpq_cmp (v1.val, v2.val) < 0 ? 1 : 0); + break; + default: error (_("Integer-only operation on fixed point number.")); } @@ -1774,7 +1786,8 @@ value_less (struct value *arg1, struct value *arg2) is_int1 = is_integral_type (type1); is_int2 = is_integral_type (type2); - if (is_int1 && is_int2) + if ((is_int1 && is_int2) + || (is_fixed_point_type (type1) && is_fixed_point_type (type2))) return longest_to_int (value_as_long (value_binop (arg1, arg2, BINOP_LESS))); else if ((is_floating_value (arg1) || is_int1) -- 2.1.4