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