binutils-gdb/gdb/testsuite/gdb.base/all-bin.exp
Andrew Burgess 80c0a3bf1b gdb/testsuite: remove definition of true/false from gdb_compiler_info
Since pretty much forever the get_compiler_info function has included
these lines:

    # Most compilers will evaluate comparisons and other boolean
    # operations to 0 or 1.
    uplevel \#0 { set true 1 }
    uplevel \#0 { set false 0 }

These define global variables true (to 1) and false (to 0).

It seems odd to me that these globals are defined in
get_compiler_info, I guess maybe the original thinking was that if a
compiler had different true/false values then we would detect it there
and define true/false differently.

I don't think we should be bundling this logic into get_compiler_info,
it seems weird to me that in order to use $true/$false a user needs to
first call get_compiler_info.

It would be better I think if each test script that wants these
variables just defined them itself, if in the future we did need
different true/false values based on compiler version then we'd just
do:

  if { [test_compiler_info "some_pattern"] } {
    # Defined true/false one way...
  } else {
    # Defined true/false another way...
  }

But given the current true/false definitions have been in place since
at least 1999, I suspect this will not be needed any time soon.

Given that the definitions of true/false are so simple, right now my
suggestion is just to define them in each test script that wants
them (there's not that many).  If we ever did need more complex logic
then we can always add a function in gdb.exp that sets up these
globals, but that seems overkill for now.

There should be no change in what is tested after this commit.
2022-06-10 11:05:33 +01:00

179 lines
5.0 KiB
Plaintext

# Copyright 1998-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 was written by Elena Zannoni (ezannoni@cygnus.com)
# This file is part of the gdb testsuite
#
# tests for arithmetic, logical and relational operators
# with mixed types
#
#
# test running programs
#
standard_testfile all-types.c
if [get_compiler_info] {
return -1
}
if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
return -1
}
#
# set it up at a breakpoint so we can play with the variable values
#
if ![runto_main] then {
perror "couldn't run to breakpoint"
return
}
# These are used as expected result values.
set false 0
set true 1
gdb_test "next" "return 0;" "continuing after dummy()"
gdb_test "print v_int+v_char" " = 71" "print value of v_int+v_char"
gdb_test "print v_int+v_short" " = 9" "print value of v_int+v_short"
gdb_test "print v_int+v_signed_char" " = 72" \
"print value of v_int+v_signed_char"
gdb_test "print v_int+v_unsigned_char" " = 73" \
"print value of v_int+v_unsigned_char"
gdb_test "print v_int+v_signed_short" " = 10" \
"print value of v_int+v_signed_short"
gdb_test "print v_int+v_unsigned_short" " = 11" \
"print value of v_int+v_unsigned_short"
gdb_test "print v_int+v_signed_int" " = 13" \
"print value of v_int+v_signed_int"
gdb_test "print v_int+v_unsigned_int" " = 14" \
"print value of v_int+v_unsigned_int"
gdb_test "print v_int+v_long" " = 15" "print value of v_int+v_long"
gdb_test "print v_int+v_signed_long" " = 16" \
"print value of v_int+v_signed_long"
gdb_test "print v_int+v_unsigned_long" " = 17" \
"print value of v_int+v_unsigned_long"
gdb_test "print v_int+v_float" " = 106.34343.*" \
"print value of v_int+v_float"
gdb_test "print v_int+v_double" " = 206.565.*" \
"print value of v_int+v_double"
#
# test the relational operators with mixed types
#
gdb_test "print v_int <= v_char" " = 1" "print value of v_int<=v_char"
gdb_test "print v_int <= v_short" " = $false" \
"print value of v_int<=v_short"
gdb_test "print v_int <= v_signed_char" " = 1" \
"print value of v_int<=v_signed_char"
gdb_test "print v_int <= v_unsigned_char" " = 1" \
"print value of v_int<=v_unsigned_char"
gdb_test "print v_int <= v_signed_short" " = $false" \
"print value of v_int<=v_signed_short"
gdb_test "print v_int <= v_unsigned_short" " = $false" \
"print value of v_int<=v_unsigned_short"
gdb_test "print v_int <= v_signed_int" " = $true" \
"print value of v_int<=v_signed_int"
gdb_test "print v_int <= v_unsigned_int" " = $true" \
"print value of v_int<=v_unsigned_int"
gdb_test "print v_int <= v_long" " = $true" "print value of v_int<=v_long"
gdb_test "print v_int <= v_signed_long" " = $true" \
"print value of v_int<=v_signed_long"
gdb_test "print v_int <= v_unsigned_long" " = $true" \
"print value of v_int<=v_unsigned_long"
gdb_test "print v_int <= v_float" " = $true" "print value of v_int<=v_float"
gdb_test "print v_int <= v_double" " = $true" \
"print value of v_int<=v_double"
#
# test the logical operators with mixed types
#
gdb_test_no_output "set variable v_char=0" "set v_char=0"
gdb_test_no_output "set variable v_double=0.0" "set v_double=0"
gdb_test_no_output "set variable v_unsigned_long=0" "set v_unsigned_long=0"
gdb_test "print v_int && v_char" " = $false" "print value of v_int&&v_char"
gdb_test "print v_int && v_short" " = $true" "print value of v_int&&v_short"
gdb_test "print v_int && v_signed_char" " = $true" \
"print value of v_int&&v_signed_char"
gdb_test "print v_int && v_unsigned_char" " = $true" \
"print value of v_int&&v_unsigned_char"
gdb_test "print v_int && v_signed_short" " = $true" \
"print value of v_int&&v_signed_short"
gdb_test "print v_int && v_unsigned_short" " = $true" \
"print value of v_int&&v_unsigned_short"
gdb_test "print v_int && v_signed_int" " = $true" \
"print value of v_int&&v_signed_int"
gdb_test "print v_int && v_unsigned_int" " = $true" \
"print value of v_int&&v_unsigned_int"
gdb_test "print v_int && v_long" " = $true" "print value of v_int&&v_long"
gdb_test "print v_int && v_signed_long" " = $true" \
"print value of v_int&&v_signed_long"
gdb_test "print v_int && v_unsigned_long" " = $false" \
"print value of v_int&&v_unsigned_long"
gdb_test "print v_int && v_float" " = $true" "print value of v_int&&v_float"
gdb_test "print v_int && v_double" " = $false" \
"print value of v_int&&v_double"