OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gdb-7.2/] [gdb-7.2-or32-1.0rc1/] [gdb/] [testsuite/] [gdb.base/] [commands.exp] - Blame information for rev 341

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 330 jeremybenn
#   Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1997, 1998, 1999, 2000,
2
#   2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010
3
#   Free Software Foundation, Inc.
4
 
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program.  If not, see .
17
 
18
if $tracelevel then {
19
    strace $tracelevel
20
}
21
 
22
#
23
# test special commands (if, while, etc)
24
#
25
 
26
if { [prepare_for_testing commands.exp commands run.c {debug additional_flags=-DFAKEARGV}] } {
27
    return -1
28
}
29
 
30
proc gdbvar_simple_if_test {} {
31
    global gdb_prompt
32
 
33
    gdb_test_no_output "set \$foo = 0" "set foo in gdbvar_simple_if_test"
34
    # All this test should do is print 0xdeadbeef once.
35
    gdb_test "if \$foo == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
36
            "\\\$\[0-9\]* = 0xdeadbeef" "gdbvar_simple_if_test #1"
37
    # All this test should do is print 0xfeedface once.
38
    gdb_test "if \$foo == 0\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
39
            "\\\$\[0-9\]* = 0xfeedface" "gdbvar_simple_if_test #2"
40
}
41
 
42
proc gdbvar_simple_while_test {} {
43
    global gdb_prompt
44
 
45
    gdb_test_no_output "set \$foo = 5" "set foo in gdbvar_simple_while_test"
46
    # This test should print 0xfeedface five times.
47
    gdb_test "while \$foo > 0\np/x 0xfeedface\nset \$foo -= 1\nend" \
48
            "\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" \
49
            "gdbvar_simple_while_test #1"
50
}
51
 
52
proc gdbvar_complex_if_while_test {} {
53
    global gdb_prompt
54
 
55
    gdb_test_no_output "set \$foo = 4" \
56
        "set foo in gdbvar complex_if_while_test"
57
    # This test should alternate between 0xdeadbeef and 0xfeedface two times.
58
    gdb_test "while \$foo > 0\nset \$foo -= 1\nif \(\$foo % 2\) == 1\np/x 0xdeadbeef\nelse\np/x 0xfeedface\nend\nend" \
59
            "\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" \
60
            "gdbvar_complex_if_while_test #1"
61
}
62
 
63
proc progvar_simple_if_test {} {
64
    global gdb_prompt
65
 
66
    if [target_info exists noargs] {
67
        verbose "Skipping progvar_simple_if_test because of noargs."
68
        return
69
    }
70
 
71
    if { ![runto factorial] } then { gdb_suppress_tests; }
72
    # Don't depend upon argument passing, since most simulators don't
73
    # currently support it.  Bash value variable to be what we want.
74
    gdb_test "p value=5" ".*" "set value to 5 in progvar_simple_if_test #1"
75
    # All this test should do is print 0xdeadbeef once.
76
    gdb_test "if value == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
77
            "\\\$\[0-9\]* = 0xdeadbeef" \
78
            "progvar_simple_if_test #1"
79
    # All this test should do is print 0xfeedface once.
80
    gdb_test "if value == 5\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
81
            "\\\$\[0-9\]* = 0xfeedface" \
82
            "progvar_simple_if_test #2"
83
    gdb_stop_suppressing_tests;
84
}
85
 
86
proc progvar_simple_while_test {} {
87
    global gdb_prompt
88
 
89
    if [target_info exists noargs] {
90
        verbose "Skipping progvar_simple_while_test because of noargs."
91
        return
92
    }
93
 
94
    gdb_test_no_output "set args 5" "set args in progvar_simple_while_test"
95
    if { ![runto factorial] } then { gdb_suppress_tests }
96
    # Don't depend upon argument passing, since most simulators don't
97
    # currently support it.  Bash value variable to be what we want.
98
    gdb_test "p value=5" ".*" "set value to 5 in progvar_simple_if_test #2"
99
    # This test should print 0xfeedface five times.
100
    gdb_test "while value > 0\np/x 0xfeedface\nset value -= 1\nend" \
101
            "\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" \
102
            "progvar_simple_while_test #1"
103
    gdb_stop_suppressing_tests;
104
}
105
 
106
proc progvar_complex_if_while_test {} {
107
    global gdb_prompt
108
 
109
    if [target_info exists noargs] {
110
        verbose "Skipping progvar_simple_if_while_test because of noargs."
111
        return
112
    }
113
 
114
    gdb_test_no_output "set args 4" \
115
        "set args in progvar_complex_if_while_test"
116
    if { ![runto factorial] } then { gdb_suppress_tests }
117
    # Don't depend upon argument passing, since most simulators don't
118
    # currently support it.  Bash value variable to be what we want.
119
    gdb_test "p value=4" ".*" "set value to 4 in progvar_simple_if_test"
120
    # This test should alternate between 0xdeadbeef and 0xfeedface two times.
121
    gdb_test "while value > 0\nset value -= 1\nif \(value % 2\) == 1\np/x 0xdeadbeef\nelse\np/x 0xfeedface\nend\nend" \
122
            "\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" \
123
            "progvar_complex_if_while_test #1"
124
    gdb_stop_suppressing_tests;
125
}
126
 
127
proc if_while_breakpoint_command_test {} {
128
    if [target_info exists noargs] {
129
        verbose "Skipping if_while_breakpoint_command_test because of noargs."
130
        return
131
    }
132
 
133
    gdb_test_no_output "set args 5" \
134
        "set args in if_while_breakpoint_command_test"
135
    if { ![runto factorial] } then { gdb_suppress_tests }
136
    # Don't depend upon argument passing, since most simulators don't
137
    # currently support it.  Bash value variable to be what we want.
138
    gdb_test "p value=5" ".*" "set value to 5 in progvar_simple_if_test"
139
    delete_breakpoints
140
    gdb_test "break factorial" "Breakpoint.*at.*" "break factorial #1"
141
 
142
    gdb_test_multiple "commands" \
143
        "commands in if_while_breakpoint_command_test" {
144
            -re "End with" {
145
                pass "commands in if_while_breakpoint_command_test"
146
            }
147
        }
148
 
149
    # This test should alternate between 0xdeadbeef and 0xfeedface two times.
150
    gdb_test "while value > 0\nset value -= 1\nif \(value % 2\) == 1\np/x 0xdeadbeef\nelse\np/x 0xfeedface\nend\nend\nend" \
151
            "" \
152
            "commands part 2 in if_while_breakpoint_command_test"
153
    gdb_test "continue" \
154
            "\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" \
155
            "if_while_breakpoint_command_test #1"
156
   gdb_test "info break" \
157
           "while.*set.*if.*p/x.*else.*p/x.*end.*" \
158
           "info break in if_while_breakpoint_command_test"
159
    gdb_stop_suppressing_tests;
160
}
161
 
162
# Test that we can run the inferior from breakpoint commands.
163
#
164
# The expected behavior is that all commands after the first "step"
165
# shall be ignored.  See the gdb manual, "Break Commands",
166
# subsection "Breakpoint command lists".
167
 
168
proc infrun_breakpoint_command_test {} {
169
    if [target_info exists noargs] {
170
        verbose "Skipping infrun_breakpoint_command_test because of noargs."
171
        return
172
    }
173
 
174
    gdb_test_no_output "set args 6" \
175
        "set args in infrun_breakpoint_command_test"
176
    if { ![runto factorial] } then { gdb_suppress_tests }
177
    # Don't depend upon argument passing, since most simulators don't
178
    # currently support it.  Bash value variable to be what we want.
179
    gdb_test "p value=6" ".*" "set value to 6 in progvar_simple_if_test #1"
180
    delete_breakpoints
181
    gdb_test "break factorial if value == 5" "Breakpoint.*at.*"
182
 
183
# infrun_breakpoint_command_test - This test was broken into two parts
184
# to get around a synchronization problem in expect.
185
# part1: issue the gdb command "commands"
186
# part2: send the list of commands
187
    gdb_test_multiple "commands" \
188
        "commands in infrun_breakpoint_command_test #1" {
189
            -re "End with" {
190
                pass "commands in infrun_breakpoint_command_test #1"
191
            }
192
        }
193
    gdb_test "step\nstep\nstep\nstep\nend" "" \
194
        "commands in infrun_breakpoint_command_test #2"
195
 
196
    gdb_test "continue" \
197
        "Continuing.*.*.*Breakpoint \[0-9\]*, factorial \\(value=5\\).*at.*\[0-9\]*\[      \]*if \\(value > 1\\) \{.*\[0-9\]*\[      \]*value \\*= factorial \\(value - 1\\);.*" \
198
        "continue in infrun_breakpoint_command_test"
199
 
200
    gdb_stop_suppressing_tests;
201
}
202
 
203
proc breakpoint_command_test {} {
204
    if [target_info exists noargs] {
205
        verbose "Skipping breakpoint_command_test because of noargs."
206
        return
207
    }
208
 
209
    gdb_test_no_output "set args 6" "set args in breakpoint_command_test"
210
    if { ![runto factorial] } then { gdb_suppress_tests; }
211
    # Don't depend upon argument passing, since most simulators don't
212
    # currently support it.  Bash value variable to be what we want.
213
    gdb_test "p value=6" ".*" "set value to 6 in progvar_simple_if_test #2"
214
    delete_breakpoints
215
    gdb_test "break factorial" "Breakpoint.*at.*" "break factorial #2"
216
    gdb_test "commands\nprintf \"Now the value is %d\\n\", value\nend" \
217
        "End with.*" "commands in breakpoint_command_test"
218
    gdb_test "continue" \
219
            "Breakpoint \[0-9\]*, factorial.*Now the value is 5" \
220
        "continue in breakpoint_command_test"
221
    gdb_test "print value" " = 5" "print value in breakpoint_command_test"
222
    gdb_stop_suppressing_tests;
223
}
224
 
225
# Test a simple user defined command (with arguments)
226
proc user_defined_command_test {} {
227
    global gdb_prompt
228
 
229
    gdb_test_no_output "set \$foo = 4" \
230
        "set foo in user_defined_command_test"
231
 
232
    gdb_test_multiple "define mycommand" \
233
        "define mycommand in user_defined_command_test" {
234
            -re "End with"  {
235
                pass "define mycommand in user_defined_command_test"
236
            }
237
        }
238
 
239
    # This test should alternate between 0xdeadbeef and 0xfeedface two times.
240
    gdb_test "while \$arg0 > 0\nset \$arg0 -= 1\nif \(\$arg0 % 2\) == 1\np/x 0xdeadbeef\nelse\np/x 0xfeedface\nend\nend\nend" \
241
            "" \
242
            "enter commands in user_defined_command_test"
243
 
244
    gdb_test "mycommand \$foo" \
245
            "\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" \
246
            "execute user defined command in user_defined_command_test"
247
   gdb_test "show user mycommand" \
248
        "  while \\\$arg0.*set.*    if \\\(\\\$arg0.*p/x.*    else\[^\n\].*p/x.*    end\[^\n\].*  end\[^\n\].*" \
249
           "display user command in user_defined_command_test"
250
}
251
 
252
proc watchpoint_command_test {} {
253
    global noargs
254
    global gdb_prompt
255
 
256
    if [target_info exists noargs] {
257
        verbose "Skipping watchpoint_command_test because of noargs."
258
        return
259
    }
260
 
261
    # Disable hardware watchpoints if necessary.
262
    if [target_info exists gdb,no_hardware_watchpoints] {
263
        gdb_test_no_output "set can-use-hw-watchpoints 0" ""
264
    }
265
 
266
    gdb_test_no_output "set args 6" "set args in watchpoint_command_test"
267
    if { ![runto factorial] } then { return }
268
    delete_breakpoints
269
 
270
    # Verify that we can create a watchpoint, and give it a commands
271
    # list that continues the inferior.  We set the watchpoint on a
272
    # local variable, too, so that it self-deletes when the watched
273
    # data goes out of scope.
274
    #
275
    # What should happen is: Each time the watchpoint triggers, it
276
    # continues the inferior.  Eventually, the watchpoint will self-
277
    # delete, when the watched variable is out of scope.  But by that
278
    # time, the inferior should have exited.  GDB shouldn't crash or
279
    # anything untoward as a result of this.
280
    #
281
    set wp_id -1
282
 
283
    gdb_test_multiple "watch local_var" "watch local_var" {
284
        -re "\[Ww\]atchpoint (\[0-9\]*): local_var.*$gdb_prompt $" {
285
            set wp_id $expect_out(1,string)
286
            pass "watch local_var"
287
        }
288
    }
289
 
290
    if {$wp_id == -1} {return}
291
 
292
    gdb_test_multiple "commands $wp_id" "begin commands on watch" {
293
        -re "Type commands for breakpoint.*, one per line.*>$" {
294
            pass "begin commands on watch"
295
        }
296
    }
297
    gdb_test_multiple "print value" "add print command to watch" {
298
        -re ">$" {
299
            pass "add print command to watch"
300
        }
301
    }
302
    gdb_test_multiple "continue" "add continue command to watch" {
303
        -re ">$" {
304
            pass "add continue command to watch"
305
        }
306
    }
307
    gdb_test "end" \
308
        "" \
309
        "end commands on watch"
310
 
311
    gdb_test "continue" \
312
        "Continuing.*\[Ww\]atchpoint $wp_id deleted because the program has left the block in.*which its expression is valid.*run.c:(57|82).*" \
313
        "continue with watch"
314
}
315
 
316
proc test_command_prompt_position {} {
317
    global gdb_prompt
318
 
319
    if [target_info exists noargs] {
320
        verbose "Skipping test_command_prompt_position because of noargs."
321
        return
322
    }
323
 
324
    if { ![runto factorial] } then { gdb_suppress_tests; }
325
    # Don't depend upon argument passing, since most simulators don't
326
    # currently support it.  Bash value variable to be what we want.
327
    delete_breakpoints
328
    gdb_test "break factorial" "Breakpoint.*at.*" "break factorial #3"
329
    gdb_test "p value=5" ".*" "set value to 5 in test_command_prompt_position"
330
    # All this test should do is print 0xdeadbeef once.
331
    gdb_test "if value == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
332
            "\\\$\[0-9\]* = 0xdeadbeef" \
333
            "if test in test_command_prompt_position"
334
 
335
    # Now let's test for the correct position of the '>' in gdb's
336
    # prompt for commands.  It should be at the beginning of the line,
337
    # and not after one space.
338
 
339
    send_gdb "commands\n"
340
    gdb_expect {
341
        -re "Type commands.*End with.*\[\r\n\]>$" {
342
            send_gdb "printf \"Now the value is %d\\n\", value\n"
343
            gdb_expect {
344
                -re "^printf.*value\r\n>$" {
345
                    send_gdb "end\n"
346
                    gdb_expect {
347
                        -re "^end\r\n$gdb_prompt $" {
348
                            pass "> OK in test_command_prompt_position"
349
                        }
350
                        -re ".*$gdb_prompt $" {
351
                            fail "some other message in test_command_prompt_position"
352
                        }
353
                        timeout  {
354
                            fail "(timeout) 1 in test_command_prompt_position"
355
                        }
356
                    }
357
                }
358
                -re "^ >$" { fail "> not OK in test_command_prompt_position" }
359
                -re ".*$gdb_prompt $"   {
360
                    fail "wrong message in test_command_prompt_position"
361
                }
362
                timeout    {
363
                    fail "(timeout) 2 in test_command_prompt_position "
364
                }
365
            }
366
        }
367
        -re "Type commands.*End with.*\[\r\n\] >$" {
368
            fail "prompt not OK in test_command_prompt_position"
369
        }
370
        -re ".*$gdb_prompt $" {
371
            fail "commands in test_command_prompt_position"
372
        }
373
        timeout { fail "(timeout) 3 commands in test_command_prompt_position" }
374
    }
375
 
376
    gdb_stop_suppressing_tests;
377
}
378
 
379
 
380
 
381
proc deprecated_command_test {} {
382
    gdb_test "maintenance deprecate blah" "Can't find command.*" \
383
          "tried to deprecate non-existing command"
384
 
385
    gdb_test_no_output "maintenance deprecate p \"new_p\"" "maintenance deprecate p \"new_p\" /1/"
386
    gdb_test "p 5" \
387
            "Warning: 'p', an alias for the command 'print' is deprecated.*Use 'new_p'.*" \
388
            "p deprecated warning, with replacement"
389
    gdb_test "p 5" ".\[0-9\]* = 5.*" "Deprecated warning goes away /1/"
390
 
391
    gdb_test_no_output "maintenance deprecate p \"new_p\"" "maintenance deprecate p \"new_p\" /2/"
392
    gdb_test_no_output "maintenance deprecate print \"new_print\""
393
    gdb_test "p 5" \
394
            "Warning: command 'print' \\(p\\) is deprecated.*Use 'new_print'.*" \
395
            "both alias and command are deprecated"
396
    gdb_test "p 5" ".\[0-9\]* = 5.*" "Deprecated warning goes away /2/"
397
 
398
    gdb_test_no_output "maintenance deprecate set remote memory-read-packet-size \"srm\" " \
399
            "deprecate long command /1/"
400
    gdb_test "set remote memory-read-packet-size" \
401
            "Warning: command 'set remote memory-read-packet-size' is deprecated.*Use 'srm'.*" \
402
            "long command deprecated /1/"
403
 
404
    gdb_test_no_output "maintenance deprecate set remote memory-read-packet-size" \
405
            "deprecate long command /2/"
406
    gdb_test "set remote memory-read-packet-size" \
407
            "Warning: command 'set remote memory-read-packet-size' is deprecated.*No alternative known.*" \
408
            "long command deprecated with no alternative /2/"
409
 
410
    gdb_test "maintenance deprecate" \
411
            "\"maintenance deprecate\".*" \
412
            "deprecate with no arguments"
413
}
414
 
415
proc bp_deleted_in_command_test {} {
416
    global gdb_prompt
417
 
418
    if [target_info exists noargs] {
419
        verbose "Skipping bp_deleted_in_command_test because of noargs."
420
        return
421
    }
422
 
423
    gdb_test_no_output "set args 1" \
424
        "set args in bp_deleted_in_command_test"
425
    delete_breakpoints
426
 
427
    # Create a breakpoint, and associate a command-list to it, with
428
    # one command that deletes this breakpoint.
429
    gdb_test "break factorial" \
430
             "Breakpoint \[0-9\]+ at .*: file .*/run.c, line \[0-9\]+\." \
431
             "breakpoint in bp_deleted_in_command_test"
432
 
433
    gdb_test_multiple "commands" "begin commands in bp_deleted_in_command_test" {
434
      -re "Type commands for breakpoint.*>$" {
435
          pass "begin commands in bp_deleted_in_command_test"
436
      }
437
    }
438
    gdb_test_multiple "silent" "add silent command" {
439
        -re ">$" {
440
            pass "add silent command"
441
        }
442
    }
443
    gdb_test_multiple "clear factorial" "add clear command" {
444
        -re ">$" {
445
            pass "add clear command"
446
        }
447
    }
448
    gdb_test_multiple "printf \"factorial command-list executed\\n\"" \
449
        "add printf command" {
450
        -re ">$" {
451
            pass "add printf command"
452
        }
453
    }
454
    gdb_test_multiple "cont" "add cont command" {
455
        -re ">$" {
456
            pass "add cont command"
457
        }
458
    }
459
    gdb_test "end" \
460
        "" \
461
        "end commands"
462
 
463
    gdb_run_cmd
464
    gdb_expect {
465
        -re ".*factorial command-list executed.*$gdb_prompt $" {
466
            pass "run factorial until breakpoint"
467
        }
468
        -re ".*$gdb_prompt $" {
469
            fail "run factorial until breakpoint"
470
        }
471
        default { fail "(timeout) run factorial until breakpoint" }
472
        timeout { fail "(timeout) run factorial until breakpoint" }
473
    }
474
}
475
 
476
proc temporary_breakpoint_commands {} {
477
    global gdb_prompt
478
 
479
    if [target_info exists noargs] {
480
        verbose "Skipping temporary_breakpoint_commands because of noargs."
481
        return
482
    }
483
 
484
    gdb_test_no_output "set args 1" \
485
        "set args in temporary_breakpoint_commands"
486
    delete_breakpoints
487
 
488
    # Create a temporary breakpoint, and associate a commands list to it.
489
    # This test will verify that this commands list is executed when the
490
    # breakpoint is hit.
491
    gdb_test "tbreak factorial" \
492
            "Temporary breakpoint \[0-9\]+ at .*: file .*/run.c, line \[0-9\]+\." \
493
            "breakpoint in temporary_breakpoint_commands"
494
 
495
    gdb_test_multiple "commands" \
496
        "begin commands in bp_deleted_in_command_test" {
497
            -re "Type commands for breakpoint.*>$" {
498
                pass "begin commands in bp_deleted_in_command_test"
499
            }
500
        }
501
    gdb_test_multiple "silent" "add silent tbreak command" {
502
        -re ">$" {
503
            pass "add silent tbreak command"
504
        }
505
    }
506
    gdb_test_multiple "printf \"factorial tbreak commands executed\\n\"" \
507
        "add printf tbreak command" {
508
            -re ">$" {
509
                pass "add printf tbreak command"
510
            }
511
        }
512
    gdb_test_multiple "cont" "add cont tbreak command" {
513
        -re ">$" {
514
            pass "add cont tbreak command"
515
        }
516
    }
517
    gdb_test "end" \
518
        "" \
519
        "end tbreak commands"
520
 
521
    gdb_run_cmd
522
    gdb_expect {
523
        -re ".*factorial tbreak commands executed.*$gdb_prompt $" {
524
            pass "run factorial until temporary breakpoint"
525
        }
526
        timeout { fail "(timeout) run factorial until temporary breakpoint" }
527
    }
528
}
529
 
530
# Test that GDB can handle $arg0 outside of user functions without
531
# crashing.
532
proc stray_arg0_test { } {
533
    gdb_test "print \$arg0" \
534
        "\\\$\[0-9\]* = void" \
535
        "stray_arg0_test #1"
536
 
537
    gdb_test "if 1 == 1\nprint \$arg0\nend" \
538
        "\\\$\[0-9\]* = void" \
539
        "stray_arg0_test #2"
540
 
541
    gdb_test "print \$arg0 = 1" \
542
        "\\\$\[0-9\]* = 1" \
543
        "stray_arg0_test #3"
544
 
545
    gdb_test "print \$arg0" \
546
        "\\\$\[0-9\]* = 1" \
547
        "stray_arg0_test #4"
548
}
549
 
550
# Test that GDB is able to source a file with an indented comment.
551
proc source_file_with_indented_comment {} {
552
    set fd [open "file1" w]
553
    puts $fd \
554
{define my_fun
555
    #indented comment
556
end
557
echo Done!\n}
558
    close $fd
559
 
560
    gdb_test "source file1" "Done!" "source file with indented comment"
561
}
562
 
563
# Test that GDB can handle arguments when sourcing files recursively.
564
# If the arguments are overwritten with ####### then the test has failed.
565
proc recursive_source_test {} {
566
    set fd [open "file1" w]
567
    puts $fd \
568
{source file2
569
abcdef qwerty}
570
    close $fd
571
 
572
    set fd [open "file2" w]
573
    puts $fd \
574
{define abcdef
575
  echo 1: <<<$arg0>>>\n
576
  source file3
577
  echo 2: <<<$arg0>>>\n
578
end}
579
    close $fd
580
 
581
    set fd [open "file3" w]
582
    puts $fd \
583
"echo in file3\\n
584
#################################################################"
585
    close $fd
586
 
587
    gdb_test "source file1" \
588
        "1: <<>>\[\r\n]+in file3\[\r\n]+2: <<>>" \
589
        "recursive source test"
590
 
591
    file delete file1
592
    file delete file2
593
    file delete file3
594
}
595
 
596
proc gdb_test_no_prompt { command result msg } {
597
    global gdb_prompt
598
 
599
    set msg "$command - $msg"
600
    set result "^[string_to_regexp $command]\r\n$result$"
601
    gdb_test_multiple $command $msg {
602
        -re "$result" {
603
            pass $msg
604
            return 1
605
        }
606
        -re "\r\n *>$" {
607
            fail $msg
608
            return 0
609
        }
610
    }
611
    return 0
612
}
613
 
614
proc if_commands_test {} {
615
    global gdb_prompt
616
 
617
    gdb_test_no_output "set \$tem = 1" "set \$tem in if_commands_test"
618
 
619
    set test "if_commands_test 1"
620
    gdb_test_no_prompt "if \$tem == 2" { >} $test
621
    gdb_test_no_prompt "break main" { >} $test
622
    gdb_test_no_prompt "else" { >} $test
623
    gdb_test_no_prompt "break factorial" { >} $test
624
    gdb_test_no_prompt "commands" {  >} $test
625
    gdb_test_no_prompt "silent" {  >} $test
626
    gdb_test_no_prompt "set \$tem = 3" {  >} $test
627
    gdb_test_no_prompt "continue" {  >} $test
628
    gdb_test_multiple "end" "first end - $test" {
629
        -re " >\$" {
630
            pass "first end - $test"
631
        }
632
        -re "\r\n>\$" {
633
            fail "first end - $test"
634
        }
635
    }
636
    gdb_test_multiple "end" "second end - $test" {
637
        -re "Breakpoint \[0-9\]+ at .*: file .*/run.c, line \[0-9\]+\.\r\n$gdb_prompt $" {
638
            pass "second end - $test"
639
        }
640
        -re "Undefined command: \"silent\".*$gdb_prompt $" {
641
            fail "second end - $test"
642
        }
643
    }
644
 
645
    set test "if_commands_test 2"
646
    gdb_test_no_prompt "if \$tem == 1" { >} $test
647
    gdb_test_no_prompt "break main" { >} $test
648
    gdb_test_no_prompt "else" { >} $test
649
    gdb_test_no_prompt "break factorial" { >} $test
650
    gdb_test_no_prompt "commands" {  >} $test
651
    gdb_test_no_prompt "silent" {  >} $test
652
    gdb_test_no_prompt "set \$tem = 3" {  >} $test
653
    gdb_test_no_prompt "continue" {  >} $test
654
    gdb_test_multiple "end" "first end - $test" {
655
        -re " >\$" {
656
            pass "first end - $test"
657
        }
658
        -re "\r\n>\$" {
659
            fail "first end - $test"
660
        }
661
    }
662
    gdb_test_multiple "end" "second end - $test" {
663
        -re "Breakpoint \[0-9\]+ at .*: file .*/run.c, line \[0-9\]+\.\r\n$gdb_prompt $" {
664
            pass "second end - $test"
665
        }
666
    }
667
}
668
 
669
proc redefine_hook_test {} {
670
    global gdb_prompt
671
 
672
    gdb_test "define one\nend" \
673
      "" \
674
      "define one"
675
 
676
    gdb_test "define hook-one\necho hibob\\n\nend" \
677
      "" \
678
      "define hook-one"
679
 
680
    gdb_test_multiple "define one" "redefine one" {
681
        -re "Redefine command .one.. .y or n. $" {
682
            send_gdb "y\n"
683
            exp_continue
684
        }
685
 
686
        -re "End with"  {
687
            pass "define one in redefine_hook_test"
688
        }
689
        default {
690
            fail "(timeout or eof) define one in redefine_hook_test"
691
        }
692
    }
693
 
694
    gdb_test "end" \
695
            "" \
696
            "enter commands for one redefinition in redefine_hook_test"
697
 
698
    gdb_test "one" \
699
            "hibob" \
700
            "execute one command in redefine_hook_test"
701
}
702
 
703
proc redefine_backtrace_test {} {
704
    global gdb_prompt
705
 
706
    gdb_test_multiple "define backtrace" "define backtrace" {
707
        -re "Really redefine built-in.*$" {
708
            send_gdb "y\n"
709
            exp_continue
710
        }
711
 
712
        -re "End with"  {
713
            pass "define backtrace in redefine_backtrace_test"
714
        }
715
        default {
716
            fail "(timeout or eof) define backtrace in redefine_backtrace_test"
717
        }
718
    }
719
    gdb_test "echo hibob\\n\nend" \
720
            "" \
721
            "enter commands in redefine_backtrace_test"
722
 
723
    gdb_test "backtrace" \
724
            "hibob" \
725
            "execute backtrace command in redefine_backtrace_test"
726
    gdb_test "bt" \
727
            "hibob" \
728
            "execute bt command in redefine_backtrace_test"
729
}
730
 
731
gdbvar_simple_if_test
732
gdbvar_simple_while_test
733
gdbvar_complex_if_while_test
734
progvar_simple_if_test
735
progvar_simple_while_test
736
progvar_complex_if_while_test
737
if_while_breakpoint_command_test
738
infrun_breakpoint_command_test
739
breakpoint_command_test
740
user_defined_command_test
741
watchpoint_command_test
742
test_command_prompt_position
743
deprecated_command_test
744
bp_deleted_in_command_test
745
temporary_breakpoint_commands
746
stray_arg0_test
747
source_file_with_indented_comment
748
recursive_source_test
749
if_commands_test
750
redefine_hook_test
751
# This one should come last, as it redefines "backtrace".
752
redefine_backtrace_test

powered by: WebSVN 2.1.0

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