Home | History | Annotate | Line # | Download | only in gdb.base
floatn.exp revision 1.1
      1  1.1  christos # Copyright 2016-2017 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 # This file is part of the gdb testsuite.  It is intended to test that
     17  1.1  christos # gdb could correctly handle floating point constant with a suffix.
     18  1.1  christos 
     19  1.1  christos standard_testfile .c
     20  1.1  christos 
     21  1.1  christos proc do_compile { {opts {}} } {
     22  1.1  christos     global srcdir subdir srcfile binfile
     23  1.1  christos     set ccopts {debug quiet}
     24  1.1  christos     foreach opt $opts {lappend ccopts "additional_flags=$opt"}
     25  1.1  christos     gdb_compile "${srcdir}/${subdir}/${srcfile}" "$binfile" executable $ccopts
     26  1.1  christos }
     27  1.1  christos 
     28  1.1  christos if { [do_compile] != "" && [do_compile {-mfloat128}] != "" } {
     29  1.1  christos     untested "compiler can't handle _FloatN/_FloatNx types?"
     30  1.1  christos     return -1
     31  1.1  christos }
     32  1.1  christos 
     33  1.1  christos clean_restart ${binfile}
     34  1.1  christos 
     35  1.1  christos if ![runto_main] then {
     36  1.1  christos     perror "couldn't run to breakpoint"
     37  1.1  christos     continue
     38  1.1  christos }
     39  1.1  christos 
     40  1.1  christos # Run to the breakpoint at return.
     41  1.1  christos gdb_breakpoint [gdb_get_line_number "return"]
     42  1.1  christos gdb_continue_to_breakpoint "return"
     43  1.1  christos 
     44  1.1  christos # Print the original values of f32, f64, f128, f32x, f64x.
     45  1.1  christos gdb_test "print f32" ".* = 1\\.5.*" "the original value of f32 is 1.5"
     46  1.1  christos gdb_test "print f64" ".* = 2\\.25.*" "the original value of f64 is 2.25"
     47  1.1  christos gdb_test "print f128" ".* = 3\\.375.*" "the original value of f128 is 3.375"
     48  1.1  christos gdb_test "print f32x" ".* = 10\\.5.*" "the original value of f32x is 10.5"
     49  1.1  christos gdb_test "print f64x" ".* = 20\\.25.*" "the original value of f64x is 20.25"
     50  1.1  christos 
     51  1.1  christos # Test that gdb could correctly recognize float constant expression with a suffix.
     52  1.1  christos # FIXME: gdb does not yet recognize the suffix for _FloatN/_FloatNx types.
     53  1.1  christos gdb_test "print f32=-1.5" ".* = -1\\.5.*" "try to change f32 to -1.5 with 'print f32=-1.5'"
     54  1.1  christos gdb_test "print f64=-2.25" ".* = -2\\.25.*" "try to change f64 to -2.25 with 'print f64=-2.25'"
     55  1.1  christos gdb_test "print f128=-3.375" ".* = -3\\.375.*" "try to change f128 to -3.375 with 'print f128=-3.375'"
     56  1.1  christos gdb_test "print f32x=-10.5" ".* = -10\\.5.*" "try to change f32x to -10.5 with 'print f32=-1.5x'"
     57  1.1  christos gdb_test "print f64x=-20.25" ".* = -20\\.25.*" "try to change f64x to -20.25 with 'print f64=-2.25x'"
     58  1.1  christos 
     59  1.1  christos # Test that gdb could handle the above correctly with "set var" command.
     60  1.1  christos set test "set variable f32 = 10.5"
     61  1.1  christos gdb_test_multiple "set var f32=10.5" "$test" {
     62  1.1  christos     -re "$gdb_prompt $" {
     63  1.1  christos 	pass "$test"
     64  1.1  christos     }
     65  1.1  christos     -re "Invalid number.*$gdb_prompt $" {
     66  1.1  christos 	fail "$test (do not recognize 10.5)"
     67  1.1  christos     }
     68  1.1  christos }
     69  1.1  christos 
     70  1.1  christos set test "set variable f64 = 20.25"
     71  1.1  christos gdb_test_multiple "set var f64=20.25" "$test" {
     72  1.1  christos     -re "$gdb_prompt $" {
     73  1.1  christos 	pass "$test"
     74  1.1  christos     }
     75  1.1  christos     -re "Invalid number.*$gdb_prompt $" {
     76  1.1  christos 	fail "$test (do not recognize 20.25)"
     77  1.1  christos     }
     78  1.1  christos }
     79  1.1  christos 
     80  1.1  christos set test "set variable f128 = 30.375"
     81  1.1  christos gdb_test_multiple "set var f128=30.375" "$test" {
     82  1.1  christos     -re "$gdb_prompt $" {
     83  1.1  christos 	pass "$test"
     84  1.1  christos     }
     85  1.1  christos     -re "Invalid number.*$gdb_prompt $" {
     86  1.1  christos 	fail "$test (do not recognize 30.375)"
     87  1.1  christos     }
     88  1.1  christos }
     89  1.1  christos 
     90  1.1  christos set test "set variable f32x = 100.5"
     91  1.1  christos gdb_test_multiple "set var f32x=100.5" "$test" {
     92  1.1  christos     -re "$gdb_prompt $" {
     93  1.1  christos 	pass "$test"
     94  1.1  christos     }
     95  1.1  christos     -re "Invalid number.*$gdb_prompt $" {
     96  1.1  christos 	fail "$test (do not recognize 100.5)"
     97  1.1  christos     }
     98  1.1  christos }
     99  1.1  christos 
    100  1.1  christos set test "set variable f64x = 200.25"
    101  1.1  christos gdb_test_multiple "set var f64x=200.25" "$test" {
    102  1.1  christos     -re "$gdb_prompt $" {
    103  1.1  christos 	pass "$test"
    104  1.1  christos     }
    105  1.1  christos     -re "Invalid number.*$gdb_prompt $" {
    106  1.1  christos 	fail "$test (do not recognize 200.25)"
    107  1.1  christos     }
    108  1.1  christos }
    109  1.1  christos 
    110  1.1  christos gdb_test "print f32" ".* = 10\\.5.*" "the value of f32 is changed to 10.5"
    111  1.1  christos gdb_test "print f64" ".* = 20\\.25.*" "the value of f64 is changed to 20.25"
    112  1.1  christos gdb_test "print f128" ".* = 30\\.375.*" "the value of f128 is changed to 30.375"
    113  1.1  christos gdb_test "print f32x" ".* = 100\\.5.*" "the value of f32x is changed to 100.5"
    114  1.1  christos gdb_test "print f64x" ".* = 200\\.25.*" "the value of f64x is changed to 200.25"
    115  1.1  christos 
    116  1.1  christos # Print the original values of c32, c64, c128, c32x, c64x.
    117  1.1  christos gdb_test "print c32" ".* = 1\\.5 \\+ 1 \\* I.*" "the original value of c32 is 1.5 + 1 * I"
    118  1.1  christos gdb_test "print c64" ".* = 2\\.25 \\+ 1 \\* I.*" "the original value of c64 is 2.25 + 1 * I"
    119  1.1  christos gdb_test "print c128" ".* = 3\\.375 \\+ 1 \\* I.*" "the original value of c128 is 3.375 + 1 * I"
    120  1.1  christos gdb_test "print c32x" ".* = 10\\.5 \\+ 1 \\* I.*" "the original value of c32x is 10.5 + 1 * I"
    121  1.1  christos gdb_test "print c64x" ".* = 20\\.25 \\+ 1 \\* I.*" "the original value of c64x is 20.25 + 1 * I"
    122  1.1  christos 
    123  1.1  christos # FIXME: GDB cannot parse non-trivial complex constants yet.
    124  1.1  christos 
    125