Home | History | Annotate | Line # | Download | only in gdb.base
      1  1.1.1.5  christos # Copyright 2016-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 # 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.1.4  christos if {![runto_main]} {
     36  1.1.1.4  christos     return
     37      1.1  christos }
     38      1.1  christos 
     39      1.1  christos # Run to the breakpoint at return.
     40      1.1  christos gdb_breakpoint [gdb_get_line_number "return"]
     41      1.1  christos gdb_continue_to_breakpoint "return"
     42      1.1  christos 
     43      1.1  christos # Print the original values of f32, f64, f128, f32x, f64x.
     44      1.1  christos gdb_test "print f32" ".* = 1\\.5.*" "the original value of f32 is 1.5"
     45      1.1  christos gdb_test "print f64" ".* = 2\\.25.*" "the original value of f64 is 2.25"
     46      1.1  christos gdb_test "print f128" ".* = 3\\.375.*" "the original value of f128 is 3.375"
     47      1.1  christos gdb_test "print f32x" ".* = 10\\.5.*" "the original value of f32x is 10.5"
     48      1.1  christos gdb_test "print f64x" ".* = 20\\.25.*" "the original value of f64x is 20.25"
     49      1.1  christos 
     50      1.1  christos # Test that gdb could correctly recognize float constant expression with a suffix.
     51      1.1  christos # FIXME: gdb does not yet recognize the suffix for _FloatN/_FloatNx types.
     52      1.1  christos gdb_test "print f32=-1.5" ".* = -1\\.5.*" "try to change f32 to -1.5 with 'print f32=-1.5'"
     53      1.1  christos gdb_test "print f64=-2.25" ".* = -2\\.25.*" "try to change f64 to -2.25 with 'print f64=-2.25'"
     54      1.1  christos gdb_test "print f128=-3.375" ".* = -3\\.375.*" "try to change f128 to -3.375 with 'print f128=-3.375'"
     55      1.1  christos gdb_test "print f32x=-10.5" ".* = -10\\.5.*" "try to change f32x to -10.5 with 'print f32=-1.5x'"
     56      1.1  christos gdb_test "print f64x=-20.25" ".* = -20\\.25.*" "try to change f64x to -20.25 with 'print f64=-2.25x'"
     57      1.1  christos 
     58      1.1  christos # Test that gdb could handle the above correctly with "set var" command.
     59      1.1  christos set test "set variable f32 = 10.5"
     60      1.1  christos gdb_test_multiple "set var f32=10.5" "$test" {
     61      1.1  christos     -re "$gdb_prompt $" {
     62      1.1  christos 	pass "$test"
     63      1.1  christos     }
     64      1.1  christos     -re "Invalid number.*$gdb_prompt $" {
     65      1.1  christos 	fail "$test (do not recognize 10.5)"
     66      1.1  christos     }
     67      1.1  christos }
     68      1.1  christos 
     69      1.1  christos set test "set variable f64 = 20.25"
     70      1.1  christos gdb_test_multiple "set var f64=20.25" "$test" {
     71      1.1  christos     -re "$gdb_prompt $" {
     72      1.1  christos 	pass "$test"
     73      1.1  christos     }
     74      1.1  christos     -re "Invalid number.*$gdb_prompt $" {
     75      1.1  christos 	fail "$test (do not recognize 20.25)"
     76      1.1  christos     }
     77      1.1  christos }
     78      1.1  christos 
     79      1.1  christos set test "set variable f128 = 30.375"
     80      1.1  christos gdb_test_multiple "set var f128=30.375" "$test" {
     81      1.1  christos     -re "$gdb_prompt $" {
     82      1.1  christos 	pass "$test"
     83      1.1  christos     }
     84      1.1  christos     -re "Invalid number.*$gdb_prompt $" {
     85      1.1  christos 	fail "$test (do not recognize 30.375)"
     86      1.1  christos     }
     87      1.1  christos }
     88      1.1  christos 
     89      1.1  christos set test "set variable f32x = 100.5"
     90      1.1  christos gdb_test_multiple "set var f32x=100.5" "$test" {
     91      1.1  christos     -re "$gdb_prompt $" {
     92      1.1  christos 	pass "$test"
     93      1.1  christos     }
     94      1.1  christos     -re "Invalid number.*$gdb_prompt $" {
     95      1.1  christos 	fail "$test (do not recognize 100.5)"
     96      1.1  christos     }
     97      1.1  christos }
     98      1.1  christos 
     99      1.1  christos set test "set variable f64x = 200.25"
    100      1.1  christos gdb_test_multiple "set var f64x=200.25" "$test" {
    101      1.1  christos     -re "$gdb_prompt $" {
    102      1.1  christos 	pass "$test"
    103      1.1  christos     }
    104      1.1  christos     -re "Invalid number.*$gdb_prompt $" {
    105      1.1  christos 	fail "$test (do not recognize 200.25)"
    106      1.1  christos     }
    107      1.1  christos }
    108      1.1  christos 
    109      1.1  christos gdb_test "print f32" ".* = 10\\.5.*" "the value of f32 is changed to 10.5"
    110      1.1  christos gdb_test "print f64" ".* = 20\\.25.*" "the value of f64 is changed to 20.25"
    111      1.1  christos gdb_test "print f128" ".* = 30\\.375.*" "the value of f128 is changed to 30.375"
    112      1.1  christos gdb_test "print f32x" ".* = 100\\.5.*" "the value of f32x is changed to 100.5"
    113      1.1  christos gdb_test "print f64x" ".* = 200\\.25.*" "the value of f64x is changed to 200.25"
    114      1.1  christos 
    115      1.1  christos # Print the original values of c32, c64, c128, c32x, c64x.
    116  1.1.1.3  christos gdb_test "print c32" ".* = 1\\.5 \\+ 1i.*" "the original value of c32 is 1.5 + 1i"
    117  1.1.1.3  christos gdb_test "print c64" ".* = 2\\.25 \\+ 1i.*" "the original value of c64 is 2.25 + 1i"
    118  1.1.1.3  christos gdb_test "print c128" ".* = 3\\.375 \\+ 1i.*" "the original value of c128 is 3.375 + 1i"
    119  1.1.1.3  christos gdb_test "print c32x" ".* = 10\\.5 \\+ 1i.*" "the original value of c32x is 10.5 + 1i"
    120  1.1.1.3  christos gdb_test "print c64x" ".* = 20\\.25 \\+ 1i.*" "the original value of c64x is 20.25 + 1i"
    121