* elf64-sparc.c (sparc64_elf_relocate_section): Clear the location
[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
95 set pat [string_to_regexp ${type}]
96 send_gdb "next\n"
97 gdb_expect {
98 -re "sizeof \\(${pat}\\) == ${size}\[\r\n\].*$gdb_prompt $" {
99 pass "check sizeof ${type} == ${size}"
100 }
101 -re ".*$gdb_prompt $" {
102 fail "check sizeof ${type} == ${size}"
103 }
104 timeout {
105 fail "check sizeof ${type} == ${size} (timeout)"
106 }
107 }
108}
109
110check_sizeof "char" ${sizeof_char}
111check_sizeof "short" ${sizeof_short}
112check_sizeof "int" ${sizeof_int}
113check_sizeof "long" ${sizeof_long}
114check_sizeof "long long" ${sizeof_long_long}
115
116check_sizeof "void *" ${sizeof_data_ptr}
117check_sizeof "void (*)(void)" ${sizeof_func_ptr}
118
119check_sizeof "float" ${sizeof_float}
120check_sizeof "double" ${sizeof_double}
121check_sizeof "long double" ${sizeof_long_double}
122
123
124#
125# For reference, dump out the entire architecture
126#
127# The output is very long so use a while loop to consume it
128send_gdb "maint print arch\n"
129set ok 1
130while { $ok } {
131 gdb_expect {
132 -re ".*dump" {
133 #pass "maint print arch $ok"
134 #set ok [expr $ok + 1]
135 }
136 -re "$gdb_prompt $" {
137 pass "maint print arch"
138 set ok 0
139 }
140 timeout {
141 fail "maint print arch (timeout)"
142 set ok 0
143 }
144 }
145}
This page took 0.040681 seconds and 4 git commands to generate.