From patchwork Fri Feb 24 16:38:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 65604 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 16B2F3850413 for ; Fri, 24 Feb 2023 16:39:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 16B2F3850413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677256757; bh=QexkVmCGGsIg/k2bbnWNi0rhytoh4TlhUpMN6Ep8wIU=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=bkdBGz4Xb6H+gyYLF9Sq24pErLShi8cyI7cvXGg5Vr9DuzIhrwoJTYZBC2gQ5lpxO HGiWC+gXn+G8h8HccGGd0A+Gf+pgvJCLKeCa2PX4i/LE/tL4hpM5Ig6HJu0dfRytcK XGvOsGyKg+p1C4+w403o3cZLmC2yeioLlXM3HIdw= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by sourceware.org (Postfix) with ESMTPS id C450E3850871 for ; Fri, 24 Feb 2023 16:38:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C450E3850871 Received: by mail-io1-xd2c.google.com with SMTP id y140so7140615iof.6 for ; Fri, 24 Feb 2023 08:38:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=QexkVmCGGsIg/k2bbnWNi0rhytoh4TlhUpMN6Ep8wIU=; b=lf1puEz3MN6DjVW4mwbQsZklrD6ErvYhcVgEksgWQi8WiLk12gbIfR+U1atfhkyCvE c/E+fPM8jF8O1yc96hEzJ92nsALUnFHR71KCyaWmrfiMNCjxsKPyX0UGeTzM37KQ1Dhr 2ioxPI45EBP+3qMwmYPX+ZvrEbyLoomfhgB0g4TwXn/T4A0qPB17wvT1fvqrbeCeodNN 5oK5n/0kZPGJ2gte0rqlYxz9X7qRbcRgLWBMxVs61R+C/DYm5FfQgF6sRODK3oUWf77d b3FpYrBHBBR4ivPOzWcs6t8vepSbiU60CYdmLzy6fdLoNskZ2nulKescMTzvJGNuGCqA TaBg== X-Gm-Message-State: AO0yUKUC0nK9zkZUybgI2pf9yzZzIVYICn769NMi2nJw4e1ZCh3mjfCx o7hl0hR1tgefz68zX/XekzeZQ5CYGBEbzBiE X-Google-Smtp-Source: AK7set+1McBwlylK7BZIy70DreLVFapdXevZivU76WtsTC+YpxrJ5HE5LDvsYvK+wH/hbaOnVx4voQ== X-Received: by 2002:a5d:8b56:0:b0:74c:87b5:a083 with SMTP id c22-20020a5d8b56000000b0074c87b5a083mr8802812iot.17.1677256721017; Fri, 24 Feb 2023 08:38:41 -0800 (PST) Received: from localhost.localdomain (75-166-130-93.hlrn.qwest.net. [75.166.130.93]) by smtp.gmail.com with ESMTPSA id e13-20020a5d8acd000000b0074564031d75sm3170882iot.2.2023.02.24.08.38.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 08:38:40 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Handle half-float in 'x' command Date: Fri, 24 Feb 2023 09:38:34 -0700 Message-Id: <20230224163834.2675084-1-tromey@adacore.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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 Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Using 'x/hf' should print bytes as float16, but instead it currently prints as an integer. I tracked this down to a missing case in float_type_from_length. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30161 --- gdb/printcmd.c | 4 +++- gdb/testsuite/gdb.dwarf2/dw2-bfloat16.c | 26 +++++++++++++++++++++++ gdb/testsuite/gdb.dwarf2/dw2-bfloat16.exp | 19 ++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-bfloat16.c diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 0d3bc292d4e..6fd69818db9 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -349,7 +349,9 @@ float_type_from_length (struct type *type) struct gdbarch *gdbarch = type->arch (); const struct builtin_type *builtin = builtin_type (gdbarch); - if (type->length () == builtin->builtin_float->length ()) + if (type->length () == builtin->builtin_half->length ()) + type = builtin->builtin_half; + else if (type->length () == builtin->builtin_float->length ()) type = builtin->builtin_float; else if (type->length () == builtin->builtin_double->length ()) type = builtin->builtin_double; diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bfloat16.c b/gdb/testsuite/gdb.dwarf2/dw2-bfloat16.c new file mode 100644 index 00000000000..30dcd38bf06 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-bfloat16.c @@ -0,0 +1,26 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Storage for the 'x' test. */ +unsigned char storage[2]; + +int +main() +{ + asm ("main_label: .globl main_label"); + return 0; +} diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bfloat16.exp b/gdb/testsuite/gdb.dwarf2/dw2-bfloat16.exp index 79058cafe7f..242d1197103 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-bfloat16.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-bfloat16.exp @@ -21,7 +21,7 @@ load_lib dwarf.exp # This test can only be run on targets which support DWARF-2 and use gas. require dwarf2_support -standard_testfile main.c -dw.S +standard_testfile .c -dw.S # Make some DWARF for the test. # 0x4049 is the equivalent of 3.141 for bfloat16. @@ -78,3 +78,20 @@ if ![runto_main] { # Make sure we can print both types correctly. gdb_test "print bf16_1" " = 3.141" gdb_test "print fp16_1" " = 3.1406" + +set bytes {0x48 0x42} +set endian [get_endianness] +if {$endian == "big"} { + set bytes [lreverse $bytes] +} + +gdb_test_no_output "set var \$s = (unsigned char *) &storage" \ + "set convenience variable" +gdb_test "print/x \$s\[0\] = [lindex $bytes 0]" \ + " = $hex" "set first element" +gdb_test "print/x \$s\[1\] = [lindex $bytes 1]" \ + " = $hex" "set second element" +gdb_test "print *(__fp16 *) \$s" " = 3\\.1406" \ + "print float16 value" +gdb_test "x/hf \$s" "$hex :\[ \t\]*3\\.1406" \ + "examine float16 value"