From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id w44FNQHND2ITFwAAWB0awg (envelope-from ) for ; Fri, 18 Feb 2022 11:44:49 -0500 Received: by simark.ca (Postfix, from userid 112) id C68D51F3C9; Fri, 18 Feb 2022 11:44:49 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [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 E41A11EE1F for ; Fri, 18 Feb 2022 11:44:48 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 12F03385E45F for ; Fri, 18 Feb 2022 16:44:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12F03385E45F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1645202688; bh=rDaFVvnj1zeo8cZlR90YMcidcLCUu4Uob1LsCxVdZfc=; h=To:Subject:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Mms+SnM7GkZ8zhuxfh+GKp9PpLfZ+FpfgAHN+FCw4ovr81zZqzmYi6ltSY0XYOnPv mRiflRUJB16WCsq/+GpOviQxGZvzJNzhHB8oykYmkmhJJ8qXKAeSpQz0YQ5M5x/3au 4FfC4yqpJnyVpBHwMb89pamTurlCZslwgvBLZ3kw= Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) by sourceware.org (Postfix) with ESMTPS id 8D063385842F for ; Fri, 18 Feb 2022 16:44:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8D063385842F Received: by mail-il1-x12d.google.com with SMTP id d3so5059102ilr.10 for ; Fri, 18 Feb 2022 08:44:27 -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:references:date:in-reply-to :message-id:user-agent:mime-version; bh=rDaFVvnj1zeo8cZlR90YMcidcLCUu4Uob1LsCxVdZfc=; b=SDaUBYXLo1s70H2KGsy9OB92Q8UMdekMtqPt9iSs16h5ABIRlRbGYzEDRcWpbMDLbO ce4O6uKNYkKB86ffdfYNlP+OLXthKtYRLEx5Z4aCRJBN34SOMeuN7oUu8qkiG33LW7iB 6nCPNlUzGCfkeGi7XkHUT2mDbPc/OH6aTO3wtMtjuB23zs3XKSz+HdVdzB23mASy87Wk I7Mewcr0KuqwynQUrOgtFT5+L3CuejNk8h9zYr4HO+agExPTlKjzhUu2P/ojLooVIJ19 FBoQsbRA45znD51QgAf6QdLma0cajzCTtjiIysK8KkVPaX23k4pRhiniCmVBUaN2J3Lm QtWw== X-Gm-Message-State: AOAM532FbGZbZg8wv88szT1bQmLbX+OwpyvAoTV65CQbc6tXkE4uyTQD 2x8OIvdqekzi399JxwpsyANzYQ== X-Google-Smtp-Source: ABdhPJxGaYJmhzz3yYcijGhKP9IdnBG87zmEdE8/GQeYPTnp0Vffz+LPiU/fMVKAuOQD1XoYDRsXWA== X-Received: by 2002:a05:6e02:1e08:b0:2bd:d0bc:174e with SMTP id g8-20020a056e021e0800b002bdd0bc174emr5839166ila.143.1645202666892; Fri, 18 Feb 2022 08:44:26 -0800 (PST) Received: from murgatroyd (75-166-146-214.hlrn.qwest.net. [75.166.146.214]) by smtp.gmail.com with ESMTPSA id w4sm3686769ilo.53.2022.02.18.08.44.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Feb 2022 08:44:26 -0800 (PST) To: Andrew Burgess Subject: Re: [PATCH] Change how "print/x" displays floating-point value References: <20220217212957.1747537-1-tromey@adacore.com> <874k4xdqwl.fsf@redhat.com> X-Attribution: Tom Date: Fri, 18 Feb 2022 09:44:24 -0700 In-Reply-To: <874k4xdqwl.fsf@redhat.com> (Andrew Burgess's message of "Thu, 17 Feb 2022 23:17:30 +0000") Message-ID: <87k0dsqg47.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain 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: , From: Tom Tromey via Gdb-patches Reply-To: Tom Tromey Cc: Tom Tromey , Tom Tromey via Gdb-patches Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Andrew> Would it be possible to increase the testing to cover printing doubles Andrew> as well as floats, and also to test /o and /t format? Did it. Andrew> FWIW, I think this change makes sense. Though I wonder if it is worth Andrew> having a NEWS entry as this might look like a bug to someone who is used Andrew> to the old behaviour? I had actually considered this, so I since you also asked, I think it's a good idea. Andrew> Also, maybe I'm just overly paranoid, but I wonder if it is worth really Andrew> stressing the point in the manual (@node Output Format) that the value Andrew> is reinterpreted, rather than cast. Especially for /d /u /o, etc the Andrew> manual is rather vague on how a float will be handled, e.g.: I did this too. Let me know what you think of this. Tom commit bb4117440a91bff97483eaab4d12543c9663de09 Author: Tom Tromey Date: Thu Feb 17 13:43:59 2022 -0700 Change how "print/x" displays floating-point value 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 diff --git a/gdb/NEWS b/gdb/NEWS index 9da74e71796..544efa3fe74 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -97,6 +97,12 @@ show style disassembler enabled * Changed commands +print + Printing of floating-point values with base-modifying formats like + /x has been changed to display the underlying bytes of the value in + the desired base. This was GDB's documented behavior, but was never + implemented correctly. + maint packet This command can now print a reply, if the reply includes non-printable characters. Any non-printable characters are printed diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index a68cf31dcf3..88121c9d4c5 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -10758,16 +10758,20 @@ Regard the bits of the value as an integer, and print the integer in hexadecimal. @item d -Print as integer in signed decimal. +Regard the bits of the value as an integer, and print the integer in +decimal. @item u -Print as integer in unsigned decimal. +Regard the bits of the value as an integer, and print the integer in +unsigned decimal. @item o -Print as integer in octal. +Regard the bits of the value as an integer, and print the integer in +octal. @item t -Print as integer in binary. The letter @samp{t} stands for ``two''. +Regard the bits of the value as an integer, and print the integer in +binary. The letter @samp{t} stands for ``two''. @footnote{@samp{b} cannot be used because these format letters are also used with the @code{x} command, where @samp{b} stands for ``byte''; see @ref{Memory,,Examining Memory}.} @@ -10789,10 +10793,11 @@ The command @code{info symbol 0x54320} yields similar results. @xref{Symbols, info symbol}. @item c -Regard as an integer and print it as a character constant. This -prints both the numerical value and its character representation. The -character representation is replaced with the octal escape @samp{\nnn} -for characters outside the 7-bit @sc{ascii} range. +Cast the value to an integer (unlike other formats, this does not just +reinterpret the underlying bits) and print it as a character constant. +This prints both the numerical value and its character representation. +The character representation is replaced with the octal escape +@samp{\nnn} for characters outside the 7-bit @sc{ascii} range. Without this format, @value{GDBN} displays @code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} data as character 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..78a2147017d 100644 --- a/gdb/testsuite/gdb.base/printcmds.exp +++ b/gdb/testsuite/gdb.base/printcmds.exp @@ -158,8 +158,14 @@ 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/t 1.5f" " = 111111110000000000000000000000" + gdb_test "print/o 1.5f" " = 07760000000" + gdb_test "print/c 65.0f" " = 65 'A'" 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" } } }