return -1
}
+# Given a floating point EXPRESSION, return the size of the result.
+
+proc float_size { expression } {
+
+ set size 0
+ gdb_test_multiple "ptype ${expression}" "" {
+ -re -wrap "<16-byte float>" {
+ set size 16
+ }
+ -re -wrap "<12-byte float>" {
+ set size 12
+ }
+ -re -wrap "<\\d+-byte float>" {
+ # Assume 8 for anything less than or equal to 8.
+ set size 8
+ }
+ }
+
+ return $size
+}
+
clean_restart ${testfile}
set bp_location [gdb_get_line_number "BREAK" ${testdir}/prog.adb]
gdb_test "print val_double" " = -2.0e-19" \
"print val_double after assignment"
-set 16llf_supported 0
-gdb_test_multiple "ptype long_long_float" "" {
- -re -wrap "<16-byte float>" {
- set 16llf_supported 1
- pass $gdb_test_name
- }
- -re -wrap "<\\d+-byte float>" {
- pass $gdb_test_name
+# Fetch the size of a compiler-generated long double.
+set compiler_long_double_size [float_size "long_long_float" ]
+
+# Fetch the size of an internal long double type in GDB.
+set gdb_long_double_size [float_size "16llf#0#" ]
+
+# Different architectures use different long double formats. For
+# example, IEEE quad versus i387 long doubles. Account for that in the
+# tests below.
+
+# Set default values for 128-bit IEEE quad long doubles.
+set valid_long_double "16llf#4000921fb54442d18469898cc51701b8#"
+set printed_long_double "3.1415926535897932384626433832795028"
+set invalid_long_double ""
+set has_invalid_long_double 0
+
+if { [istarget x86_64-*-* ] || [istarget i?86-*-*] } {
+ # i387 long double have invalid values
+ set has_invalid_long_double 1
+ if { $compiler_long_double_size == 16 } {
+ # 5.0e+25 in i387 128-bit long double.
+ set valid_long_double "16llf#7ffff7ff4054a56fa5b99019a5c8#"
+ set invalid_long_double "16llf#a56fa5b99019a5c800007ffff7ff4054#"
+ set printed_long_double "5.0e\\+25"
+ } elseif { $compiler_long_double_size == 12 } {
+ # 5.0e+25 in i387 80-bit long double.
+ set valid_long_double "16llf#56554054a56fa5b99019a5c8#"
+ set invalid_long_double "16llf#9019a5c800007ffff7ff4054#"
+ set printed_long_double "5.0e\\+25"
}
}
-if { $16llf_supported } {
- gdb_test "print 16llf#7FFFF7FF4054A56FA5B99019A5C8#" " = 5.0e\\+25"
+# Exercise GDB-side long doubles.
+if { $gdb_long_double_size > 8 } {
+ gdb_test "print ${valid_long_double}" " = ${printed_long_double}"
+ gdb_test "print \$foo:=${valid_long_double}" "= ${printed_long_double}"
+ gdb_test "print \$foo" "= ${printed_long_double}" \
+ "print internal long double variable after assignment"
}
-gdb_test "print val_long_double" " = 5.0e\\+25"
-if { $16llf_supported } {
- gdb_test "print val_long_double := 16llf#7FFFF7FF4054A56FA5B99019A5C8#" \
- " = 5.0e\\+25"
+
+# Exercise compiler-side long doubles.
+if { $compiler_long_double_size > 8 } {
+ gdb_test "print val_long_double" " = 5.0e\\+25"
+ gdb_test "print val_long_double := ${valid_long_double}" \
+ " = ${printed_long_double}"
+ gdb_test "print val_long_double" " = ${printed_long_double}" \
+ "print val_long_double after assignment"
}
-gdb_test "print val_long_double" " = 5.0e\\+25" \
- "print val_long_double after assignment"
-if { $16llf_supported } {
- gdb_test "print 16llf#a56fa5b99019a5c800007ffff7ff4054#" \
- " = <invalid float value>"
+# If the target has invalid long double values, test it now.
+if { $has_invalid_long_double } {
+ gdb_test "print ${invalid_long_double}" \
+ " = <invalid float value>" "print invalid long double value"
}