xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/float128.exp (revision 8e33eff89e26cf71871ead62f0d5063e1313c33a)
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 __float128 type?"
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 value of ld and f128
44gdb_test "print ld" ".* = 1\\.375.*" "the original value of ld is 1.375"
45gdb_test "print f128" ".* = 2\\.375.*" "the original value of f128 is 2.375"
46
47# Test that gdb could correctly recognize float constant expression with a suffix.
48# FIXME: gdb does not yet recognize the GNU extension 'q' suffix for __float128 constants.
49gdb_test "print ld=-1.375l" ".* = -1\\.375.*" "try to change ld to -1.375 with 'print ld=-1.375l'"
50gdb_test "print f128=-2.375l" ".* = -2\\.375.*" "try to change f128 to -2.375 with 'print f128=-2.375l'"
51
52# Test that gdb could handle the above correctly with "set var" command.
53set test "set variable ld=10.375l"
54gdb_test_multiple "set var ld=10.375l" "$test" {
55    -re "$gdb_prompt $" {
56	pass "$test"
57    }
58    -re "Invalid number.*$gdb_prompt $" {
59	fail "$test (do not recognize 10.375l)"
60    }
61}
62
63set test "set variable f128=20.375l"
64gdb_test_multiple "set var f128=20.375l" "$test" {
65    -re "$gdb_prompt $" {
66	pass "$test"
67    }
68    -re "Invalid number.*$gdb_prompt $" {
69	fail "$test (do not recognize 20.375l)"
70    }
71}
72
73gdb_test "print ld" ".* = 10\\.375.*" "the value of ld is changed to 10.375"
74gdb_test "print f128" ".* = 20\\.375.*" "the value of f128 is changed to 20.375"
75
76set mpfr_supported -1
77gdb_test_multiple "show configuration" "" {
78    -wrap -re "--with-mpfr\r\n.*" {
79       set mpfr_supported 1
80    }
81    -wrap -re "--without-mpfr\r\n.*" {
82       set mpfr_supported 0
83    }
84}
85
86# Test that we can correctly handle the largest IEEE-128 value
87# Note: If we get "inf" instead of the correct result, we may have run into
88# an internal overflow.  This typically happens on host platforms without
89# native IEEE-128 support where GDB was built without MPFR support.
90set test "print large128"
91gdb_test_multiple "print large128" "$test" {
92    -re ".* = 1\\.18973149535723176508575932662800702e\\+4932.*$gdb_prompt $" {
93	pass "$test"
94    }
95    -re ".* = inf.*$gdb_prompt $" {
96       if { $mpfr_supported == 0 } {
97	   # If the host platform has native 128-bit float support (as is
98	   # the case for some versions of s390 and powerpc), the
99	   # "print large128" test should be passing, even without MPFR
100	   # support.  So, in those cases we should have fail here rather than
101	   # unsupported.  However, given that we don't have a way to readily
102	   # test for this, we fall back to unsupported.
103	   unsupported "$test (Missing MPFR support)"
104       } else {
105           fail $test
106       }
107    }
108    -re ".*$gdb_prompt $" {
109	fail "$test"
110    }
111}
112
113