1# Tests for reference types with short type variables in GDB.
2# Copyright 1998-2023 Free Software Foundation, Inc.
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
6# the Free Software Foundation; either version 3 of the License, or
7# (at your option) any later version.
8#
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.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17# written by Elena Zannoni (ezannoni@cygnus.com)
18
19#
20# test running programs
21#
22
23if { [skip_cplus_tests] } { return }
24
25standard_testfile .cc
26
27if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
28    return -1
29}
30
31#
32# set it up at a breakpoint so we can play with the variable values
33#
34if {![runto_main]} {
35    return
36}
37
38if {![runto 'marker1']} {
39    return
40}
41
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
55    #
56    # set it up at a breakpoint so we can play with the variable values
57    #
58    if {![runto_main]} {
59	return
60    }
61
62    if {![runto 'marker1']} {
63	return
64    }
65
66    gdb_test "up" ".*main.*" "up from marker1 2"
67}
68
69
70gdb_test "print s" ".\[0-9\]* = -1" "print value of s"
71gdb_test "ptype s" "type = short"
72
73gdb_test "print *ps" ".\[0-9\]* = -1" "print value of ps"
74gdb_test "ptype ps" "type = short \\*"
75
76gdb_test "print as\[0\]" ".\[0-9\]* = 0" "print value of as\[0\]"
77gdb_test_multiple "ptype as" "ptype as" {
78    -re "type = short \\\[4\\\].*$gdb_prompt $"  { pass "ptype as" }
79    -re "type = short int \\\[4\\\].*$gdb_prompt $"  { pass "ptype as" }
80}
81
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" {
87    -re ".\[0-9\]* = \\(short &\\) @$hex: -1.*$gdb_prompt $" {
88        pass "print value of rs"
89    }
90    -re ".\[0-9\]* = \\(short int &\\) @$hex: -1.*$gdb_prompt $" {
91        pass "print value of rs"
92    }
93    eof { fail "print rs ($GDB dumped core) (FIXME)" ; gdb_start_again ; }
94}
95
96gdb_test_multiple "ptype rs" "ptype rs" {
97    -re "type = short &.*$gdb_prompt $"  { pass "ptype rs" }
98    -re "type = short int &.*$gdb_prompt $"  { pass "ptype rs" }
99}
100
101gdb_test "print *rps" ".\[0-9\]* = -1" "print value of *rps"
102
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"
108
109gdb_test_multiple "ptype rps" "ptype rps" {
110    -re "type = short \\*&.*$gdb_prompt $"  { pass "ptype rps" }
111    -re "type = short int \\*&.*$gdb_prompt $"  { pass "ptype rps" }
112}
113
114
115gdb_test "print ras\[0\]" ".\[0-9\]* = 0" "print value of ras\[0\]"
116
117gdb_test_multiple "ptype ras" "ptype ras" {
118    -re "type = short \\\(&\\\)\\\[4\\\].*$gdb_prompt $"  { pass "ptype ras" }
119    -re "type = short int \\\(&\\\)\\\[4\\\].*$gdb_prompt $"  { pass "ptype ras" }
120}
121
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\]"
125
126
127if {![runto 'f']} {
128    return
129}
130
131gdb_test "up" ".main2.*" "up from f"
132
133gdb_test "print C" ".\[0-9\]* = 65 \'A\'" "print value of C"
134gdb_test "ptype C" "type = char"
135
136gdb_test "print UC" ".\[0-9\]* = 21 '\.025'" "print value of UC"
137gdb_test "ptype UC" "type = unsigned char"
138
139gdb_test "print S" ".\[0-9\]* = -14" "print value of S"
140gdb_test "ptype S" "type = short.*"
141
142gdb_test "print US" ".\[0-9\]* = 7" "print value of US"
143gdb_test_multiple "ptype US" "ptype US" {
144    -re "type = unsigned short.*$gdb_prompt $"  { pass "ptype US" }
145    -re "type = short unsigned.*$gdb_prompt $"  { pass "ptype US" }
146}
147
148gdb_test "print I" ".\[0-9\]* = 102" "print value of I"
149gdb_test "ptype I" "type = int"
150
151gdb_test "print UI" ".\[0-9\]* = 1002" "print value of UI"
152gdb_test "ptype UI" "type = unsigned int"
153
154gdb_test "print L" ".\[0-9\]* = -234" "print value of L"
155gdb_test "ptype L" "type = long.*"
156
157gdb_test "print UL" ".\[0-9\]* = 234" "print value of UL"
158gdb_test_multiple "ptype UL" "ptype UL" {
159    -re "type = unsigned long.*$gdb_prompt $"  { pass "ptype UL" }
160    -re "type = long unsigned.*$gdb_prompt $"  { pass "ptype UL" }
161}
162
163gdb_test "print F" ".\[0-9\]* = 1.2\[0-9\]*e\\+0?10.*" \
164    "print value of F"
165
166gdb_test "ptype F" "type = float.*"
167
168gdb_test "print D" ".\[0-9\]* = -1.375e-123.*" \
169    "print value of D"
170
171gdb_test "ptype D" "type = double.*"
172
173
174#
175# test reference types
176#
177
178gdb_test "ptype rC" "type = char &"
179
180gdb_test "ptype rUC" "type = unsigned char &"
181
182gdb_test_multiple "ptype rS" "ptype rS" {
183    -re "type = short &.*$gdb_prompt $"  { pass "ptype rS" }
184    -re "type = short int &.*$gdb_prompt $"  { pass "ptype rS" }
185}
186
187gdb_test_multiple "ptype rUS" "ptype rUS" {
188    -re "type = unsigned short &.*$gdb_prompt $"  { pass "ptype rUS" }
189    -re "type = short unsigned int &.*$gdb_prompt $"  { pass "ptype rUS" }
190}
191
192gdb_test "ptype rI" "type = int &"
193
194gdb_test "ptype rUI" "type = unsigned int &"
195
196gdb_test_multiple "ptype rL" "ptype rL" {
197    -re "type = long &.*$gdb_prompt $"  { pass "ptype rL" }
198    -re "type = long int &.*$gdb_prompt $"  { pass "ptype rL" }
199}
200
201gdb_test_multiple "ptype rUL" "ptype rUL" {
202    -re "type = unsigned long &.*$gdb_prompt $"  { pass "ptype rUL" }
203    -re "type = long unsigned int &.*$gdb_prompt $"  { pass "ptype rUL" }
204}
205
206gdb_test "ptype rF" "type = float &"
207
208gdb_test "ptype rD" "type = double &"
209
210gdb_test "print rC" ".\[0-9\]* = \\(char &\\) @$hex: 65 \'A\'" \
211    "print value of rC"
212
213gdb_test "print rUC" \
214    ".\[0-9\]* = \\(unsigned char &\\) @$hex: 21 \'.025\'" \
215    "print value of rUC"
216
217gdb_test_multiple "print rS" "print value of rS" {
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    }
224}
225
226gdb_test_multiple "print rUS" "print value of rUS" {
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    }
233}
234
235gdb_test "print rI" ".\[0-9\]* = \\(int &\\) @$hex: 102" \
236	"print value of rI"
237
238gdb_test "print rUI" \
239    ".\[0-9\]* = \\(unsigned int &\\) @$hex: 1002" \
240        "print value of rUI"
241
242gdb_test_multiple "print rL" "print value of rL" {
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    }
249}
250
251gdb_test_multiple "print rUL" "print value of rUL" {
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    }
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"
267
268