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