]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/pointers.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / pointers.exp
CommitLineData
6aba47ca 1# Copyright 1998, 1999, 2000, 2007 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
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# This file was written by Elena Zannoni (ezannoni@cygnus.com)
21
22# This file is part of the gdb testsuite
23#
24# tests for pointer arithmetic and pointer dereferencing
25# with integer type variables and pointers to integers
26#
27
28if $tracelevel then {
29 strace $tracelevel
30 }
31
32#
33# test running programs
34#
35set prms_id 0
36set bug_id 0
37
38set testfile "pointers"
39set srcfile ${testfile}.c
40set binfile ${objdir}/${subdir}/${testfile}
41
fc91c6c2 42if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
43 untested pointers.exp
44 return -1
c906108c
SS
45 }
46
085dd6e6
JM
47if [get_compiler_info ${binfile}] {
48 return -1;
49}
c906108c
SS
50
51gdb_exit
52gdb_start
53gdb_reinitialize_dir $srcdir/$subdir
54gdb_load ${binfile}
55
56
57#
58# set it up at a breakpoint so we can play with the variable values
59#
60
61if ![runto_main] then {
62 perror "couldn't run to breakpoint"
63 continue
64}
65
a0b3c4fd 66gdb_test "next " "more_code.*;" "continuing after dummy()"
c906108c
SS
67
68
69#
70# let's see if gdb catches some illegal operations on pointers
71#
72# I must comment these out because strict type checking is not
73# supported in this version of GDB. I do not really know
74# what the expected gdb reply is.
75#
76
77#send_gdb "print v_int_pointer2 = &v_int_pointer\n"
78#gdb_expect {
79# -re ".*.*$gdb_prompt $" {
80# pass "illegal pointer assignment rejected"
81# }
82# -re ".*$gdb_prompt $" { fail "illegal pointer assignment rejected" }
83# timeout { fail "(timeout) illegal pointer assignment rejected" }
84# }
85
86
87#send_gdb "print v_unsigned_int_pointer = &v_int\n"
88#gdb_expect {
89# -re ".*.*$gdb_prompt $" {
90# pass "illegal pointer assignment rejected"
91# }
92# -re ".*$gdb_prompt $" { fail "illegal pointer assignment rejected" }
93# timeout { fail "(timeout) ilegal pointer assignment rejected" }
94# }
95
96#send_gdb "print v_unsigned_int_pointer == v_double_pointer\n"
97#gdb_expect {
98# -re ".*.*$gdb_prompt $" {
99# pass "illegal pointer operation (+) rejected"
100# }
101# -re ".*$gdb_prompt $" { fail "illegal pointer operation (+) rejected" }
102# timeout { fail "(timeout) illegal pointer operation (+) rejected" }
103# }
104
105
106#send_gdb "print v_unsigned_int_pointer * v_double_pointer\n"
107#gdb_expect {
108# -re ".*Argument to arithmetic operation not a number or boolean.*$gdb_prompt $" {
109# pass "illegal pointer operation (*) rejected"
110# }
111# -re ".*$gdb_prompt $" { fail "illegal pointer operation (*) rejected" }
112# timeout { fail "(timeout) illegal pointer operation (*) rejected" }
113# }
114
115
116#send_gdb "print v_unsigned_int_pointer = v_double_pointer\n"
117#gdb_expect {
118# -re ".*.*$gdb_prompt $" {
119# pass "ilegal pointer assignment rejected"
120# }
121# -re ".*$gdb_prompt $" { fail "illegal pointer assignment rejected" }
122# timeout { fail "(timeout) illegal pointer assignment rejected" }
123# }
124
125
126#send_gdb "print v_unsigned_int_pointer = v_unsigned_int\n"
127#gdb_expect {
128# -re ".*.*$gdb_prompt $" {
129# pass "illegal pointer assignment rejected"
130# }
131# -re ".*$gdb_prompt $" { fail "illegal pointer assignment rejected" }
132# timeout { fail "(timeout) illegal pointer assignment rejected" }
133# }
134
135gdb_test "set variable v_int_pointer=&v_int_array\[0\]" "" "set pointer to beginning of array"
136gdb_test "set variable v_int_pointer2=&v_int_array\[1\]" "" "set pointer to end of array"
137
138
139send_gdb "print *v_int_pointer\n"
140gdb_expect {
141 -re ".*= 6.*$gdb_prompt $" {
142 pass "print object pointed to"
143 }
144 -re ".*$gdb_prompt $" { fail "print object pointed to" }
145 timeout { fail "(timeout) print object pointed to" }
146 }
147
148send_gdb "print *v_int_pointer2\n"
149gdb_expect {
150 -re ".*= 18.*$gdb_prompt $" {
151 pass "print object pointed to"
152 }
153 -re ".*$gdb_prompt $" { fail "print object pointed to" }
154 timeout { fail "(timeout) print object pointed to" }
155 }
156
157
158send_gdb "print v_int_pointer == v_int_pointer2\n"
159gdb_expect {
085dd6e6 160 -re ".*= $false.*$gdb_prompt $" {
c906108c
SS
161 pass "pointer1==pointer2"
162 }
163 -re ".*$gdb_prompt $" { fail "pointer1==pointer2" }
164 timeout { fail "(timeout) pointer1==pointer2" }
165 }
166
167send_gdb "print v_int_pointer != v_int_pointer2\n"
168gdb_expect {
085dd6e6 169 -re ".*= $true.*$gdb_prompt $" {
c906108c
SS
170 pass "pointer1!=pointer2"
171 }
172 -re ".*$gdb_prompt $" { fail "pointer1!=pointer2" }
173 timeout { fail "(timeout) pointer1!=pointer2" }
174 }
175
176
177send_gdb "print v_int_pointer <= v_int_pointer2\n"
178gdb_expect {
085dd6e6 179 -re ".*= $true.*$gdb_prompt $" {
c906108c
SS
180 pass "pointer1<=pointer2"
181 }
182 -re ".*$gdb_prompt $" { fail "pointer1<=pointer2" }
183 timeout { fail "(timeout) pointer1<=pointer2" }
184 }
185
186
187send_gdb "print v_int_pointer >= v_int_pointer2\n"
188gdb_expect {
085dd6e6 189 -re ".*= $false.*$gdb_prompt $" {
c906108c
SS
190 pass "pointer1>=pointer2"
191 }
192 -re ".*$gdb_prompt $" { fail "pointer1>=pointer2" }
193 timeout { fail "(timeout) pointer1>=pointer2" }
194 }
195
196
197send_gdb "print v_int_pointer < v_int_pointer2\n"
198gdb_expect {
085dd6e6 199 -re ".*= $true.*$gdb_prompt $" {
c906108c
SS
200 pass "pointer1<pointer2"
201 }
202 -re ".*$gdb_prompt $" { fail "pointer1<pointer2" }
203 timeout { fail "(timeout) pointer1<pointer2" }
204 }
205
206send_gdb "print v_int_pointer > v_int_pointer2\n"
207gdb_expect {
085dd6e6 208 -re ".*= $false.*$gdb_prompt $" {
c906108c
SS
209 pass "pointer1>pointer2"
210 }
211 -re ".*$gdb_prompt $" { fail "pointer1>pointer2" }
212 timeout { fail "(timeout) pointer1>pointer2" }
213 }
214
215
216gdb_test "set variable y = *v_int_pointer++" "" "set y = *v_int_pointer++"
217send_gdb "print y\n"
218gdb_expect {
219 -re ".*= 6.*$gdb_prompt $" {
220 send_gdb "print *v_int_pointer\n"
221 gdb_expect {
222 -re ".*= 18.*$gdb_prompt $" {
223 pass "pointer assignment and increment"
224 }
225 -re ".*$gdb_prompt $" { fail "pointer assignment and increment" }
226 timeout { fail "(timeout) pointer assignment and increment" }
227 }
228 }
229 -re ".*$gdb_prompt $" { fail "pointer assignment and increment" }
230 timeout { fail "(timeout) pointer assignment and increment" }
231 }
232
233
234
235
236gdb_test "set variable y = *--v_int_pointer2" "" "set y = *--v_int_pointer2"
237send_gdb "print y\n"
238gdb_expect {
239 -re ".*= 6.*$gdb_prompt $" {
240 send_gdb "print *v_int_pointer2\n"
241 gdb_expect {
242 -re ".*= 6.*$gdb_prompt $" {
243 pass "pointer decrement and assignment"
244 }
245 -re ".*$gdb_prompt $" { fail "pointer decrement and assignment" }
246 timeout { fail "(timeout) pointer decrement and assignment" }
247 }
248 }
249 -re ".*$gdb_prompt $" { fail "pointer decrement and assignment" }
250 timeout { fail "(timeout) pointer decrement and assignment" }
251 }
252
253gdb_test "set variable y =v_int_pointer-v_int_pointer2" "" "set y =v_int_pointer-v_int_pointer2"
254send_gdb "print y\n"
255gdb_expect {
256 -re ".*= 1.*$gdb_prompt $" {
257 pass "pointer1-pointer2"
258 }
259 -re ".*$gdb_prompt $" { fail "pointer1-pointer2" }
260 timeout { fail "(timeout) pointer1-pointer2" }
261 }
262
263gdb_test "set variable v_int_pointer=v_int_array" "" "set v_int_pointer=v_int_array"
264send_gdb "print *v_int_pointer\n"
265gdb_expect {
266 -re ".*= 6.*$gdb_prompt $" {
267 pass "print array element through pointer"
268 }
269 -re ".*$gdb_prompt $" { fail "print array element through pointer" }
270 timeout { fail "(timeout) print array element through pointer" }
271 }
272
273
274send_gdb "print *(v_int_pointer+1)\n"
275gdb_expect {
276 -re ".*= 18.*$gdb_prompt $" {
277 pass "print array element through pointer"
278 }
279 -re ".*$gdb_prompt $" { fail "print array element through pointer" }
280 timeout { fail "(timeout) print array element through pointer" }
281 }
282
283# test print elements of array through pointers
284
285send_gdb "print (*rptr)\[0\]\n"
286gdb_expect {
287 -re ".*= 0.*$gdb_prompt $" {
288 pass "print array element through pointer"
289 }
290 -re ".*$gdb_prompt $" { fail "print array element through pointer" }
291 timeout { fail "(timeout) print array element through pointer" }
292 }
293
294send_gdb "print (*rptr)\[1\]\n"
295gdb_expect {
296 -re ".*= 1.*$gdb_prompt $" {
297 pass "print array element through pointer"
298 }
299 -re ".*$gdb_prompt $" { fail "print array element through pointer" }
300 timeout { fail "(timeout) print array element through pointer" }
301 }
302
303
304send_gdb "print (*rptr)\[2\]\n"
305gdb_expect {
306 -re ".*= 2.*$gdb_prompt $" {
307 pass "print array element through pointer"
308 }
309 -re ".*$gdb_prompt $" { fail "print array element through pointer" }
310 timeout { fail "(timeout) print array element through pointer" }
311 }
312
313gdb_test "set variable rptr = rptr+1" "" "increment rptr"
314
315send_gdb "print (*rptr)\[0\]\n"
316gdb_expect {
317 -re ".*= 3.*$gdb_prompt $" {
318 pass "print array element through pointer"
319 }
320 -re ".*$gdb_prompt $" { fail "print array element through pointer" }
321 timeout { fail "(timeout) print array element through pointer" }
322 }
323
324
325send_gdb "print (*rptr)\[1\]\n"
326gdb_expect {
327 -re ".*= 4.*$gdb_prompt $" {
328 pass "print array element through pointer"
329 }
330 -re ".*$gdb_prompt $" { fail "print array element through pointer" }
331 timeout { fail "(timeout) print array element through pointer" }
332 }
333
334
335send_gdb "print (*rptr)\[2\]\n"
336gdb_expect {
337 -re ".*= 5.*$gdb_prompt $" {
338 pass "print array element through pointer"
339 }
340 -re ".*$gdb_prompt $" { fail "print array element through pointer" }
341 timeout { fail "(timeout) print array element through pointer" }
342 }
343
344
345send_gdb "print *( *(matrix+1) +2)\n"
346gdb_expect {
347 -re ".*= 5.*$gdb_prompt $" {
348 pass "print array element w/ pointer arithmetic"
349 }
350 -re ".*$gdb_prompt $" { fail "print array element w/ pointer arithemtic" }
351 timeout { fail "(timeout) print array element w/ pointer arithmetic" }
352 }
353
354
355send_gdb "print **ptr_to_ptr_to_float\n"
356gdb_expect {
357 -re ".*= 100.*$gdb_prompt $" {
358 pass "print through ptr to ptr"
359 }
360 -re ".*$gdb_prompt $" { fail "print through ptr to ptr" }
361 timeout { fail "(timeout) print through ptr to ptr" }
362 }
adf40b2e
JM
363
364# tests for pointers
365# with elementary type variables and pointers.
366#
367
368send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
369
ed4c619a
AC
370send_gdb "cont\n"
371gdb_expect {
372 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
373 pass "continue to marker1"
374 send_gdb "up\n"
375 gdb_expect {
376 -re ".*more_code.*$gdb_prompt $" {
377 pass "up from marker1"
378 }
379 -re ".*$gdb_prompt $" {
380 fail "up from marker1"
381 }
382 timeout { fail "up from marker1 (timeout)" }
383 }
384 }
385 -re "$gdb_prompt $" {
386 fail "continue to marker1"
adf40b2e 387 }
ed4c619a
AC
388 timeout {
389 fail "continue to marker1 (timeout)"
390 }
391}
adf40b2e
JM
392
393
394send_gdb "print *pUC\n"
395gdb_expect {
396 -re ".\[0-9\]* = 21 \'.025\'.*$gdb_prompt $" {
397 pass "print value of *pUC"
398 }
399 -re ".*$gdb_prompt $" { fail "print value of *pUC" }
400 timeout { fail "(timeout) print value of *pUC" }
401 }
402
403
404send_gdb "ptype pUC\n"
405gdb_expect {
406 -re "type = unsigned char \\*.*$gdb_prompt $" { pass "ptype pUC" }
407 -re ".*$gdb_prompt $" { fail "ptype pUC" }
408 timeout { fail "(timeout) ptype pUC" }
409}
410
411send_gdb "print *pS\n"
412gdb_expect {
413 -re ".\[0-9\]* = -14.*$gdb_prompt $" {
414 pass "print value of *pS"
415 }
416 -re ".*$gdb_prompt $" { fail "print value of *pS" }
417 timeout { fail "(timeout) print value of *pS" }
418 }
419
420
421send_gdb "ptype pS\n"
422gdb_expect {
423 -re "type = short \\*.*$gdb_prompt $" { pass "ptype pS" }
424 -re "type = short int \\*.*$gdb_prompt $" { pass "ptype pS" }
425 -re ".*$gdb_prompt $" { fail "ptype pS" }
426 timeout { fail "(timeout) ptype pS" }
427}
428
429send_gdb "print *pUS\n"
430gdb_expect {
431 -re ".\[0-9\]* = 7.*$gdb_prompt $" {
432 pass "print value of *pUS"
433 }
434 -re ".*$gdb_prompt $" { fail "print value of *pUS" }
435 timeout { fail "(timeout) print value of *pUS" }
436 }
437
438
439send_gdb "ptype pUS\n"
440gdb_expect {
441 -re "type = unsigned short \\*.*$gdb_prompt $" { pass "ptype pUS" }
442 -re "type = short unsigned int \\*.*$gdb_prompt $" { pass "ptype pUS" }
443 -re ".*$gdb_prompt $" { fail "ptype pUS" }
444 timeout { fail "(timeout) ptype pUS" }
445}
446
447send_gdb "print *pI\n"
448gdb_expect {
449 -re ".\[0-9\]* = 102.*$gdb_prompt $" {
450 pass "print value of *pI"
451 }
452 -re ".*$gdb_prompt $" { fail "print value of *pI" }
453 timeout { fail "(timeout) print value of *pI" }
454 }
455
456
457send_gdb "ptype pI\n"
458gdb_expect {
459 -re "type = int \\*.*$gdb_prompt $" { pass "ptype pI" }
460 -re ".*$gdb_prompt $" { fail "ptype pI" }
461 timeout { fail "(timeout) ptype pI" }
462}
463
464send_gdb "print *pUI\n"
465gdb_expect {
466 -re ".\[0-9\]* = 1002.*$gdb_prompt $" {
467 pass "print value of *pUI"
468 }
469 -re ".*$gdb_prompt $" { fail "print value of *pUI" }
470 timeout { fail "(timeout) print value of *pUI" }
471 }
472
473
474send_gdb "ptype pUI\n"
475gdb_expect {
476 -re "type = unsigned int \\*.*$gdb_prompt $" { pass "ptype pUI" }
477 -re ".*$gdb_prompt $" { fail "ptype pUI" }
478 timeout { fail "(timeout) ptype pUI" }
479}
480
481send_gdb "print *pL\n"
482gdb_expect {
483 -re ".\[0-9\]* = -234.*$gdb_prompt $" {
484 pass "print value of *pL"
485 }
486 -re ".*$gdb_prompt $" { fail "print value of *pL" }
487 timeout { fail "(timeout) print value of *pL" }
488 }
489
490
491send_gdb "ptype pL\n"
492gdb_expect {
493 -re "type = long \\*.*$gdb_prompt $" { pass "ptype pL" }
494 -re "type = long int \\*.*$gdb_prompt $" { pass "ptype pL" }
495 -re ".*$gdb_prompt $" { fail "ptype pL" }
496 timeout { fail "(timeout) ptype pL" }
497}
498
499send_gdb "print *pUL\n"
500gdb_expect {
501 -re ".\[0-9\]* = 234.*$gdb_prompt $" {
502 pass "print value of *pUL"
503 }
504 -re ".*$gdb_prompt $" { fail "print value of *pUL" }
505 timeout { fail "(timeout) print value of *pUL" }
506 }
507
508
509send_gdb "ptype pUL\n"
510gdb_expect {
511 -re "type = unsigned long \\*.*$gdb_prompt $" { pass "ptype pUL" }
512 -re "type = long unsigned int \\*.*$gdb_prompt $" { pass "ptype pUL" }
513 -re ".*$gdb_prompt $" { fail "ptype pUL" }
514 timeout { fail "(timeout) ptype pUL" }
515}
516
517send_gdb "print *pF\n"
518gdb_expect {
519 -re ".\[0-9\]* = 1.2\[0-9\]*e\\+10.*$gdb_prompt $" {
520 pass "print value of *pF"
521 }
522 -re ".*$gdb_prompt $" { fail "print value of *pF" }
523 timeout { fail "(timeout) print value of *pF" }
524 }
525
526
527send_gdb "ptype pF\n"
528gdb_expect {
529 -re "type = float \\*.*$gdb_prompt $" { pass "ptype pF" }
530 -re ".*$gdb_prompt $" { fail "ptype pF" }
531 timeout { fail "(timeout) ptype pF" }
532}
533
534send_gdb "print *pD\n"
535gdb_expect {
1b3c5540 536 -re ".\[0-9\]* = -1.2\[0-9\]*e\\-37.*$gdb_prompt $" {
adf40b2e
JM
537 pass "print value of *pD"
538 }
539 -re ".*$gdb_prompt $" { fail "print value of *pD" }
540 timeout { fail "(timeout) print value of *pD" }
541 }
542
543
544send_gdb "ptype pD\n"
545gdb_expect {
546 -re "type = double \\*.*$gdb_prompt $" { pass "ptype pD" }
547 -re ".*$gdb_prompt $" { fail "ptype pD" }
548 timeout { fail "(timeout) ptype pD" }
549}
550
551send_gdb "print ******ppppppC\n"
552gdb_expect {
553 -re ".\[0-9\]* = 65 \'A\'.*$gdb_prompt $" {
554 pass "print value of ******ppppppC"
555 }
556 -re ".*$gdb_prompt $" { fail "print value of ******ppppppC" }
557 timeout { fail "(timeout) print value of ******ppppppC" }
558 }
559
560
561send_gdb "ptype pC\n"
562gdb_expect {
563 -re "type = char \\*.*$gdb_prompt $" { pass "ptype pC" }
564 -re ".*$gdb_prompt $" { fail "ptype pC" }
565 timeout { fail "(timeout) ptype pC" }
566}
567
568send_gdb "ptype ppC\n"
569gdb_expect {
570 -re "type = char \\*\\*.*$gdb_prompt $" { pass "ptype ppC" }
571 -re ".*$gdb_prompt $" { fail "ptype ppC" }
572 timeout { fail "(timeout) ptype ppC" }
573}
574
575send_gdb "ptype pppC\n"
576gdb_expect {
ed4c619a 577 -re "type = char \\*\\*\\*.*$gdb_prompt $" { pass "ptype pppC" }
adf40b2e
JM
578 -re ".*$gdb_prompt $" { fail "ptype pppC" }
579 timeout { fail "(timeout) ptype pppC" }
580}
581
582send_gdb "ptype ppppC\n"
583gdb_expect {
584 -re "type = char \\*\\*\\*\\*.*$gdb_prompt $" { pass "ptype ppppC" }
585 -re ".*$gdb_prompt $" { fail "ptype ppppC" }
586 timeout { fail "(timeout) ptype ppppC" }
587}
588
589send_gdb "ptype pppppC\n"
590gdb_expect {
591 -re "type = char \\*\\*\\*\\*\\*.*$gdb_prompt $" { pass "ptype pppppC" }
592 -re ".*$gdb_prompt $" { fail "ptype pppppC" }
593 timeout { fail "(timeout) ptype pppppC" }
594}
595
596send_gdb "ptype ppppppC\n"
597gdb_expect {
598 -re "type = char \\*\\*\\*\\*\\*\\*.*$gdb_prompt $" { pass "ptype ppppppC" }
599 -re ".*$gdb_prompt $" { fail "ptype ppppppC" }
600 timeout { fail "(timeout) ptype ppppppC" }
601}
602