1# This testcase is part of GDB, the GNU debugger. 2 3# Copyright 2000-2013 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 18if [target_info exists gdb,noinferiorio] { 19 verbose "Skipping sizeof.exp because of no fileio capabilities." 20 continue 21} 22 23# 24# test running programs 25# 26 27set testfile "sizeof" 28set srcfile ${testfile}.c 29set binfile ${objdir}/${subdir}/${testfile} 30if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { 31 untested sizeof.exp 32 return -1 33} 34 35if [get_compiler_info] { 36 return -1; 37} 38 39gdb_exit 40gdb_start 41gdb_reinitialize_dir $srcdir/$subdir 42gdb_load ${binfile} 43 44# 45# set it up at a breakpoint so we can play with the variable values 46# 47 48if ![runto_main] then { 49 perror "couldn't run to breakpoint" 50 continue 51} 52 53# 54# Query GDB for the size of various types 55# 56 57gdb_test "next" 58 59set sizeof_char [get_sizeof "char" 1] 60set sizeof_short [get_sizeof "short" 2] 61set sizeof_int [get_sizeof "int" 4] 62set sizeof_long [get_sizeof "long" 4] 63set sizeof_long_long [get_sizeof "long long" 8] 64 65set sizeof_data_ptr [get_sizeof "void *" 4] 66set sizeof_func_ptr [get_sizeof "void (*)(void)" 4] 67 68set sizeof_float [get_sizeof "float" 4] 69set sizeof_double [get_sizeof "double" 8] 70set sizeof_long_double [get_sizeof "long double" 8] 71 72# 73# Compare GDB's idea of types with the running program 74# 75 76proc check_sizeof { type size } { 77 global gdb_prompt 78 79 set pat [string_to_regexp "sizeof (${type}) == ${size}"] 80 gdb_test "next" "${pat}\[\r\n\]+\[0-9\].*" "check sizeof \"$type\"" 81} 82 83check_sizeof "char" ${sizeof_char} 84check_sizeof "short" ${sizeof_short} 85check_sizeof "int" ${sizeof_int} 86check_sizeof "long" ${sizeof_long} 87check_sizeof "long long" ${sizeof_long_long} 88 89check_sizeof "void *" ${sizeof_data_ptr} 90check_sizeof "void (*)(void)" ${sizeof_func_ptr} 91 92check_sizeof "float" ${sizeof_float} 93check_sizeof "double" ${sizeof_double} 94check_sizeof "long double" ${sizeof_long_double} 95 96proc check_valueof { exp val } { 97 global gdb_prompt 98 99 set pat [string_to_regexp "valueof (${exp}) == ${val}"] 100 gdb_test "next" "${pat}\[\r\n\]+\[0-9\].*" "check valueof \"$exp\"" 101} 102 103# Check that GDB and the target agree over the sign of a character. 104 105set signof_byte [get_integer_valueof "'\\377'" -1] 106set signof_char [get_integer_valueof "(int) (char) -1" -1] 107set signof_signed_char [get_integer_valueof "(int) (signed char) -1" -1] 108set signof_unsigned_char [get_integer_valueof "(int) (unsigned char) -1" -1] 109 110check_valueof "'\\377'" ${signof_byte} 111check_valueof "(int) (char) -1" ${signof_char} 112check_valueof "(int) (signed char) -1" ${signof_signed_char} 113check_valueof "(int) (unsigned char) -1" ${signof_unsigned_char} 114 115proc check_padding { fmt type val } { 116 global gdb_prompt 117 gdb_test_no_output "set padding_${type}.v = ${val}" 118 gdb_test "print padding_${type}.p1" "= \"The quick brown \"" 119 gdb_test "print${fmt} padding_${type}.v" "= ${val}" 120 gdb_test "print padding_${type}.p2" "\"The quick brown \".*" 121} 122 123# Check that GDB is managing to store a value in a struct field 124# without corrupting the fields immediately adjacent to it. 125 126check_padding "/d" "char" 1 127check_padding "/d" "short" 2 128check_padding "/d" "int" 4 129check_padding "/d" "long" 4 130check_padding "/d" "long_long" 8 131 132# use multiples of two which can be represented exactly 133check_padding "/f" "float" 1 134check_padding "/f" "double" 2 135check_padding "/f" "long_double" 4 136 137# 138# For reference, dump out the entire architecture 139# 140# The output is very long so use a while loop to consume it 141send_gdb "maint print arch\n" 142set ok 1 143while { $ok } { 144 gdb_expect { 145 -re ".*dump" { 146 #pass "maint print arch $ok" 147 #set ok [expr $ok + 1] 148 } 149 -re "$gdb_prompt $" { 150 pass "maint print arch" 151 set ok 0 152 } 153 timeout { 154 fail "maint print arch (timeout)" 155 set ok 0 156 } 157 } 158} 159