From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by sourceware.org (Postfix) with ESMTPS id 0B1C93858D20 for ; Thu, 17 Feb 2022 21:30:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0B1C93858D20 Received: by mail-il1-x12e.google.com with SMTP id p11so3266814ils.1 for ; Thu, 17 Feb 2022 13:30:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NSQN3ciNUfNJvQocmxMcpATmk6KM4pG1/Rg8MaFg2hU=; b=CwREQHJMRfIyylbjB2Ia0V7u14RGpJlkAi5okPbSfaJ4kmWs4PzoQFrPLShxvLAZ1A i1B81r2Ms/oUVRwu+OABckLIPqWXgV1+UzVQO7Im3j6RWW74j9EYq7UN7YeCod8iLc67 xUIeQ3sGIRW1BAJcJZP/vKUyDw0vNYOZfI90B3bcxztUrBlOpNdXGepl3aPgxxHp2t6e lKHyQ/EZkuHdqjI9RNbiWikRU6WemQ6fdn2xzZcZa7yDRsuGSwLhcSww6kK49R43tJ5w 6JNgQtvzOCkSdsB48oZ94g51g1bDTWHW1JQzcG4Z9qtWxAdGxeMNr3PFMvxHrhKSq9Vt KUhQ== X-Gm-Message-State: AOAM532hCUPns3yzPgGlto+eeMNdgA0kZgU5mPYA7lm8ZbHv1fevuIUK wynO56cSt+D2AyVJPnsYOqDzIfHvZaLn8w== X-Google-Smtp-Source: ABdhPJwfIiI0vcb1Nxi6bod2AacWJsxnSWCv5ChGKMuIY2cjK6OLFS2dA+yj51fxK1fBTDD5X25RUA== X-Received: by 2002:a92:7513:0:b0:2b9:5b61:e376 with SMTP id q19-20020a927513000000b002b95b61e376mr3288845ilc.193.1645133400384; Thu, 17 Feb 2022 13:30:00 -0800 (PST) Received: from murgatroyd.Home (75-166-146-214.hlrn.qwest.net. [75.166.146.214]) by smtp.gmail.com with ESMTPSA id h8sm2388614ile.22.2022.02.17.13.29.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 13:29:59 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Change how "print/x" displays floating-point value Date: Thu, 17 Feb 2022 14:29:57 -0700 Message-Id: <20220217212957.1747537-1-tromey@adacore.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Thu, 17 Feb 2022 21:30:02 -0000 Currently, "print/x" will display a floating-point value by first casting it to an integer type. This yields weird results like: (gdb) print/x 1.5 $1 = 0x1 This has confused users multiple times -- see PR gdb/16242, where there are several dups. I've also seen some confusion from this internally at AdaCore. The manual says: 'x' Regard the bits of the value as an integer, and print the integer in hexadecimal. ... which seems more useful. So, perhaps what happened is that this was incorrectly implemented (or maybe correctly implemented and then regressed, as there don't seem to be any tests). This patch fixes the bug. There was a previous discussion where we agreed to preserve the old behavior: https://sourceware.org/legacy-ml/gdb-patches/2017-06/msg00314.html However, I think it makes more sense to follow the manual. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16242 --- gdb/printcmd.c | 9 ++------- gdb/testsuite/gdb.base/printcmds.exp | 7 +++++-- gdb/testsuite/gdb.base/return-nodebug.exp | 7 ++++++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 6f9be820b0c..30de1927d39 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -426,19 +426,14 @@ print_scalar_formatted (const gdb_byte *valaddr, struct type *type, len = newlen; } - /* Historically gdb has printed floats by first casting them to a - long, and then printing the long. PR cli/16242 suggests changing - this to using C-style hex float format. - - Biased range types and sub-word scalar types must also be handled + /* Biased range types and sub-word scalar types must be handled here; the value is correctly computed by unpack_long. */ gdb::byte_vector converted_bytes; /* Some cases below will unpack the value again. In the biased 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 - || is_fixed_point_type (type)) + if ((is_fixed_point_type (type) && (options->format == 'o' || options->format == 'x' || options->format == 't' diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp index 37632985a07..2d0aafd6d8b 100644 --- a/gdb/testsuite/gdb.base/printcmds.exp +++ b/gdb/testsuite/gdb.base/printcmds.exp @@ -158,8 +158,11 @@ proc test_float_rejected {} { # Regression test for PR gdb/21675 proc test_radices {} { gdb_test "print/o 16777211" " = 077777773" - gdb_test "print/d 1.5" " = 1" - gdb_test "print/u 1.5" " = 1" + + # See PR gdb/16242 for this. + gdb_test "print/d 1.5f" " = 1069547520" + gdb_test "print/u 1.5f" " = 1069547520" + gdb_test "print/x 1.5f" " = 0x3fc00000" gdb_test "print/u (char) -1" " = 255" gdb_test "print/d (unsigned char) -1" " = -1" diff --git a/gdb/testsuite/gdb.base/return-nodebug.exp b/gdb/testsuite/gdb.base/return-nodebug.exp index 6fd41bee884..1cce09d2fc4 100644 --- a/gdb/testsuite/gdb.base/return-nodebug.exp +++ b/gdb/testsuite/gdb.base/return-nodebug.exp @@ -38,7 +38,12 @@ proc do_test {type} { "advance to marker" # And if it returned the full width of the result. - gdb_test "print /d t" " = -1" "full width of the returned result" + if {$type == "float" || $type == "double"} { + set flag "" + } else { + set flag "/d" + } + gdb_test "print $flag t" " = -1" "full width of the returned result" } } } -- 2.31.1