summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/float128.exp
blob: 21a1a99f6ee763407e710492957776e983f6306a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright 2016-2022 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This file is part of the gdb testsuite.  It is intended to test that
# gdb could correctly handle floating point constant with a suffix.

standard_testfile .c

proc do_compile { {opts {}} } {
    global srcdir subdir srcfile binfile
    set ccopts {debug quiet}
    foreach opt $opts {lappend ccopts "additional_flags=$opt"}
    gdb_compile "${srcdir}/${subdir}/${srcfile}" "$binfile" executable $ccopts
}

if { [do_compile] != "" && [do_compile {-mfloat128}] != "" } {
    untested "compiler can't handle __float128 type?"
    return -1
}

clean_restart ${binfile}

if {![runto_main]} {
    return
}

# Run to the breakpoint at return.
gdb_breakpoint [gdb_get_line_number "return"]
gdb_continue_to_breakpoint "return"

# Print the original value of ld and f128
gdb_test "print ld" ".* = 1\\.375.*" "the original value of ld is 1.375"
gdb_test "print f128" ".* = 2\\.375.*" "the original value of f128 is 2.375"

# Test that gdb could correctly recognize float constant expression with a suffix.
# FIXME: gdb does not yet recognize the GNU extension 'q' suffix for __float128 constants.
gdb_test "print ld=-1.375l" ".* = -1\\.375.*" "try to change ld to -1.375 with 'print ld=-1.375l'"
gdb_test "print f128=-2.375l" ".* = -2\\.375.*" "try to change f128 to -2.375 with 'print f128=-2.375l'"

# Test that gdb could handle the above correctly with "set var" command.
set test "set variable ld=10.375l"
gdb_test_multiple "set var ld=10.375l" "$test" {
    -re "$gdb_prompt $" {
	pass "$test"
    }
    -re "Invalid number.*$gdb_prompt $" {
	fail "$test (do not recognize 10.375l)"
    }
}

set test "set variable f128=20.375l"
gdb_test_multiple "set var f128=20.375l" "$test" {
    -re "$gdb_prompt $" {
	pass "$test"
    }
    -re "Invalid number.*$gdb_prompt $" {
	fail "$test (do not recognize 20.375l)"
    }
}

gdb_test "print ld" ".* = 10\\.375.*" "the value of ld is changed to 10.375"
gdb_test "print f128" ".* = 20\\.375.*" "the value of f128 is changed to 20.375"

set mpfr_supported -1
gdb_test_multiple "show configuration" "" {
    -wrap -re "--with-mpfr\r\n.*" {
       set mpfr_supported 1
    }
    -wrap -re "--without-mpfr\r\n.*" {
       set mpfr_supported 0
    }
}

# Test that we can correctly handle the largest IEEE-128 value
# Note: If we get "inf" instead of the correct result, we may have run into
# an internal overflow.  This typically happens on host platforms without
# native IEEE-128 support where GDB was built without MPFR support.
set test "print large128"
gdb_test_multiple "print large128" "$test" {
    -re ".* = 1\\.18973149535723176508575932662800702e\\+4932.*$gdb_prompt $" {
	pass "$test"
    }
    -re ".* = inf.*$gdb_prompt $" {
       if { $mpfr_supported == 0 } {
	   # If the host platform has native 128-bit float support (as is
	   # the case for some versions of s390 and powerpc), the
	   # "print large128" test should be passing, even without MPFR
	   # support.  So, in those cases we should have fail here rather than
	   # unsupported.  However, given that we don't have a way to readily
	   # test for this, we fall back to unsupported.
	   unsupported "$test (Missing MPFR support)"
       } else {
           fail $test
       }
    }
    -re ".*$gdb_prompt $" {
	fail "$test"
    }
}