1 1.1.1.2 christos # Copyright 2022-2024 Free Software Foundation, Inc. 2 1.1 christos # 3 1.1 christos # This program is free software; you can redistribute it and/or modify 4 1.1 christos # it under the terms of the GNU General Public License as published by 5 1.1 christos # the Free Software Foundation; either version 3 of the License, or 6 1.1 christos # (at your option) any later version. 7 1.1 christos # 8 1.1 christos # This program is distributed in the hope that it will be useful, 9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 1.1 christos # GNU General Public License for more details. 12 1.1 christos # 13 1.1 christos # You should have received a copy of the GNU General Public License 14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 1.1 christos 16 1.1 christos # Test floating-point literal extension. 17 1.1 christos 18 1.1 christos load_lib "ada.exp" 19 1.1 christos 20 1.1.1.2 christos require allow_ada_tests 21 1.1 christos 22 1.1 christos standard_ada_testfile prog 23 1.1 christos 24 1.1 christos if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} { 25 1.1 christos return -1 26 1.1 christos } 27 1.1 christos 28 1.1 christos # Given a floating point EXPRESSION, return the size of the result. 29 1.1 christos 30 1.1 christos proc float_size { expression } { 31 1.1 christos 32 1.1 christos set size 0 33 1.1 christos gdb_test_multiple "ptype ${expression}" "" { 34 1.1 christos -re -wrap "<16-byte float>" { 35 1.1 christos set size 16 36 1.1 christos } 37 1.1 christos -re -wrap "<12-byte float>" { 38 1.1 christos set size 12 39 1.1 christos } 40 1.1 christos -re -wrap "<\\d+-byte float>" { 41 1.1 christos # Assume 8 for anything less than or equal to 8. 42 1.1 christos set size 8 43 1.1 christos } 44 1.1 christos } 45 1.1 christos 46 1.1 christos return $size 47 1.1 christos } 48 1.1 christos 49 1.1 christos clean_restart ${testfile} 50 1.1 christos 51 1.1 christos set bp_location [gdb_get_line_number "BREAK" ${testdir}/prog.adb] 52 1.1 christos runto "prog.adb:$bp_location" 53 1.1 christos 54 1.1 christos gdb_test "print 16f#41b80000#" " = 23.0" 55 1.1 christos gdb_test "print val_float" " = 23.0" 56 1.1 christos gdb_test "print val_float := 16f#41b80000#" " = 23.0" 57 1.1 christos gdb_test "print val_float" " = 23.0" \ 58 1.1 christos "print val_float after assignment" 59 1.1 christos 60 1.1 christos gdb_test "print 16lf#bc0d83c94fb6d2ac#" " = -2.0e-19" 61 1.1 christos gdb_test "print val_double" " = -2.0e-19" 62 1.1 christos gdb_test "print val_double := 16lf#bc0d83c94fb6d2ac#" " = -2.0e-19" 63 1.1 christos gdb_test "print val_double" " = -2.0e-19" \ 64 1.1 christos "print val_double after assignment" 65 1.1 christos 66 1.1 christos # Fetch the size of a compiler-generated long double. 67 1.1 christos set compiler_long_double_size [float_size "long_long_float" ] 68 1.1 christos 69 1.1 christos # Fetch the size of an internal long double type in GDB. 70 1.1 christos set gdb_long_double_size [float_size "16llf#0#" ] 71 1.1 christos 72 1.1 christos # Different architectures use different long double formats. For 73 1.1 christos # example, IEEE quad versus i387 long doubles. Account for that in the 74 1.1 christos # tests below. 75 1.1 christos 76 1.1 christos # Get the used long double format. 77 1.1 christos set long_double_format "" 78 1.1 christos set cmd "maint print architecture" 79 1.1 christos gdb_test_multiple $cmd "" { 80 1.1 christos -re "^[string_to_regexp $cmd](?=\r\n)" { 81 1.1 christos exp_continue 82 1.1 christos } 83 1.1 christos -re "^\r\ngdbarch_dump: long_double_format = (\[^\r\n\]*)(?=\r\n)" { 84 1.1 christos set long_double_format $expect_out(1,string) 85 1.1 christos exp_continue 86 1.1 christos } 87 1.1 christos -re "^\r\n$gdb_prompt $" { 88 1.1 christos pass $gdb_test_name 89 1.1 christos } 90 1.1 christos -re "^\r\n(\[^\r\n\]*)(?=\r\n)" { 91 1.1 christos exp_continue 92 1.1 christos } 93 1.1 christos } 94 1.1 christos 95 1.1 christos # Set default values for 128-bit IEEE quad long doubles. 96 1.1 christos set valid_long_double "16llf#4000921fb54442d18469898cc51701b8#" 97 1.1 christos set printed_long_double "3.1415926535897932384626433832795028" 98 1.1 christos set invalid_long_double "" 99 1.1 christos set has_invalid_long_double 0 100 1.1 christos 101 1.1 christos switch -glob $long_double_format { 102 1.1 christos floatformat_ibm_long_double_* { 103 1.1 christos set w1 c1e1c00000000000 104 1.1 christos set w2 4544adf4b7320335 105 1.1 christos switch $long_double_format { 106 1.1 christos floatformat_ibm_long_double_big { 107 1.1 christos set valid_long_double "16llf#$w2$w1#" 108 1.1 christos } 109 1.1 christos floatformat_ibm_long_double_little { 110 1.1 christos set valid_long_double "16llf#$w1$w2#" 111 1.1 christos } 112 1.1 christos } 113 1.1 christos set printed_long_double "50000000000000000000000000.0" 114 1.1 christos } 115 1.1 christos } 116 1.1 christos 117 1.1 christos if { [istarget x86_64-*-* ] || [istarget i?86-*-*] } { 118 1.1 christos # i387 long double have invalid values 119 1.1 christos set has_invalid_long_double 1 120 1.1 christos if { $compiler_long_double_size == 16 } { 121 1.1 christos # 5.0e+25 in i387 128-bit long double. 122 1.1 christos set valid_long_double "16llf#7ffff7ff4054a56fa5b99019a5c8#" 123 1.1 christos set invalid_long_double "16llf#a56fa5b99019a5c800007ffff7ff4054#" 124 1.1 christos set printed_long_double "5.0e\\+25" 125 1.1 christos } elseif { $compiler_long_double_size == 12 } { 126 1.1 christos # 5.0e+25 in i387 80-bit long double. 127 1.1 christos set valid_long_double "16llf#56554054a56fa5b99019a5c8#" 128 1.1 christos set invalid_long_double "16llf#9019a5c800007ffff7ff4054#" 129 1.1 christos set printed_long_double "5.0e\\+25" 130 1.1 christos } 131 1.1 christos } 132 1.1 christos 133 1.1 christos # Exercise GDB-side long doubles. 134 1.1 christos if { $gdb_long_double_size > 8 } { 135 1.1 christos gdb_test "print ${valid_long_double}" " = ${printed_long_double}" 136 1.1 christos gdb_test "print \$foo:=${valid_long_double}" "= ${printed_long_double}" 137 1.1 christos gdb_test "print \$foo" "= ${printed_long_double}" \ 138 1.1 christos "print internal long double variable after assignment" 139 1.1 christos } 140 1.1 christos 141 1.1 christos # Exercise compiler-side long doubles. 142 1.1 christos if { $compiler_long_double_size > 8 } { 143 1.1 christos gdb_test "print val_long_double" " = 5.0e\\+25" 144 1.1 christos gdb_test "print val_long_double := ${valid_long_double}" \ 145 1.1 christos " = ${printed_long_double}" 146 1.1 christos gdb_test "print val_long_double" " = ${printed_long_double}" \ 147 1.1 christos "print val_long_double after assignment" 148 1.1 christos } 149 1.1 christos 150 1.1 christos # If the target has invalid long double values, test it now. 151 1.1 christos if { $has_invalid_long_double } { 152 1.1 christos gdb_test "print ${invalid_long_double}" \ 153 1.1 christos " = <invalid float value>" "print invalid long double value" 154 1.1 christos } 155