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