OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.1/] [gdb/] [testsuite/] [gdb.base/] [pointers.exp] - Blame information for rev 252

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.