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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [gdb/] [testsuite/] [gdb.base/] [dump.exp] - Blame information for rev 828

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

Line No. Rev Author Line
1 227 jeremybenn
# Copyright 2002, 2004, 2007, 2008, 2009, 2010 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 3 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, see .
15
 
16
# This file was written by Michael Snyder (msnyder@redhat.com)
17
# This is a test for the gdb command "dump".
18
 
19
if $tracelevel then {
20
        strace $tracelevel
21
}
22
 
23
set prms_id 0
24
set bug_id 0
25
 
26
set testfile "dump"
27
 
28
set srcfile  ${testfile}.c
29
set binfile  ${objdir}/${subdir}/${testfile}
30
set options  {debug}
31
 
32
set is64bitonly "no"
33
set endian "auto"
34
 
35
if [istarget "alpha*-*-*"] then {
36
    # SREC etc cannot handle 64-bit addresses.  Force the test
37
    # program into the low 31 bits of the address space.
38
    lappend options "additional_flags=-Wl,-taso"
39
}
40
 
41
if {[istarget "ia64*-*-*"] || [istarget "hppa64-*-*"]} then {
42
    set is64bitonly "yes"
43
}
44
 
45
if {[istarget "spu*-*-*"]} then {
46
    # The internal address format used for the combined Cell/B.E.
47
    # debugger requires 64-bit.
48
    set is64bitonly "yes"
49
}
50
 
51
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable ${options}] != "" } {
52
     untested dump.exp
53
     return -1
54
}
55
 
56
# Start with a fresh gdb.
57
 
58
gdb_exit
59
gdb_start
60
gdb_reinitialize_dir $srcdir/$subdir
61
 
62
gdb_test "dump mem /dev/null 0x10 0x20" "Cannot access memory at address 0x10" \
63
         "inaccessible memory is reported"
64
 
65
gdb_load ${binfile}
66
 
67
# Clean up any stale output files from previous test runs
68
 
69
remote_exec build "rm -f intarr1.bin intarr1b.bin intarr1.ihex intarr1.srec intarr1.tekhex intarr2.bin intarr2b.bin intarr2.ihex intarr2.srec intarr2.tekhex intstr1.bin intstr1b.bin intstr1.ihex intstr1.srec intstr1.tekhex intstr2.bin intstr2b.bin intstr2.ihex intstr2.srec intstr2.tekhex intarr3.srec"
70
 
71
# Test help (FIXME:)
72
 
73
# Run target program until data structs are initialized.
74
 
75
if { ! [ runto checkpoint1 ] } then {
76
    untested dump.exp
77
    return -1
78
}
79
 
80
# Get the endianness for the later use with endianless formats.
81
 
82
send_gdb "show endian\n"
83
gdb_expect {
84
    -re ".* (big|little) endian.*$gdb_prompt $" {
85
        set endian $expect_out(1,string)
86
        pass "endianness: $endian"
87
    }
88
    default {
89
        fail "(timeout) getting target endianness"
90
    }
91
}
92
 
93
# Now generate some dump files.
94
 
95
proc make_dump_file { command msg } {
96
  global gdb_prompt
97
 
98
    send_gdb "${command}\n"
99
    gdb_expect {
100
        -re ".*\[Ee\]rror.*$gdb_prompt $"      { fail $msg }
101
        -re ".*\[Ww\]arning.*$gdb_prompt $"    { fail $msg }
102
        -re ".*\[Uu\]ndefined .*$gdb_prompt $" { fail $msg }
103
        -re ".*$gdb_prompt $" { pass $msg }
104
        timeout                                { fail "$msg (timeout)" }
105
    }
106
}
107
 
108
make_dump_file "dump val intarr1.bin intarray" \
109
        "dump array as value, default"
110
 
111
make_dump_file "dump val intstr1.bin intstruct" \
112
        "dump struct as value, default"
113
 
114
make_dump_file "dump bin val intarr1b.bin intarray" \
115
        "dump array as value, binary"
116
 
117
make_dump_file "dump bin val intstr1b.bin intstruct" \
118
        "dump struct as value, binary"
119
 
120
make_dump_file "dump srec val intarr1.srec intarray" \
121
        "dump array as value, srec"
122
 
123
make_dump_file "dump srec val intstr1.srec intstruct" \
124
        "dump struct as value, srec"
125
 
126
make_dump_file "dump ihex val intarr1.ihex intarray" \
127
        "dump array as value, intel hex"
128
 
129
make_dump_file "dump ihex val intstr1.ihex intstruct" \
130
        "dump struct as value, intel hex"
131
 
132
make_dump_file "dump tekhex val intarr1.tekhex intarray" \
133
        "dump array as value, tekhex"
134
 
135
make_dump_file "dump tekhex val intstr1.tekhex intstruct" \
136
        "dump struct as value, tekhex"
137
 
138
proc capture_value { expression args } {
139
    global gdb_prompt
140
    global expect_out
141
 
142
    set output_string ""
143
    if {[llength $args] > 0} {
144
        # Convert $args into a simple string.
145
        set test "[join $args]; capture $expression"
146
    } {
147
        set test "capture $expression"
148
    }
149
    gdb_test_multiple "print ${expression}" "$test" {
150
        -re "\\$\[0-9\]+ = (\[^\r\n\]+).*$gdb_prompt $" {
151
            set output_string "$expect_out(1,string)"
152
            pass "$test"
153
        }
154
        -re "(Cannot access memory at address \[^\r\n\]+).*$gdb_prompt $" {
155
            # Even a failed value is valid
156
            set output_string "$expect_out(1,string)"
157
            pass "$test"
158
        }
159
    }
160
    return $output_string
161
}
162
 
163
set array_start  [capture_value "/x &intarray\[0\]"]
164
set array_end    [capture_value "/x &intarray\[32\]"]
165
set struct_start [capture_value "/x &intstruct"]
166
set struct_end   [capture_value "/x &intstruct + 1"]
167
 
168
set array_val    [capture_value "intarray"]
169
set struct_val   [capture_value "intstruct"]
170
 
171
make_dump_file "dump mem intarr2.bin $array_start $array_end" \
172
        "dump array as memory, default"
173
 
174
make_dump_file "dump  mem intstr2.bin $struct_start $struct_end" \
175
        "dump struct as memory, default"
176
 
177
make_dump_file "dump bin mem intarr2b.bin $array_start $array_end" \
178
        "dump array as memory, binary"
179
 
180
make_dump_file "dump bin mem intstr2b.bin $struct_start $struct_end" \
181
        "dump struct as memory, binary"
182
 
183
make_dump_file "dump srec mem intarr2.srec $array_start $array_end" \
184
        "dump array as memory, srec"
185
 
186
make_dump_file "dump srec mem intstr2.srec $struct_start $struct_end" \
187
        "dump struct as memory, srec"
188
 
189
make_dump_file "dump ihex mem intarr2.ihex $array_start $array_end" \
190
        "dump array as memory, ihex"
191
 
192
make_dump_file "dump ihex mem intstr2.ihex $struct_start $struct_end" \
193
        "dump struct as memory, ihex"
194
 
195
make_dump_file "dump tekhex mem intarr2.tekhex $array_start $array_end" \
196
        "dump array as memory, tekhex"
197
 
198
make_dump_file "dump tekhex mem intstr2.tekhex $struct_start $struct_end" \
199
        "dump struct as memory, tekhex"
200
 
201
# test complex expressions
202
make_dump_file \
203
        "dump srec mem intarr3.srec &intarray \(char *\) &intarray + sizeof intarray" \
204
        "dump array as mem, srec, expressions"
205
 
206
 
207
# Now start a fresh gdb session, and reload the saved value files.
208
 
209
gdb_exit
210
gdb_start
211
gdb_file_cmd ${binfile}
212
 
213
# Now fix the endianness at the correct state.
214
 
215
send_gdb "set endian $endian\n"
216
gdb_expect {
217
    -re ".* (big|little) endian.*$gdb_prompt $" {
218
        pass "setting $endian endianness"
219
    }
220
    default {
221
        fail "(timeout) setting $endian endianness"
222
    }
223
}
224
 
225
# Reload saved values one by one, and compare.
226
 
227
if { ![string compare $array_val \
228
           [capture_value "intarray" "file binfile"]] } then {
229
    fail "start with intarray un-initialized"
230
} else {
231
    pass "start with intarray un-initialized"
232
}
233
 
234
if { ![string compare $struct_val \
235
           [capture_value "intstruct" "file binfile"]] } then {
236
    fail "start with intstruct un-initialized"
237
} else {
238
    pass "start with intstruct un-initialized"
239
}
240
 
241
proc test_reload_saved_value { filename msg oldval newval } {
242
    global gdb_prompt
243
 
244
    gdb_file_cmd $filename
245
    if { ![string compare $oldval \
246
               [capture_value $newval "$msg"]] } then {
247
        pass "$msg; value restored ok"
248
    } else {
249
        fail "$msg; value restored ok"
250
    }
251
}
252
 
253
proc test_restore_saved_value { restore_args msg oldval newval } {
254
    global gdb_prompt
255
 
256
    gdb_test "restore $restore_args" \
257
        "Restoring .*" \
258
        "$msg; file restored ok"
259
    if { ![string compare $oldval \
260
               [capture_value $newval "$msg"]] } then {
261
        pass "$msg; value restored ok"
262
    } else {
263
        fail "$msg; value restored ok"
264
    }
265
}
266
 
267
# srec format can not be loaded for 64-bit-only platforms
268
if ![string compare $is64bitonly "no"] then {
269
  test_reload_saved_value "intarr1.srec" "reload array as value, srec" \
270
        $array_val "intarray"
271
  test_reload_saved_value "intstr1.srec" "reload struct as value, srec" \
272
        $struct_val "intstruct"
273
  test_reload_saved_value "intarr2.srec" "reload array as memory, srec" \
274
        $array_val "intarray"
275
  test_reload_saved_value "intstr2.srec" "reload struct as memory, srec" \
276
        $struct_val "intstruct"
277
}
278
 
279
# ihex format can not be loaded for 64-bit-only platforms
280
if ![string compare $is64bitonly "no"] then {
281
 
282
  test_reload_saved_value "intarr1.ihex" "reload array as value, intel hex" \
283
        $array_val "intarray"
284
  test_reload_saved_value "intstr1.ihex" "reload struct as value, intel hex" \
285
        $struct_val "intstruct"
286
  test_reload_saved_value "intarr2.ihex" "reload array as memory, intel hex" \
287
        $array_val "intarray"
288
  test_reload_saved_value "intstr2.ihex" "reload struct as memory, intel hex" \
289
        $struct_val "intstruct"
290
}
291
 
292
# tekhex format can not be loaded for 64-bit-only platforms
293
if ![string compare $is64bitonly "no"] then {
294
  test_reload_saved_value "intarr1.tekhex" "reload array as value, tekhex" \
295
        $array_val "intarray"
296
  test_reload_saved_value "intstr1.tekhex" "reload struct as value, tekhex" \
297
        $struct_val "intstruct"
298
  test_reload_saved_value "intarr2.tekhex" "reload array as memory, tekhex" \
299
        $array_val "intarray"
300
  test_reload_saved_value "intstr2.tekhex" "reload struct as memory, tekhex" \
301
        $struct_val "intstruct"
302
}
303
 
304
# Start a fresh gdb session
305
 
306
gdb_exit
307
gdb_start
308
gdb_reinitialize_dir $srcdir/$subdir
309
gdb_load ${binfile}
310
 
311
# Run to main.
312
if { ! [ runto_main ] } then {
313
    untested dump.exp
314
    return -1
315
}
316
 
317
if { ![string compare $array_val \
318
           [capture_value "intarray" "load binfile"]] } then {
319
    fail "start with intarray un-initialized, runto main"
320
} else {
321
    pass "start with intarray un-initialized, runto main"
322
}
323
 
324
if { ![string compare $struct_val \
325
           [capture_value "intstruct" "load binfile"]] } then {
326
    fail "start with intstruct un-initialized, runto main"
327
} else {
328
    pass "start with intstruct un-initialized, runto main"
329
}
330
 
331
if ![string compare $is64bitonly "no"] then {
332
  test_restore_saved_value "intarr1.srec" "array as value, srec" \
333
        $array_val "intarray"
334
 
335
  test_restore_saved_value "intstr1.srec" "struct as value, srec" \
336
        $struct_val "intstruct"
337
 
338
  gdb_test "print zero_all ()" "void" "zero all"
339
 
340
  test_restore_saved_value "intarr2.srec" "array as memory, srec" \
341
        $array_val "intarray"
342
 
343
  test_restore_saved_value "intstr2.srec" "struct as memory, srec" \
344
        $struct_val "intstruct"
345
 
346
  gdb_test "print zero_all ()" ""
347
 
348
  test_restore_saved_value "intarr1.ihex" "array as value, ihex" \
349
        $array_val "intarray"
350
 
351
  test_restore_saved_value "intstr1.ihex" "struct as value, ihex" \
352
        $struct_val "intstruct"
353
 
354
  gdb_test "print zero_all ()" ""
355
 
356
  test_restore_saved_value "intarr2.ihex" "array as memory, ihex" \
357
        $array_val "intarray"
358
 
359
  test_restore_saved_value "intstr2.ihex" "struct as memory, ihex" \
360
        $struct_val "intstruct"
361
 
362
  gdb_test "print zero_all ()" ""
363
 
364
  test_restore_saved_value "intarr1.tekhex" "array as value, tekhex" \
365
        $array_val "intarray"
366
 
367
  test_restore_saved_value "intstr1.tekhex" "struct as value, tekhex" \
368
        $struct_val "intstruct"
369
 
370
  gdb_test "print zero_all ()" ""
371
 
372
  test_restore_saved_value "intarr2.tekhex" "array as memory, tekhex" \
373
        $array_val "intarray"
374
 
375
  test_restore_saved_value "intstr2.tekhex" "struct as memory, tekhex" \
376
        $struct_val "intstruct"
377
}
378
 
379
gdb_test "print zero_all ()" ""
380
 
381
test_restore_saved_value "intarr1.bin binary $array_start" \
382
        "array as value, binary" \
383
        $array_val "intarray"
384
 
385
test_restore_saved_value "intstr1.bin binary $struct_start" \
386
        "struct as value, binary" \
387
        $struct_val "intstruct"
388
 
389
gdb_test "print zero_all ()" ""
390
 
391
test_restore_saved_value "intarr2.bin binary $array_start" \
392
        "array as memory, binary" \
393
        $array_val "intarray"
394
 
395
test_restore_saved_value "intstr2.bin binary $struct_start" \
396
        "struct as memory, binary" \
397
        $struct_val "intstruct"
398
 
399
# test restore with offset.
400
 
401
set array2_start   [capture_value "/x &intarray2\[0\]"]
402
set struct2_start  [capture_value "/x &intstruct2"]
403
set array2_offset  \
404
        [capture_value "(char *) &intarray2 - (char *) &intarray"]
405
set struct2_offset \
406
        [capture_value "(char *) &intstruct2 - (char *) &intstruct"]
407
 
408
gdb_test "print zero_all ()" ""
409
 
410
 
411
if ![string compare $is64bitonly "no"] then {
412
  test_restore_saved_value "intarr1.srec $array2_offset" \
413
        "array copy, srec" \
414
        $array_val "intarray2"
415
 
416
  test_restore_saved_value "intstr1.srec $struct2_offset" \
417
        "struct copy, srec" \
418
        $struct_val "intstruct2"
419
 
420
  gdb_test "print zero_all ()" ""
421
 
422
  test_restore_saved_value "intarr1.ihex $array2_offset" \
423
        "array copy, ihex" \
424
        $array_val "intarray2"
425
 
426
  test_restore_saved_value "intstr1.ihex $struct2_offset" \
427
        "struct copy, ihex" \
428
        $struct_val "intstruct2"
429
 
430
  gdb_test "print zero_all ()" ""
431
 
432
  test_restore_saved_value "intarr1.tekhex $array2_offset" \
433
        "array copy, tekhex" \
434
        $array_val "intarray2"
435
 
436
  test_restore_saved_value "intstr1.tekhex $struct2_offset" \
437
        "struct copy, tekhex" \
438
        $struct_val "intstruct2"
439
}
440
 
441
gdb_test "print zero_all ()" ""
442
 
443
test_restore_saved_value "intarr1.bin binary $array2_start" \
444
        "array copy, binary" \
445
        $array_val "intarray2"
446
 
447
test_restore_saved_value "intstr1.bin binary $struct2_start" \
448
        "struct copy, binary" \
449
        $struct_val "intstruct2"
450
 
451
#
452
# test restore with start/stop addresses.
453
#
454
# For this purpose, we will restore just the third element of the array,
455
# and check to see that adjacent elements are not modified.
456
#
457
# We will need the address and offset of the third and fourth elements.
458
#
459
 
460
set element3_start  [capture_value "/x &intarray\[3\]"]
461
set element4_start  [capture_value "/x &intarray\[4\]"]
462
set element3_offset \
463
        [capture_value "/x (char *) &intarray\[3\] - (char *) &intarray\[0\]"]
464
set element4_offset \
465
        [capture_value "/x (char *) &intarray\[4\] - (char *) &intarray\[0\]"]
466
 
467
if ![string compare $is64bitonly "no"] then {
468
  gdb_test "print zero_all ()" ""
469
 
470
  test_restore_saved_value "intarr1.srec 0 $element3_start $element4_start" \
471
        "array partial, srec" 4 "intarray\[3\]"
472
 
473
  gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 1"
474
  gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 1"
475
 
476
  gdb_test "print zero_all ()" ""
477
 
478
  test_restore_saved_value "intarr1.ihex 0 $element3_start $element4_start" \
479
        "array partial, ihex" 4 "intarray\[3\]"
480
 
481
  gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 2"
482
  gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 2"
483
 
484
  gdb_test "print zero_all ()" ""
485
 
486
  test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
487
        "array partial, tekhex" 4 "intarray\[3\]"
488
 
489
  gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 3"
490
  gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 3"
491
}
492
 
493
gdb_test "print zero_all ()" ""
494
 
495
test_restore_saved_value \
496
    "intarr1.bin binary $array_start $element3_offset $element4_offset" \
497
    "array partial, binary" 4 "intarray\[3\]"
498
 
499
gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 4"
500
gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 4"
501
 
502
if ![string compare $is64bitonly "no"] then {
503
  gdb_test "print zero_all ()" "" ""
504
 
505
  # restore with expressions
506
  test_restore_saved_value \
507
        "intarr3.srec (char*)${array2_start}-(char*)${array_start} &intarray\[3\] &intarray\[4\]" \
508
        "array partial with expressions" 4 "intarray2\[3\]"
509
 
510
  gdb_test "print intarray2\[2\] == 0" " = 1" "element 2 not changed, == 4"
511
  gdb_test "print intarray2\[4\] == 0" " = 1" "element 4 not changed, == 4"
512
}
513
 
514
# clean up files
515
 
516
remote_exec build "rm -f intarr1.bin intarr1b.bin intarr1.ihex intarr1.srec intarr1.tekhex intarr2.bin intarr2b.bin intarr2.ihex intarr2.srec intarr2.tekhex intstr1.bin intstr1b.bin intstr1.ihex intstr1.srec intstr1.tekhex intstr2.bin intstr2b.bin intstr2.ihex intstr2.srec intstr2.tekhex intarr3.srec"

powered by: WebSVN 2.1.0

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