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