]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/pointers.exp
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / pointers.exp
CommitLineData
e2882c85 1# Copyright 1998-2018 Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
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.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 15
c906108c
SS
16# This file was written by Elena Zannoni (ezannoni@cygnus.com)
17
18# This file is part of the gdb testsuite
19#
20# tests for pointer arithmetic and pointer dereferencing
21# with integer type variables and pointers to integers
22#
23
c906108c
SS
24#
25# test running programs
26#
c906108c 27
822bd149 28standard_testfile .c
c906108c 29
fc91c6c2 30if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
84c93cd5 31 untested "failed to compile"
b60f0898 32 return -1
c906108c
SS
33 }
34
4c93b1db 35if [get_compiler_info] {
ae59b1da 36 return -1
085dd6e6 37}
c906108c 38
822bd149 39clean_restart ${binfile}
c906108c
SS
40
41
42#
43# set it up at a breakpoint so we can play with the variable values
44#
45
46if ![runto_main] then {
47 perror "couldn't run to breakpoint"
48 continue
49}
50
a0b3c4fd 51gdb_test "next " "more_code.*;" "continuing after dummy()"
c906108c
SS
52
53
54#
55# let's see if gdb catches some illegal operations on pointers
56#
57# I must comment these out because strict type checking is not
58# supported in this version of GDB. I do not really know
59# what the expected gdb reply is.
60#
61
62#send_gdb "print v_int_pointer2 = &v_int_pointer\n"
63#gdb_expect {
64# -re ".*.*$gdb_prompt $" {
65# pass "illegal pointer assignment rejected"
66# }
67# -re ".*$gdb_prompt $" { fail "illegal pointer assignment rejected" }
68# timeout { fail "(timeout) illegal pointer assignment rejected" }
69# }
70
71
72#send_gdb "print v_unsigned_int_pointer = &v_int\n"
73#gdb_expect {
74# -re ".*.*$gdb_prompt $" {
75# pass "illegal pointer assignment rejected"
76# }
77# -re ".*$gdb_prompt $" { fail "illegal pointer assignment rejected" }
78# timeout { fail "(timeout) ilegal pointer assignment rejected" }
79# }
80
81#send_gdb "print v_unsigned_int_pointer == v_double_pointer\n"
82#gdb_expect {
83# -re ".*.*$gdb_prompt $" {
84# pass "illegal pointer operation (+) rejected"
85# }
86# -re ".*$gdb_prompt $" { fail "illegal pointer operation (+) rejected" }
87# timeout { fail "(timeout) illegal pointer operation (+) rejected" }
88# }
89
90
91#send_gdb "print v_unsigned_int_pointer * v_double_pointer\n"
92#gdb_expect {
93# -re ".*Argument to arithmetic operation not a number or boolean.*$gdb_prompt $" {
94# pass "illegal pointer operation (*) rejected"
95# }
96# -re ".*$gdb_prompt $" { fail "illegal pointer operation (*) rejected" }
97# timeout { fail "(timeout) illegal pointer operation (*) rejected" }
98# }
99
100
101#send_gdb "print v_unsigned_int_pointer = v_double_pointer\n"
102#gdb_expect {
103# -re ".*.*$gdb_prompt $" {
104# pass "ilegal pointer assignment rejected"
105# }
106# -re ".*$gdb_prompt $" { fail "illegal pointer assignment rejected" }
107# timeout { fail "(timeout) illegal pointer assignment rejected" }
108# }
109
110
111#send_gdb "print v_unsigned_int_pointer = v_unsigned_int\n"
112#gdb_expect {
113# -re ".*.*$gdb_prompt $" {
114# pass "illegal pointer assignment rejected"
115# }
116# -re ".*$gdb_prompt $" { fail "illegal pointer assignment rejected" }
117# timeout { fail "(timeout) illegal pointer assignment rejected" }
118# }
119
27d3a1a2
MS
120gdb_test_no_output "set variable v_int_pointer=&v_int_array\[0\]" \
121 "set pointer to beginning of array"
122gdb_test_no_output "set variable v_int_pointer2=&v_int_array\[1\]" \
123 "set pointer to end of array"
c906108c
SS
124
125
65731a6b 126gdb_test "print *v_int_pointer" " = 6" "print object pointed to"
c906108c 127
65731a6b 128gdb_test "print *v_int_pointer2" " = 18" "print object pointed to \#2"
c906108c 129
65731a6b
MS
130gdb_test "print v_int_pointer == v_int_pointer2" " = $false" \
131 "pointer1==pointer2"
132
133gdb_test "print v_int_pointer != v_int_pointer2" " = $true" \
134 "pointer1!=pointer2"
135
136gdb_test "print v_int_pointer <= v_int_pointer2" " = $true" \
137 "pointer1<=pointer2"
138
139gdb_test "print v_int_pointer >= v_int_pointer2" " = $false" \
140 "pointer1>=pointer2"
141
142gdb_test "print v_int_pointer < v_int_pointer2" " = $true" \
143 "pointer1<pointer2"
144
145gdb_test "print v_int_pointer > v_int_pointer2" " = $false" \
146 "pointer1>pointer2"
c906108c 147
27d3a1a2
MS
148gdb_test_no_output "set variable y = *v_int_pointer++" \
149 "set y = *v_int_pointer++"
65731a6b
MS
150gdb_test "print y" " = 6" "pointer assignment"
151gdb_test "print *v_int_pointer" " = 18" "and post-increment"
c906108c
SS
152
153
154
27d3a1a2
MS
155gdb_test_no_output "set variable y = *--v_int_pointer2" \
156 "set y = *--v_int_pointer2"
65731a6b
MS
157gdb_test "print y" " = 6" "pointer assignment"
158gdb_test "print *v_int_pointer2" " = 6" "and pre-decrement"
159
160
161
27d3a1a2 162gdb_test_no_output "set variable y =v_int_pointer-v_int_pointer2" \
65731a6b
MS
163 "set y =v_int_pointer-v_int_pointer2"
164gdb_test "print y" " = 1" "pointer1-pointer2"
165
166
27d3a1a2 167gdb_test_no_output "set variable v_int_pointer=v_int_array" \
65731a6b
MS
168 "set v_int_pointer=v_int_array"
169gdb_test "print *v_int_pointer" " = 6" \
170 "print array element through pointer"
171
172gdb_test "print *(v_int_pointer+1)" " = 18" \
173 "print array element through pointer \#2"
174
c906108c
SS
175
176# test print elements of array through pointers
177
65731a6b
MS
178gdb_test "print (*rptr)\[0\]" " = 0" \
179 "print array element through pointer \#3"
180
181gdb_test "print (*rptr)\[1\]" " = 1" \
182 "print array element through pointer \#4"
183
184gdb_test "print (*rptr)\[2\]" " = 2" \
185 "print array element through pointer \#5"
c906108c 186
27d3a1a2 187gdb_test_no_output "set variable rptr = rptr+1" "increment rptr"
c906108c 188
65731a6b
MS
189gdb_test "print (*rptr)\[0\]" " = 3" \
190 "print array element through pointer \#6"
adf40b2e 191
65731a6b
MS
192gdb_test "print (*rptr)\[1\]" " = 4" \
193 "print array element through pointer \#7"
adf40b2e 194
65731a6b
MS
195gdb_test "print (*rptr)\[2\]" " = 5" \
196 "print array element through pointer \#8"
adf40b2e 197
65731a6b
MS
198gdb_test "print *( *(matrix+1) +2)" " = 5" \
199 "print array element w/ pointer arithmetic"
adf40b2e 200
65731a6b
MS
201gdb_test "print **ptr_to_ptr_to_float" " = 100" \
202 "print through ptr to ptr"
adf40b2e 203
65731a6b
MS
204# tests for pointers
205# with elementary type variables and pointers.
206#
adf40b2e 207
de7ff789 208gdb_test "break marker1" ".*" ""
65731a6b
MS
209gdb_test "cont" "Break.* marker1 \\(\\) at .*:$decimal.*" \
210 continue to marker1"
211gdb_test "up" "more_code.*" "up from marker1"
212
213gdb_test "print *pUC" " = 21 \'.025\'.*" "print value of *pUC"
adf40b2e 214
65731a6b 215gdb_test "ptype pUC" "type = unsigned char \\*" "ptype pUC"
adf40b2e 216
65731a6b 217gdb_test "print *pS" " = -14" "print value of *pS"
adf40b2e 218
65731a6b 219gdb_test_multiple "ptype pS" "ptype pS" {
adf40b2e
JM
220 -re "type = short \\*.*$gdb_prompt $" { pass "ptype pS" }
221 -re "type = short int \\*.*$gdb_prompt $" { pass "ptype pS" }
65731a6b 222}
adf40b2e 223
65731a6b 224gdb_test "print *pUS" " = 7" "print value of *pUS"
adf40b2e 225
65731a6b 226gdb_test_multiple "ptype pUS" "ptype pUS" {
adf40b2e
JM
227 -re "type = unsigned short \\*.*$gdb_prompt $" { pass "ptype pUS" }
228 -re "type = short unsigned int \\*.*$gdb_prompt $" { pass "ptype pUS" }
adf40b2e
JM
229}
230
65731a6b 231gdb_test "print *pI" " = 102" "print value of *pI"
adf40b2e 232
65731a6b 233gdb_test "ptype pI" "type = int \\*" "ptype pI"
adf40b2e 234
65731a6b
MS
235gdb_test "print *pUI" " = 1002" "print value of *pUI"
236
237gdb_test "ptype pUI" "type = unsigned int \\*" "ptype pUI"
238
239gdb_test "print *pL" " = -234" "print value of *pL"
adf40b2e 240
65731a6b
MS
241gdb_test_multiple "ptype pL" "ptype pL" {
242 -re "type = long \\*.*$gdb_prompt $" { pass "ptype pL" }
243 -re "type = long int \\*.*$gdb_prompt $" { pass "ptype pL" }
244}
adf40b2e 245
65731a6b 246gdb_test "print *pUL" " = 234" "print value of *pUL"
adf40b2e 247
65731a6b 248gdb_test_multiple "ptype pUL" "ptype pUL" {
adf40b2e
JM
249 -re "type = unsigned long \\*.*$gdb_prompt $" { pass "ptype pUL" }
250 -re "type = long unsigned int \\*.*$gdb_prompt $" { pass "ptype pUL" }
adf40b2e
JM
251}
252
65731a6b 253gdb_test "print *pF" " = 1.2\[0-9\]*e\\+0?10" "print value of *pF"
adf40b2e 254
65731a6b 255gdb_test "ptype pF" "type = float \\*" "ptype pF"
adf40b2e 256
65731a6b 257gdb_test "print *pD" " = -1.2\[0-9\]*e\\-0?37" "print value of *pD"
adf40b2e 258
65731a6b 259gdb_test "ptype pD" "type = double \\*" "ptype pD"
adf40b2e 260
65731a6b
MS
261gdb_test "print ******ppppppC" " = 65 \'A\'" \
262 "print value of ******ppppppC"
adf40b2e 263
65731a6b 264gdb_test "ptype pC" "type = char \\*" "ptype pC"
adf40b2e 265
65731a6b 266gdb_test "ptype ppC" "type = char \\*\\*" "ptype ppC"
adf40b2e 267
65731a6b
MS
268gdb_test "ptype pppC" "type = char \\*\\*\\*" "ptype pppC"
269
270gdb_test "ptype ppppC" "type = char \\*\\*\\*\\*" "ptype ppppC"
271
272gdb_test "ptype pppppC" "type = char \\*\\*\\*\\*\\*" "ptype pppppC"
273
274gdb_test "ptype ppppppC" "type = char \\*\\*\\*\\*\\*\\*" "ptype ppppppC"
adf40b2e 275
f3134b88
TT
276# Regression test for a crash.
277
278gdb_test "p instance.array_variable + 0" \
9cb709b6 279 " = \\(long (int )?\\*\\) 0x\[0-9a-f\]* <instance>"