blob: 346aac407885eb0ba8a73b19f34cce6bed4bbeda (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
# Tests for reference types with short type variables in GDB.
# Copyright 1998-2000, 2004, 2007-2012 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# written by Elena Zannoni (ezannoni@cygnus.com)
#
# test running programs
#
if { [skip_cplus_tests] } { continue }
set testfile "ref-types"
set srcfile ${testfile}.cc
set binfile ${objdir}/${subdir}/${testfile}
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
untested ref-types.exp
return -1
}
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
#
# set it up at a breakpoint so we can play with the variable values
#
if ![runto_main] then {
perror "couldn't run to breakpoint"
continue
}
if ![runto 'marker1'] then {
perror "couldn't run to marker1"
continue
}
gdb_test "up" ".*main.*" "up from marker1 1"
proc gdb_start_again {} {
global srcdir
global subdir
global binfile
global gdb_prompt
global decimal
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
#
# set it up at a breakpoint so we can play with the variable values
#
if ![runto_main] then {
perror "couldn't run to breakpoint"
continue
}
if ![runto 'marker1'] then {
perror "couldn't run to marker1"
continue
}
gdb_test "up" ".*main.*" "up from marker1 2"
}
gdb_test "print s" ".\[0-9\]* = -1" "print value of s"
gdb_test "ptype s" "type = short"
gdb_test "print *ps" ".\[0-9\]* = -1" "print value of ps"
gdb_test "ptype ps" "type = short \\*"
gdb_test "print as\[0\]" ".\[0-9\]* = 0" "print value of as\[0\]"
gdb_test_multiple "ptype as" "ptype as" {
-re "type = short \\\[4\\\].*$gdb_prompt $" { pass "ptype as" }
-re "type = short int \\\[4\\\].*$gdb_prompt $" { pass "ptype as" }
}
gdb_test "print as\[1\]" ".\[0-9\]* = 1" "print value of as\[1\]"
gdb_test "print as\[2\]" ".\[0-9\]* = 2" "print value of as\[2\]"
gdb_test "print as\[3\]" ".\[0-9\]* = 3" "print value of as\[3\]"
gdb_test_multiple "print rs" "print value of rs" {
-re ".\[0-9\]* = \\(short &\\) @$hex: -1.*$gdb_prompt $" {
pass "print value of rs"
}
-re ".\[0-9\]* = \\(short int &\\) @$hex: -1.*$gdb_prompt $" {
pass "print value of rs"
}
eof { fail "print rs ($GDB dumped core) (FIXME)" ; gdb_start_again ; }
}
gdb_test_multiple "ptype rs" "ptype rs" {
-re "type = short &.*$gdb_prompt $" { pass "ptype rs" }
-re "type = short int &.*$gdb_prompt $" { pass "ptype rs" }
}
gdb_test "print *rps" ".\[0-9\]* = -1" "print value of *rps"
# GDB had a bug about dereferencing a pointer type
# that would lead to wrong results
# if we try to examine memory at pointer value.
gdb_test "x /hd rps" "$hex:\[ \t\]*-1" "examine value at rps"
gdb_test_multiple "ptype rps" "ptype rps" {
-re "type = short \\*&.*$gdb_prompt $" { pass "ptype rps" }
-re "type = short int \\*&.*$gdb_prompt $" { pass "ptype rps" }
}
gdb_test "print ras\[0\]" ".\[0-9\]* = 0" "print value of ras\[0\]"
gdb_test_multiple "ptype ras" "ptype ras" {
-re "type = short \\\(&\\\)\\\[4\\\].*$gdb_prompt $" { pass "ptype ras" }
-re "type = short int \\\(&\\\)\\\[4\\\].*$gdb_prompt $" { pass "ptype ras" }
}
gdb_test "print ras\[1\]" ".\[0-9\]* = 1" "print value of ras\[1\]"
gdb_test "print ras\[2\]" ".\[0-9\]* = 2" "print value of ras\[2\]"
gdb_test "print ras\[3\]" ".\[0-9\]* = 3" "print value of ras\[3\]"
if ![runto 'f'] then {
perror "couldn't run to f"
continue
}
gdb_test "up" ".main2.*" "up from f"
gdb_test "print C" ".\[0-9\]* = 65 \'A\'" "print value of C"
gdb_test "ptype C" "type = char"
gdb_test "print UC" ".\[0-9\]* = 21 '\.025'" "print value of UC"
gdb_test "ptype UC" "type = unsigned char"
gdb_test "print S" ".\[0-9\]* = -14" "print value of S"
gdb_test "ptype S" "type = short.*"
gdb_test "print US" ".\[0-9\]* = 7" "print value of US"
gdb_test_multiple "ptype US" "ptype US" {
-re "type = unsigned short.*$gdb_prompt $" { pass "ptype US" }
-re "type = short unsigned.*$gdb_prompt $" { pass "ptype US" }
}
gdb_test "print I" ".\[0-9\]* = 102" "print value of I"
gdb_test "ptype I" "type = int"
gdb_test "print UI" ".\[0-9\]* = 1002" "print value of UI"
gdb_test "ptype UI" "type = unsigned int"
gdb_test "print L" ".\[0-9\]* = -234" "print value of L"
gdb_test "ptype L" "type = long.*"
gdb_test "print UL" ".\[0-9\]* = 234" "print value of UL"
gdb_test_multiple "ptype UL" "ptype UL" {
-re "type = unsigned long.*$gdb_prompt $" { pass "ptype UL" }
-re "type = long unsigned.*$gdb_prompt $" { pass "ptype UL" }
}
gdb_test "print F" ".\[0-9\]* = 1.2\[0-9\]*e\\+0?10.*" \
"print value of F"
gdb_test "ptype F" "type = float.*"
gdb_test "print D" ".\[0-9\]* = -1.375e-123.*" \
"print value of D"
gdb_test "ptype D" "type = double.*"
#
# test reference types
#
gdb_test "ptype rC" "type = char &"
gdb_test "ptype rUC" "type = unsigned char &"
gdb_test_multiple "ptype rS" "ptype rS" {
-re "type = short &.*$gdb_prompt $" { pass "ptype rS" }
-re "type = short int &.*$gdb_prompt $" { pass "ptype rS" }
}
gdb_test_multiple "ptype rUS" "ptype rUS" {
-re "type = unsigned short &.*$gdb_prompt $" { pass "ptype rUS" }
-re "type = short unsigned int &.*$gdb_prompt $" { pass "ptype rUS" }
}
gdb_test "ptype rI" "type = int &"
gdb_test "ptype rUI" "type = unsigned int &"
gdb_test_multiple "ptype rL" "ptype rL" {
-re "type = long &.*$gdb_prompt $" { pass "ptype rL" }
-re "type = long int &.*$gdb_prompt $" { pass "ptype rL" }
}
gdb_test_multiple "ptype rUL" "ptype rUL" {
-re "type = unsigned long &.*$gdb_prompt $" { pass "ptype rUL" }
-re "type = long unsigned int &.*$gdb_prompt $" { pass "ptype rUL" }
}
gdb_test "ptype rF" "type = float &"
gdb_test "ptype rD" "type = double &"
gdb_test "print rC" ".\[0-9\]* = \\(char &\\) @$hex: 65 \'A\'" \
"print value of rC"
gdb_test "print rUC" \
".\[0-9\]* = \\(unsigned char &\\) @$hex: 21 \'.025\'" \
"print value of rUC"
gdb_test_multiple "print rS" "print value of rS" {
-re ".\[0-9\]* = \\(short &\\) @$hex: -14.*$gdb_prompt $" {
pass "print value of rS"
}
-re ".\[0-9\]* = \\(short int &\\) @$hex: -14.*$gdb_prompt $" {
pass "print value of rS"
}
}
gdb_test_multiple "print rUS" "print value of rUS" {
-re ".\[0-9\]* = \\(unsigned short &\\) @$hex: 7.*$gdb_prompt $" {
pass "print value of rUS"
}
-re ".\[0-9\]* = \\(short unsigned int &\\) @$hex: 7.*$gdb_prompt $" {
pass "print value of rUS"
}
}
gdb_test "print rI" ".\[0-9\]* = \\(int &\\) @$hex: 102" \
"print value of rI"
gdb_test "print rUI" \
".\[0-9\]* = \\(unsigned int &\\) @$hex: 1002" \
"print value of UI"
gdb_test_multiple "print rL" "print value of rL" {
-re ".\[0-9\]* = \\(long &\\) @$hex: -234.*$gdb_prompt $" {
pass "print value of rL"
}
-re ".\[0-9\]* = \\(long int &\\) @$hex: -234.*$gdb_prompt $" {
pass "print value of rL"
}
}
gdb_test_multiple "print rUL" "print value of rUL" {
-re ".\[0-9\]* = \\(unsigned long &\\) @$hex: 234.*$gdb_prompt $" {
pass "print value of rUL"
}
-re ".\[0-9\]* = \\(long unsigned int &\\) @$hex: 234.*$gdb_prompt $" {
pass "print value of rUL"
}
}
gdb_test "print rF" \
".\[0-9\]* = \\(float &\\) @$hex: 1.2\[0-9\]*e\\+0?10.*" \
"print value of rF"
gdb_test "print rD" \
".\[0-9\]* = \\(double &\\) @$hex: -1.375e-123.*" \
"print value of rD"
|