aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2022-02-17 13:43:59 -0700
committerTom Tromey <tromey@adacore.com>2022-03-10 12:19:08 -0700
commit56262a931b7ca8ee3ec9104bc7e9e0b40cf3d64e (patch)
tree06824fe8a8a0723d02b917c5f9aec87d17e73d6e /gdb/testsuite
parentfdda16e1fa9637f9b6ca846eebe881cd2901d75a (diff)
downloadfsf-binutils-gdb-56262a931b7ca8ee3ec9104bc7e9e0b40cf3d64e.zip
fsf-binutils-gdb-56262a931b7ca8ee3ec9104bc7e9e0b40cf3d64e.tar.gz
fsf-binutils-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/testsuite')
-rw-r--r--gdb/testsuite/gdb.base/printcmds.c2
-rw-r--r--gdb/testsuite/gdb.base/printcmds.exp23
-rw-r--r--gdb/testsuite/gdb.base/return-nodebug.exp7
3 files changed, 29 insertions, 3 deletions
diff --git a/gdb/testsuite/gdb.base/printcmds.c b/gdb/testsuite/gdb.base/printcmds.c
index 9af6bf3..78291a2 100644
--- a/gdb/testsuite/gdb.base/printcmds.c
+++ b/gdb/testsuite/gdb.base/printcmds.c
@@ -246,6 +246,8 @@ char invalid_RRR[] = "aaaaaaaaaaaaaaaaaaaa"
/* -- */
+float f_var = 65.0f;
+
int main ()
{
void *p = malloc (1);
diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp
index 3763298..3260c8a 100644
--- a/gdb/testsuite/gdb.base/printcmds.exp
+++ b/gdb/testsuite/gdb.base/printcmds.exp
@@ -158,8 +158,27 @@ 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"
+
+ # This is written in a somewhat funny way to avoid assuming a
+ # particular float format.
+ set s_int [get_sizeof int -1]
+ set s_float [get_sizeof float -1]
+ if {$s_int == $s_float && $s_int != -1} {
+ foreach fmt {d u x t o} {
+ set ival [get_valueof "/$fmt" "*(int *) &f_var" "FAIL" \
+ "get_valueof int/$fmt"]
+ set fval [get_valueof "/$fmt" f_var "FAIL" \
+ "get_valueof float/$fmt"]
+ # See PR gdb/16242 for this.
+ if {[string compare $ival $fval] == 0 && $ival != "FAIL"} {
+ pass "print/$fmt f_var"
+ } else {
+ fail "print/$fmt f_var"
+ }
+ }
+ }
+
+ gdb_test "print/c f_var" " = 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 6fd41be..1cce09d 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"
}
}
}