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

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gdb-7.2/] [gdb-7.2-or32-1.0rc3/] [gdb/] [testsuite/] [gdb.base/] [dump.exp] - Blame information for rev 579

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

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