1# This testcase is part of GDB, the GNU debugger. 2 3# Copyright 2000-2020 Free Software Foundation, Inc. 4 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 3 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18# 19# test running programs 20# 21 22standard_testfile 23 24if [get_compiler_info] { 25 return -1 26} 27 28if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { 29 return -1 30} 31 32# 33# set it up at a breakpoint so we can play with the variable values 34# 35 36if ![runto_main] then { 37 perror "couldn't run to breakpoint" 38 continue 39} 40 41# 42# Query GDB for the size of various types 43# 44 45gdb_test "next" 46 47set sizeof_char [get_sizeof "char" 1] 48set sizeof_short [get_sizeof "short" 2] 49set sizeof_int [get_sizeof "int" 4] 50set sizeof_long [get_sizeof "long" 4] 51set sizeof_long_long [get_sizeof "long long" 8] 52 53set sizeof_data_ptr [get_sizeof "void *" 4] 54set sizeof_func_ptr [get_sizeof "void (*)(void)" 4] 55 56set sizeof_float [get_sizeof "float" 4] 57set sizeof_double [get_sizeof "double" 8] 58set sizeof_long_double [get_sizeof "long double" 8] 59 60# 61# Compare GDB's idea of types with the running program 62# 63 64proc check_sizeof { type size } { 65 gdb_test "next" "" "" 66 gdb_test "p size" " = ${size}" "check sizeof \"$type\"" 67} 68 69check_sizeof "char" ${sizeof_char} 70check_sizeof "short" ${sizeof_short} 71check_sizeof "int" ${sizeof_int} 72check_sizeof "long" ${sizeof_long} 73check_sizeof "long long" ${sizeof_long_long} 74 75check_sizeof "void *" ${sizeof_data_ptr} 76check_sizeof "void (*)(void)" ${sizeof_func_ptr} 77 78check_sizeof "float" ${sizeof_float} 79check_sizeof "double" ${sizeof_double} 80check_sizeof "long double" ${sizeof_long_double} 81 82proc check_valueof { exp val } { 83 gdb_test "next" "" "" 84 gdb_test "p /d value" " = ${val}" "check valueof \"$exp\"" 85} 86 87# Check that GDB and the target agree over the sign of a character. 88 89set signof_byte [get_integer_valueof "(int) '\\377'" -1] 90set signof_char [get_integer_valueof "(int) (char) -1" -1] 91set signof_signed_char [get_integer_valueof "(int) (signed char) -1" -1] 92set signof_unsigned_char [get_integer_valueof "(int) (unsigned char) -1" -1] 93 94check_valueof "'\\377'" ${signof_byte} 95check_valueof "(int) (char) -1" ${signof_char} 96check_valueof "(int) (signed char) -1" ${signof_signed_char} 97check_valueof "(int) (unsigned char) -1" ${signof_unsigned_char} 98 99proc check_padding { fmt type val } { 100 global gdb_prompt 101 gdb_test_no_output "set padding_${type}.v = ${val}" 102 gdb_test "print padding_${type}.p1" "= \"The quick brown \"" 103 gdb_test "print${fmt} padding_${type}.v" "= ${val}" 104 gdb_test "print padding_${type}.p2" "\"The quick brown \".*" 105} 106 107# Check that GDB is managing to store a value in a struct field 108# without corrupting the fields immediately adjacent to it. 109 110check_padding "/d" "char" 1 111check_padding "/d" "short" 2 112check_padding "/d" "int" 4 113check_padding "/d" "long" 4 114check_padding "/d" "long_long" 8 115 116# use multiples of two which can be represented exactly 117check_padding "/f" "float" 1 118check_padding "/f" "double" 2 119check_padding "/f" "long_double" 4 120 121# 122# For reference, dump out the entire architecture 123# 124# The output is very long so use a while loop to consume it 125send_gdb "maint print arch\n" 126set ok 1 127while { $ok } { 128 gdb_expect { 129 -re ".*dump" { 130 #pass "maint print arch $ok" 131 #set ok [expr $ok + 1] 132 } 133 -re "$gdb_prompt $" { 134 pass "maint print arch" 135 set ok 0 136 } 137 timeout { 138 fail "maint print arch (timeout)" 139 set ok 0 140 } 141 } 142} 143