From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SPw+GIHosF+9OgAAWB0awg (envelope-from ) for ; Sun, 15 Nov 2020 03:36:17 -0500 Received: by simark.ca (Postfix, from userid 112) id 5C0451F09C; Sun, 15 Nov 2020 03:36:17 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=MAILING_LIST_MULTI,RDNS_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [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 A19591F08D for ; Sun, 15 Nov 2020 03:36:15 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E22113857011; Sun, 15 Nov 2020 08:36:14 +0000 (GMT) Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTP id D1D073857802 for ; Sun, 15 Nov 2020 08:36:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D1D073857802 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 B1E4B5604C; Sun, 15 Nov 2020 03:36:12 -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 eliCPhxm6Ad1; Sun, 15 Nov 2020 03:36:12 -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 A2ED256011; Sun, 15 Nov 2020 03:36:12 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4233) id A0D5F111; Sun, 15 Nov 2020 03:36:12 -0500 (EST) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [pushed/v2 6/9] fix printing of DWARF fixed-point type objects with format modifier Date: Sun, 15 Nov 2020 03:35:42 -0500 Message-Id: <1605429345-78384-7-git-send-email-brobecker@adacore.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1605429345-78384-1-git-send-email-brobecker@adacore.com> References: <1604817017-25807-1-git-send-email-brobecker@adacore.com> <1605429345-78384-1-git-send-email-brobecker@adacore.com> 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: , Cc: Simon Marchi , Joel Brobecker Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Consider a fixed-point type such the scaling factor is 1/16, as the following Ada code snippet would create: type FP1_Type is delta 0.1 range -1.0 .. +1.0; FP1_Var : FP1_Type := 0.25; Printing the value of this variable with a format modifier yields the wrong value. E.g.: (gdb) p /x fp1_var $6 = 0x4 Since the real value is 0.25, we therefore expected... (gdb) p /x fp1_var $6 = 0x0 What happens, in this case, is that the value being printed is actually the "raw" value of our object, before the scaling factor gets applied. This commit fixes the issue by using approach as for float values, where we convert the value into an integer value, prior to printing, knowing that the conversion takes the scaling factor into account. gdb/ChangeLog: * printcmd.c (print_scalar_formatted): Add fixed-point type handling when options->format is set. gdb/testsuite/ChangeLog: * gdb.dwarf2/dw2-fixed-point.exp: Add "print /x" tests. --- gdb/ChangeLog | 5 +++++ gdb/printcmd.c | 3 ++- gdb/testsuite/ChangeLog | 4 ++++ gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp | 12 ++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 16905ac..0d322da 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2020-11-15 Joel Brobecker + * printcmd.c (print_scalar_formatted): Add fixed-point type + handling when options->format is set. + +2020-11-15 Joel Brobecker + * ada-valprint.c (ada_value_print_1): Add fixed-point type handling. * dwarf2/read.c (get_dwarf2_rational_constant) (get_dwarf2_unsigned_rational_constant, finish_fixed_point_type) diff --git a/gdb/printcmd.c b/gdb/printcmd.c index f7186c2..6651424 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -421,7 +421,8 @@ print_scalar_formatted (const gdb_byte *valaddr, struct type *type, range case, we want to avoid this, so we store the unpacked value here for possible use later. */ gdb::optional val_long; - if ((type->code () == TYPE_CODE_FLT + if (((type->code () == TYPE_CODE_FLT + || is_fixed_point_type (type)) && (options->format == 'o' || options->format == 'x' || options->format == 't' diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 0f629bd..9b9ffe5 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2020-11-15 Joel Brobecker + * gdb.dwarf2/dw2-fixed-point.exp: Add "print /x" tests. + +2020-11-15 Joel Brobecker + * gdb.ada/fixed_cmp.exp: Force compilation to use -fgnat-encodings=all. * gdb.ada/fixed_points.exp: Add fixed-point variables printing tests. * gdb.ada/fixed_points/pck.ads, gdb.ada/fixed_points/pck.adb: diff --git a/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp b/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp index bf88ffe..27c549c 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp @@ -122,11 +122,23 @@ gdb_test_no_output "set lang ada" gdb_test "print pck.fp1_var" \ " = 0.25" +gdb_test "print /x pck.fp1_var" \ + " = 0x0" + gdb_test "print pck.fp2_var" \ " = -0.01" +gdb_test "print /x pck.fp2_var" \ + " = 0x0" + gdb_test "print pck.fp3_var" \ " = 0.1" +gdb_test "print /x pck.fp3_var" \ + " = 0x0" + gdb_test "print pck.fp1_range_var" \ " = 1" + +gdb_test "print /x pck.fp1_range_var" \ + " = 0x1" -- 2.1.4