Commit | Line | Data |
---|---|---|
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 | ||
20 | if $tracelevel { | |
21 | strace $tracelevel | |
22 | } | |
23 | ||
24 | # | |
25 | # test running programs | |
26 | # | |
27 | set prms_id 0 | |
28 | set bug_id 0 | |
29 | ||
30 | set testfile "sizeof" | |
31 | set srcfile ${testfile}.c | |
32 | set binfile ${objdir}/${subdir}/${testfile} | |
33 | if { [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 | ||
37 | if [get_compiler_info ${binfile}] { | |
38 | return -1; | |
39 | } | |
40 | ||
41 | gdb_exit | |
42 | gdb_start | |
43 | gdb_reinitialize_dir $srcdir/$subdir | |
44 | gdb_load ${binfile} | |
45 | ||
46 | # | |
47 | # set it up at a breakpoint so we can play with the variable values | |
48 | # | |
49 | ||
50 | if ![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 | ||
59 | proc 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 | ||
75 | set sizeof_char [get_sizeof "char" 1] | |
76 | set sizeof_short [get_sizeof "short" 2] | |
77 | set sizeof_int [get_sizeof "int" 4] | |
78 | set sizeof_long [get_sizeof "long" 4] | |
79 | set sizeof_long_long [get_sizeof "long long" 8] | |
80 | ||
81 | set sizeof_data_ptr [get_sizeof "void *" 4] | |
82 | set sizeof_func_ptr [get_sizeof "void (*)(void)" 4] | |
83 | ||
84 | set sizeof_float [get_sizeof "float" 4] | |
85 | set sizeof_double [get_sizeof "double" 8] | |
86 | set sizeof_long_double [get_sizeof "long double" 8] | |
87 | ||
88 | ||
89 | # | |
90 | # Compare GDB's idea of types with the running program | |
91 | # | |
92 | ||
93 | proc 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 | ||
110 | check_sizeof "char" ${sizeof_char} | |
111 | check_sizeof "short" ${sizeof_short} | |
112 | check_sizeof "int" ${sizeof_int} | |
113 | check_sizeof "long" ${sizeof_long} | |
114 | check_sizeof "long long" ${sizeof_long_long} | |
115 | ||
116 | check_sizeof "void *" ${sizeof_data_ptr} | |
117 | check_sizeof "void (*)(void)" ${sizeof_func_ptr} | |
118 | ||
119 | check_sizeof "float" ${sizeof_float} | |
120 | check_sizeof "double" ${sizeof_double} | |
121 | check_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 | |
128 | send_gdb "maint print arch\n" | |
129 | set ok 1 | |
130 | while { $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 | } |