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