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