Fix PR 20345 - call_function_by_hand_dummy: Assertion `tp->thread_fsm == &sm->thread_...
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / sizeof.exp
CommitLineData
1bf404ef
AC
1# This testcase is part of GDB, the GNU debugger.
2
618f726f 3# Copyright 2000-2016 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
4c93b1db 24if [get_compiler_info] {
ae59b1da 25 return -1
2391e11d
AC
26}
27
0ab77f5f
TT
28if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
29 untested $testfile.exp
30 return -1
31}
2391e11d
AC
32
33#
34# set it up at a breakpoint so we can play with the variable values
35#
36
37if ![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
41d0efca 46gdb_test "next"
edcc8c75 47
2391e11d
AC
48set sizeof_char [get_sizeof "char" 1]
49set sizeof_short [get_sizeof "short" 2]
50set sizeof_int [get_sizeof "int" 4]
51set sizeof_long [get_sizeof "long" 4]
52set sizeof_long_long [get_sizeof "long long" 8]
53
54set sizeof_data_ptr [get_sizeof "void *" 4]
55set sizeof_func_ptr [get_sizeof "void (*)(void)" 4]
56
57set sizeof_float [get_sizeof "float" 4]
58set sizeof_double [get_sizeof "double" 8]
59set sizeof_long_double [get_sizeof "long double" 8]
60
2391e11d
AC
61#
62# Compare GDB's idea of types with the running program
63#
64
65proc check_sizeof { type size } {
41d0efca
YQ
66 gdb_test "next" "" ""
67 gdb_test "p size" " = ${size}" "check sizeof \"$type\""
2391e11d
AC
68}
69
70check_sizeof "char" ${sizeof_char}
71check_sizeof "short" ${sizeof_short}
72check_sizeof "int" ${sizeof_int}
73check_sizeof "long" ${sizeof_long}
74check_sizeof "long long" ${sizeof_long_long}
75
76check_sizeof "void *" ${sizeof_data_ptr}
77check_sizeof "void (*)(void)" ${sizeof_func_ptr}
78
79check_sizeof "float" ${sizeof_float}
80check_sizeof "double" ${sizeof_double}
81check_sizeof "long double" ${sizeof_long_double}
82
edcc8c75 83proc check_valueof { exp val } {
41d0efca
YQ
84 gdb_test "next" "" ""
85 gdb_test "p value" " = ${val}" "check valueof \"$exp\""
edcc8c75
AC
86}
87
88# Check that GDB and the target agree over the sign of a character.
89
417e16e2
PM
90set signof_byte [get_integer_valueof "'\\377'" -1]
91set signof_char [get_integer_valueof "(int) (char) -1" -1]
92set signof_signed_char [get_integer_valueof "(int) (signed char) -1" -1]
93set signof_unsigned_char [get_integer_valueof "(int) (unsigned char) -1" -1]
edcc8c75 94
39fb8e9e 95check_valueof "'\\377'" ${signof_byte}
edcc8c75
AC
96check_valueof "(int) (char) -1" ${signof_char}
97check_valueof "(int) (signed char) -1" ${signof_signed_char}
98check_valueof "(int) (unsigned char) -1" ${signof_unsigned_char}
99
100proc check_padding { fmt type val } {
101 global gdb_prompt
27d3a1a2 102 gdb_test_no_output "set padding_${type}.v = ${val}"
edcc8c75
AC
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
111check_padding "/d" "char" 1
112check_padding "/d" "short" 2
113check_padding "/d" "int" 4
114check_padding "/d" "long" 4
115check_padding "/d" "long_long" 8
116
117# use multiples of two which can be represented exactly
118check_padding "/f" "float" 1
119check_padding "/f" "double" 2
120check_padding "/f" "long_double" 4
2391e11d
AC
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
126send_gdb "maint print arch\n"
127set ok 1
128while { $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}
This page took 2.257967 seconds and 4 git commands to generate.