1 # Copyright 2003, 2007, 2008, 2009 Free Software Foundation, Inc.
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.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This is a regression test for the following bug, as of 2003-12-12:
19 # Set a breakpoint which will be hit many times. Attach a complex set
20 # of commands to it, including a "continue" command. Run the program,
21 # so that the breakpoint is hit, its commands get executed, and the
22 # program continues and hits the breakpoint again. You will see
23 # messages like "warning: Invalid control type in command structure.",
24 # or maybe GDB will crash.
26 # When the breakpoint is hit, bpstat_stop_status copies the
27 # breakpoint's command tree to the bpstat. bpstat_do_actions then
28 # calls execute_control_command to run the commands. The 'continue'
29 # command invokes the following chain of calls:
32 # -> clear_proceed_status
34 # -> free_command_lines
35 # -> frees the commands we are currently running.
37 # When control does eventually return to execute_control_command, GDB
38 # continues to walk the tree of freed command nodes, resulting in the
39 # error messages and / or crashes.
41 # Since this bug depends on storage being reused between the time that
42 # we continue and the time that we fall back to bpstat_do_actions, the
43 # reproduction recipe is more delicate than I would like. I welcome
44 # suggestions for improving this.
49 set testfile "freebpcmd"
50 set srcfile ${testfile}.c
51 set srcfile1 ${testfile}1.c
52 set binfile ${objdir}/${subdir}/${testfile}
54 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
55 untested freebpcmd.exp
61 gdb_reinitialize_dir $srcdir/$subdir
64 gdb_test "break [gdb_get_line_number "euphonium"]" "" "set breakpoint"
66 # The goal of all this is to make sure that there's plenty of memory
67 # churn, and different amounts of it each time the inferior stops;
68 # this seems to make GDB crash more reliably.
69 set lines {{if (i%2) == 0}
76 {set variable $foo = 0}
79 {set variable $foo += $j}
89 for {set i 0} {$i < [llength $lines]} {incr i} {
92 send_gdb "[lindex $lines $i]\n"
95 set reason "got top-level prompt early"
104 if {$i >= [llength $lines]} {
105 pass "send breakpoint commands"
107 fail "send breakpoint commands ($reason)"
114 gdb_test_multiple "" "run program with breakpoint commands" {
115 -re "warning: Invalid control type in command structure" {
116 kfail "gdb/1489" "run program with breakpoint commands"
118 -re "$gdb_prompt $" {
119 pass "run program with breakpoint commands"
122 kfail "gdb/1489" "run program with breakpoint commands (GDB died)"