2000-10-16 Michael Snyder <msnyder@cleaver.cygnus.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / sizeof.exp
CommitLineData
2391e11d
AC
1# Copyright (C) 2000 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-gdb@prep.ai.mit.edu
19
20if $tracelevel {
21 strace $tracelevel
22}
23
24#
25# test running programs
26#
27set prms_id 0
28set bug_id 0
29
30set testfile "sizeof"
31set srcfile ${testfile}.c
32set binfile ${objdir}/${subdir}/${testfile}
33if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
34 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
35}
36
37if [get_compiler_info ${binfile}] {
38 return -1;
39}
40
41gdb_exit
42gdb_start
43gdb_reinitialize_dir $srcdir/$subdir
44gdb_load ${binfile}
45
46#
47# set it up at a breakpoint so we can play with the variable values
48#
49
50if ![runto_main] then {
51 perror "couldn't run to breakpoint"
52 continue
53}
54
55#
56# Query GDB for the size of various types
57#
58
59proc get_sizeof { type default } {
60 global gdb_prompt
61 send_gdb "print/d sizeof (${type})\n"
62 gdb_expect {
63 -re "\\$\[0-9\]* = (\[0-9\]*).*$gdb_prompt $" {
64 set size $expect_out(1,string)
65 pass "get sizeof ${type} ($size)"
66 }
67 timeout {
68 set size ${default}
69 fail "get sizeof ${type} (timeout)"
70 }
71 }
72 return ${size}
73}
74
75set sizeof_char [get_sizeof "char" 1]
76set sizeof_short [get_sizeof "short" 2]
77set sizeof_int [get_sizeof "int" 4]
78set sizeof_long [get_sizeof "long" 4]
79set sizeof_long_long [get_sizeof "long long" 8]
80
81set sizeof_data_ptr [get_sizeof "void *" 4]
82set sizeof_func_ptr [get_sizeof "void (*)(void)" 4]
83
84set sizeof_float [get_sizeof "float" 4]
85set sizeof_double [get_sizeof "double" 8]
86set sizeof_long_double [get_sizeof "long double" 8]
87
88
89#
90# Compare GDB's idea of types with the running program
91#
92
93proc check_sizeof { type size } {
94 global gdb_prompt
13a5e3b8
MS
95
96 if [gdb_skip_stdio_test "check sizeof $type == $size"] {
97 return;
98 }
99
2391e11d
AC
100 set pat [string_to_regexp ${type}]
101 send_gdb "next\n"
102 gdb_expect {
103 -re "sizeof \\(${pat}\\) == ${size}\[\r\n\].*$gdb_prompt $" {
104 pass "check sizeof ${type} == ${size}"
105 }
106 -re ".*$gdb_prompt $" {
107 fail "check sizeof ${type} == ${size}"
108 }
109 timeout {
110 fail "check sizeof ${type} == ${size} (timeout)"
111 }
112 }
113}
114
115check_sizeof "char" ${sizeof_char}
116check_sizeof "short" ${sizeof_short}
117check_sizeof "int" ${sizeof_int}
118check_sizeof "long" ${sizeof_long}
119check_sizeof "long long" ${sizeof_long_long}
120
121check_sizeof "void *" ${sizeof_data_ptr}
122check_sizeof "void (*)(void)" ${sizeof_func_ptr}
123
124check_sizeof "float" ${sizeof_float}
125check_sizeof "double" ${sizeof_double}
126check_sizeof "long double" ${sizeof_long_double}
127
128
129#
130# For reference, dump out the entire architecture
131#
132# The output is very long so use a while loop to consume it
133send_gdb "maint print arch\n"
134set ok 1
135while { $ok } {
136 gdb_expect {
137 -re ".*dump" {
138 #pass "maint print arch $ok"
139 #set ok [expr $ok + 1]
140 }
141 -re "$gdb_prompt $" {
142 pass "maint print arch"
143 set ok 0
144 }
145 timeout {
146 fail "maint print arch (timeout)"
147 set ok 0
148 }
149 }
150}
This page took 0.041738 seconds and 4 git commands to generate.