| 1 | # Copyright 2005-2019 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 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
| 22 | untested "failed to compile" |
| 23 | return -1 |
| 24 | } |
| 25 | |
| 26 | clean_restart ${binfile} |
| 27 | |
| 28 | if ![runto_main] then { |
| 29 | perror "couldn't run to breakpoint" |
| 30 | continue |
| 31 | } |
| 32 | |
| 33 | # Run to the breakpoint at return. |
| 34 | gdb_breakpoint [gdb_get_line_number "return"] |
| 35 | gdb_continue_to_breakpoint "return" |
| 36 | |
| 37 | # Print the original value of b32, b64 and b128. |
| 38 | gdb_test "print b32" ".*1 = 1\.5.*" "the original value of b32 is 1.5" |
| 39 | gdb_test "print b64" ".*2 = 2\.25.*" "the original value of b64 is 2.25" |
| 40 | gdb_test "print b128" ".*3 = 3\.375.*" "the original value of b128 is 3.375" |
| 41 | |
| 42 | # Test that gdb could correctly recognize float constant expression with a suffix. |
| 43 | gdb_test "print b32=-1.5f" ".*4 = -1\.5.*" "try to change b32 to -1.5 with 'print b32=-1.5f'" |
| 44 | gdb_test "print b64=-2.25f" ".*5 = -2\.25.*" "try to change b64 to -2.25 with 'print b64=-2.25f'" |
| 45 | gdb_test "print b128=-3.375l" ".*6 = -3\.375.*" "try to change b128 to -3.375 with 'print b128=-3.375l'" |
| 46 | |
| 47 | # Test that gdb could handle the above correctly with "set var" command. |
| 48 | set test "set variable b32 = 10.5f" |
| 49 | gdb_test_multiple "set var b32=10.5f" "$test" { |
| 50 | -re "$gdb_prompt $" { |
| 51 | pass "$test" |
| 52 | } |
| 53 | -re "Invalid number.*$gdb_prompt $" { |
| 54 | fail "$test (do not recognize 10.5f)" |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | set test "set variable b64 = 20.25f" |
| 59 | gdb_test_multiple "set var b64=20.25f" "$test" { |
| 60 | -re "$gdb_prompt $" { |
| 61 | pass "$test" |
| 62 | } |
| 63 | -re "Invalid number.*$gdb_prompt $" { |
| 64 | fail "$test (do not recognize 20.25f)" |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | set test "set variable b128 = 30.375l" |
| 69 | gdb_test_multiple "set var b128=30.375l" "$test" { |
| 70 | -re "$gdb_prompt $" { |
| 71 | pass "$test" |
| 72 | } |
| 73 | -re "Invalid number.*$gdb_prompt $" { |
| 74 | fail "$test (do not recognize 30.375l)" |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | gdb_test "print b32" ".*7 = 10\.5.*" "the value of b32 is changed to 10.5" |
| 79 | gdb_test "print b64" ".*8 = 20\.25.*" "the value of b64 is changed to 20.25" |
| 80 | gdb_test "print b128" ".*9 = 30\.375.*" "the value of b128 is changed to 30.375" |
| 81 | |
| 82 | # Test that gdb could handle invalid suffix correctly. |
| 83 | |
| 84 | set test "set variable b32 = 100.5a" |
| 85 | gdb_test_multiple "set var b32=100.5a" "$test" { |
| 86 | -re "Invalid number.*$gdb_prompt $" { |
| 87 | pass "$test" |
| 88 | } |
| 89 | -re "$gdb_prompt $" { |
| 90 | fail "$test (do not report error on invalid suffix)" |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | set test "set variable b64 = 200.25x" |
| 95 | gdb_test_multiple "set var b64=200.25x" "$test" { |
| 96 | -re "Invalid number.*$gdb_prompt $" { |
| 97 | pass "$test" |
| 98 | } |
| 99 | -re "$gdb_prompt $" { |
| 100 | fail "$test (do not report error on invalid suffix)" |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | set test "set variable b128 = 300.375fl" |
| 105 | gdb_test_multiple "set var b128=300.375fl" "$test" { |
| 106 | -re "Invalid number.*$gdb_prompt $" { |
| 107 | pass "$test" |
| 108 | } |
| 109 | -re "$gdb_prompt $" { |
| 110 | fail "$test (do not report error on invalid suffix)" |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | set test "set variable b128 = 300.375fff" |
| 115 | gdb_test_multiple "set var b128=300.375fff" "$test" { |
| 116 | -re "Invalid number.*$gdb_prompt $" { |
| 117 | pass "$test" |
| 118 | } |
| 119 | -re "$gdb_prompt $" { |
| 120 | fail "$test (do not report error on invalid suffix)" |
| 121 | } |
| 122 | } |