diff options
author | Tom Tromey <tromey@adacore.com> | 2022-02-17 13:43:59 -0700 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2022-03-10 12:19:08 -0700 |
commit | 56262a931b7ca8ee3ec9104bc7e9e0b40cf3d64e (patch) | |
tree | 06824fe8a8a0723d02b917c5f9aec87d17e73d6e /gdb/printcmd.c | |
parent | fdda16e1fa9637f9b6ca846eebe881cd2901d75a (diff) | |
download | gdb-56262a931b7ca8ee3ec9104bc7e9e0b40cf3d64e.zip gdb-56262a931b7ca8ee3ec9104bc7e9e0b40cf3d64e.tar.gz gdb-56262a931b7ca8ee3ec9104bc7e9e0b40cf3d64e.tar.bz2 |
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
Diffstat (limited to 'gdb/printcmd.c')
-rw-r--r-- | gdb/printcmd.c | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 6f9be82..30de192 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<LONGEST> 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' |