From patchwork Wed Nov 30 10:37:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 61254 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2FDCC385703A for ; Wed, 30 Nov 2022 10:38:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2FDCC385703A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669804693; bh=q+Bu7vZrP02ivwEtnFiRy1srKi/ZBdpSTeYDsjOXvg8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=tpbdR2ngQz4Aaf89Fo4TxIFWT2m9TDPPEfDRxJ97L1WZNVQpV0/vB+DbHfqGunB5n e+B2D8QPM8lbA6Oaf/ui3GAzdVnHDHcVnq4H3MA17p2w/8a7eSoAgtDd7I/2o7PwQ6 YUGOGu14F2Q9+h/GYzPATgJ8TwT9FQG+1aHvCV0g= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id CC93B3858412 for ; Wed, 30 Nov 2022 10:37:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CC93B3858412 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E77311FD70 for ; Wed, 30 Nov 2022 10:37:47 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CEB6E1331F for ; Wed, 30 Nov 2022 10:37:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id nyBDMXsyh2MmBQAAMHmgww (envelope-from ) for ; Wed, 30 Nov 2022 10:37:47 +0000 To: gdb-patches@sourceware.org Subject: [pushed] [gdb] Improve printing of float formats Date: Wed, 30 Nov 2022 11:37:47 +0100 Message-Id: <20221130103747.24467-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Currently, on x86_64, a little endian target, I get: ... $ gdb -q -batch -ex "maint print architecture" | grep " = floatformat" gdbarch_dump: bfloat16_format = floatformat_bfloat16_big gdbarch_dump: double_format = floatformat_ieee_double_big gdbarch_dump: float_format = floatformat_ieee_single_big gdbarch_dump: half_format = floatformat_ieee_half_big gdbarch_dump: long_double_format = floatformat_i387_ext ... which suggests big endian. This is due to this bit of code in pformat: ... /* Just print out one of them - this is only for diagnostics. */ return format[0]->name; ... Fix this by using gdbarch_byte_order to pick the appropriate index, such that we have the more accurate: ... gdbarch_dump: bfloat16_format = floatformat_bfloat16_little gdbarch_dump: half_format = floatformat_ieee_half_little gdbarch_dump: float_format = floatformat_ieee_single_little gdbarch_dump: double_format = floatformat_ieee_double_little gdbarch_dump: long_double_format = floatformat_i387_ext ... Tested on x86_64-linux. --- gdb/arch-utils.c | 8 ++++---- gdb/gdbarch-components.py | 10 +++++----- gdb/gdbarch.c | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) base-commit: 6bd454ca033dcb2e178721eb004d0c5f24415c4c diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index 7b84daf046e..60ffdc5e16a 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -1104,13 +1104,13 @@ show_gdbarch_debug (struct ui_file *file, int from_tty, } static const char * -pformat (const struct floatformat **format) +pformat (struct gdbarch *gdbarch, const struct floatformat **format) { if (format == NULL) return "(null)"; - else - /* Just print out one of them - this is only for diagnostics. */ - return format[0]->name; + + int format_index = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE ? 1 : 0; + return format[format_index]->name; } static const char * diff --git a/gdb/gdbarch-components.py b/gdb/gdbarch-components.py index 9b688998a7b..e7230949aad 100644 --- a/gdb/gdbarch-components.py +++ b/gdb/gdbarch-components.py @@ -201,7 +201,7 @@ Value( name="bfloat16_format", postdefault="floatformats_bfloat16", invalid=True, - printer="pformat (gdbarch->bfloat16_format)", + printer="pformat (gdbarch, gdbarch->bfloat16_format)", ) Value( @@ -216,7 +216,7 @@ Value( name="half_format", postdefault="floatformats_ieee_half", invalid=True, - printer="pformat (gdbarch->half_format)", + printer="pformat (gdbarch, gdbarch->half_format)", ) Value( @@ -231,7 +231,7 @@ Value( name="float_format", postdefault="floatformats_ieee_single", invalid=True, - printer="pformat (gdbarch->float_format)", + printer="pformat (gdbarch, gdbarch->float_format)", ) Value( @@ -246,7 +246,7 @@ Value( name="double_format", postdefault="floatformats_ieee_double", invalid=True, - printer="pformat (gdbarch->double_format)", + printer="pformat (gdbarch, gdbarch->double_format)", ) Value( @@ -261,7 +261,7 @@ Value( name="long_double_format", postdefault="floatformats_ieee_double", invalid=True, - printer="pformat (gdbarch->long_double_format)", + printer="pformat (gdbarch, gdbarch->long_double_format)", ) Value( diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index 3227e945880..ddb8dec1c72 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -565,31 +565,31 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) plongest (gdbarch->bfloat16_bit)); gdb_printf (file, "gdbarch_dump: bfloat16_format = %s\n", - pformat (gdbarch->bfloat16_format)); + pformat (gdbarch, gdbarch->bfloat16_format)); gdb_printf (file, "gdbarch_dump: half_bit = %s\n", plongest (gdbarch->half_bit)); gdb_printf (file, "gdbarch_dump: half_format = %s\n", - pformat (gdbarch->half_format)); + pformat (gdbarch, gdbarch->half_format)); gdb_printf (file, "gdbarch_dump: float_bit = %s\n", plongest (gdbarch->float_bit)); gdb_printf (file, "gdbarch_dump: float_format = %s\n", - pformat (gdbarch->float_format)); + pformat (gdbarch, gdbarch->float_format)); gdb_printf (file, "gdbarch_dump: double_bit = %s\n", plongest (gdbarch->double_bit)); gdb_printf (file, "gdbarch_dump: double_format = %s\n", - pformat (gdbarch->double_format)); + pformat (gdbarch, gdbarch->double_format)); gdb_printf (file, "gdbarch_dump: long_double_bit = %s\n", plongest (gdbarch->long_double_bit)); gdb_printf (file, "gdbarch_dump: long_double_format = %s\n", - pformat (gdbarch->long_double_format)); + pformat (gdbarch, gdbarch->long_double_format)); gdb_printf (file, "gdbarch_dump: wchar_bit = %s\n", plongest (gdbarch->wchar_bit));