1 # Copyright 2016-2024 Free Software Foundation, Inc. 2 3 # This program is free software; you can redistribute it and/or modify 4 # it under the terms of the GNU General Public License as published by 5 # the Free Software Foundation; either version 3 of the License, or 6 # (at your option) any later version. 7 # 8 # This program is distributed in the hope that it will be useful, 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # GNU General Public License for more details. 12 # 13 # You should have received a copy of the GNU General Public License 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 # This file is part of the gdb testsuite. It is intended to test that 17 # gdb could correctly handle floating point constant with a suffix. 18 19 standard_testfile .c 20 21 proc do_compile { {opts {}} } { 22 global srcdir subdir srcfile binfile 23 set ccopts {debug quiet} 24 foreach opt $opts {lappend ccopts "additional_flags=$opt"} 25 gdb_compile "${srcdir}/${subdir}/${srcfile}" "$binfile" executable $ccopts 26 } 27 28 if { [do_compile] != "" && [do_compile {-mfloat128}] != "" } { 29 untested "compiler can't handle _FloatN/_FloatNx types?" 30 return -1 31 } 32 33 clean_restart ${binfile} 34 35 if {![runto_main]} { 36 return 37 } 38 39 # Run to the breakpoint at return. 40 gdb_breakpoint [gdb_get_line_number "return"] 41 gdb_continue_to_breakpoint "return" 42 43 # Print the original values of f32, f64, f128, f32x, f64x. 44 gdb_test "print f32" ".* = 1\\.5.*" "the original value of f32 is 1.5" 45 gdb_test "print f64" ".* = 2\\.25.*" "the original value of f64 is 2.25" 46 gdb_test "print f128" ".* = 3\\.375.*" "the original value of f128 is 3.375" 47 gdb_test "print f32x" ".* = 10\\.5.*" "the original value of f32x is 10.5" 48 gdb_test "print f64x" ".* = 20\\.25.*" "the original value of f64x is 20.25" 49 50 # Test that gdb could correctly recognize float constant expression with a suffix. 51 # FIXME: gdb does not yet recognize the suffix for _FloatN/_FloatNx types. 52 gdb_test "print f32=-1.5" ".* = -1\\.5.*" "try to change f32 to -1.5 with 'print f32=-1.5'" 53 gdb_test "print f64=-2.25" ".* = -2\\.25.*" "try to change f64 to -2.25 with 'print f64=-2.25'" 54 gdb_test "print f128=-3.375" ".* = -3\\.375.*" "try to change f128 to -3.375 with 'print f128=-3.375'" 55 gdb_test "print f32x=-10.5" ".* = -10\\.5.*" "try to change f32x to -10.5 with 'print f32=-1.5x'" 56 gdb_test "print f64x=-20.25" ".* = -20\\.25.*" "try to change f64x to -20.25 with 'print f64=-2.25x'" 57 58 # Test that gdb could handle the above correctly with "set var" command. 59 set test "set variable f32 = 10.5" 60 gdb_test_multiple "set var f32=10.5" "$test" { 61 -re "$gdb_prompt $" { 62 pass "$test" 63 } 64 -re "Invalid number.*$gdb_prompt $" { 65 fail "$test (do not recognize 10.5)" 66 } 67 } 68 69 set test "set variable f64 = 20.25" 70 gdb_test_multiple "set var f64=20.25" "$test" { 71 -re "$gdb_prompt $" { 72 pass "$test" 73 } 74 -re "Invalid number.*$gdb_prompt $" { 75 fail "$test (do not recognize 20.25)" 76 } 77 } 78 79 set test "set variable f128 = 30.375" 80 gdb_test_multiple "set var f128=30.375" "$test" { 81 -re "$gdb_prompt $" { 82 pass "$test" 83 } 84 -re "Invalid number.*$gdb_prompt $" { 85 fail "$test (do not recognize 30.375)" 86 } 87 } 88 89 set test "set variable f32x = 100.5" 90 gdb_test_multiple "set var f32x=100.5" "$test" { 91 -re "$gdb_prompt $" { 92 pass "$test" 93 } 94 -re "Invalid number.*$gdb_prompt $" { 95 fail "$test (do not recognize 100.5)" 96 } 97 } 98 99 set test "set variable f64x = 200.25" 100 gdb_test_multiple "set var f64x=200.25" "$test" { 101 -re "$gdb_prompt $" { 102 pass "$test" 103 } 104 -re "Invalid number.*$gdb_prompt $" { 105 fail "$test (do not recognize 200.25)" 106 } 107 } 108 109 gdb_test "print f32" ".* = 10\\.5.*" "the value of f32 is changed to 10.5" 110 gdb_test "print f64" ".* = 20\\.25.*" "the value of f64 is changed to 20.25" 111 gdb_test "print f128" ".* = 30\\.375.*" "the value of f128 is changed to 30.375" 112 gdb_test "print f32x" ".* = 100\\.5.*" "the value of f32x is changed to 100.5" 113 gdb_test "print f64x" ".* = 200\\.25.*" "the value of f64x is changed to 200.25" 114 115 # Print the original values of c32, c64, c128, c32x, c64x. 116 gdb_test "print c32" ".* = 1\\.5 \\+ 1i.*" "the original value of c32 is 1.5 + 1i" 117 gdb_test "print c64" ".* = 2\\.25 \\+ 1i.*" "the original value of c64 is 2.25 + 1i" 118 gdb_test "print c128" ".* = 3\\.375 \\+ 1i.*" "the original value of c128 is 3.375 + 1i" 119 gdb_test "print c32x" ".* = 10\\.5 \\+ 1i.*" "the original value of c32x is 10.5 + 1i" 120 gdb_test "print c64x" ".* = 20\\.25 \\+ 1i.*" "the original value of c64x is 20.25 + 1i" 121