1# Copyright 2016-2023 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 19standard_testfile .c 20 21proc 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 28if { [do_compile] != "" && [do_compile {-mfloat128}] != "" } { 29 untested "compiler can't handle _FloatN/_FloatNx types?" 30 return -1 31} 32 33clean_restart ${binfile} 34 35if {![runto_main]} { 36 return 37} 38 39# Run to the breakpoint at return. 40gdb_breakpoint [gdb_get_line_number "return"] 41gdb_continue_to_breakpoint "return" 42 43# Print the original values of f32, f64, f128, f32x, f64x. 44gdb_test "print f32" ".* = 1\\.5.*" "the original value of f32 is 1.5" 45gdb_test "print f64" ".* = 2\\.25.*" "the original value of f64 is 2.25" 46gdb_test "print f128" ".* = 3\\.375.*" "the original value of f128 is 3.375" 47gdb_test "print f32x" ".* = 10\\.5.*" "the original value of f32x is 10.5" 48gdb_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. 52gdb_test "print f32=-1.5" ".* = -1\\.5.*" "try to change f32 to -1.5 with 'print f32=-1.5'" 53gdb_test "print f64=-2.25" ".* = -2\\.25.*" "try to change f64 to -2.25 with 'print f64=-2.25'" 54gdb_test "print f128=-3.375" ".* = -3\\.375.*" "try to change f128 to -3.375 with 'print f128=-3.375'" 55gdb_test "print f32x=-10.5" ".* = -10\\.5.*" "try to change f32x to -10.5 with 'print f32=-1.5x'" 56gdb_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. 59set test "set variable f32 = 10.5" 60gdb_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 69set test "set variable f64 = 20.25" 70gdb_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 79set test "set variable f128 = 30.375" 80gdb_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 89set test "set variable f32x = 100.5" 90gdb_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 99set test "set variable f64x = 200.25" 100gdb_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 109gdb_test "print f32" ".* = 10\\.5.*" "the value of f32 is changed to 10.5" 110gdb_test "print f64" ".* = 20\\.25.*" "the value of f64 is changed to 20.25" 111gdb_test "print f128" ".* = 30\\.375.*" "the value of f128 is changed to 30.375" 112gdb_test "print f32x" ".* = 100\\.5.*" "the value of f32x is changed to 100.5" 113gdb_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. 116gdb_test "print c32" ".* = 1\\.5 \\+ 1i.*" "the original value of c32 is 1.5 + 1i" 117gdb_test "print c64" ".* = 2\\.25 \\+ 1i.*" "the original value of c64 is 2.25 + 1i" 118gdb_test "print c128" ".* = 3\\.375 \\+ 1i.*" "the original value of c128 is 3.375 + 1i" 119gdb_test "print c32x" ".* = 10\\.5 \\+ 1i.*" "the original value of c32x is 10.5 + 1i" 120gdb_test "print c64x" ".* = 20\\.25 \\+ 1i.*" "the original value of c64x is 20.25 + 1i" 121