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