xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/freebpcmd.exp (revision d16b7486a53dcb8072b60ec6fcb4373a2d0c27b7)
1#   Copyright 2003-2020 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 <http://www.gnu.org/licenses/>.
15
16
17# This is a regression test for the following bug, as of 2003-12-12:
18#
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.
25#
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:
30#
31#   continue_command
32#     -> clear_proceed_status
33#       -> bpstat_clear
34#         -> free_command_lines
35#            -> frees the commands we are currently running.
36#
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.
40#
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.
45
46
47standard_testfile
48if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
49    return -1
50}
51
52gdb_test "break ${srcfile}:[gdb_get_line_number "euphonium"]" ".*" \
53    "set breakpoint"
54
55# The goal of all this is to make sure that there's plenty of memory
56# churn, and different amounts of it each time the inferior stops;
57# this seems to make GDB crash more reliably.
58set lines {{if i<0 || i > 100}
59	   {echo Invalid i value\n}
60	   {else}
61	   {if (i%2) == 0}
62           {echo "even "}
63           {print i}
64           {else}
65           {echo "odd "}
66           {print i}
67           {end}
68           {set variable $foo = 0}
69           {set variable $j = 0}
70           {while $j < i}
71           {set variable $foo += $j}
72           {set variable $j++}
73           {end}
74           {print $foo}
75           {if i != 40}
76           {c}
77           {end}
78	   {end}
79           {end}}
80
81send_gdb "commands\n"
82for {set i 0} {$i < [llength $lines]} {incr i} {
83    gdb_expect {
84        -re ".*>" {
85            send_gdb "[lindex $lines $i]\n"
86        }
87        -re "$gdb_prompt $" {
88            set reason "got top-level prompt early"
89            break
90        }
91        timeout {
92            set reason "timeout"
93            break
94        }
95    }
96}
97if {$i >= [llength $lines]} {
98    pass "send breakpoint commands"
99} else {
100    fail "send breakpoint commands ($reason)"
101}
102
103gdb_run_cmd
104
105with_timeout_factor 10 {
106    gdb_test_multiple "" "run program with breakpoint commands" {
107	-re "warning: Invalid control type in command structure" {
108	    kfail "gdb/1489" "run program with breakpoint commands"
109	}
110	-re "Invalid i value\r\n$gdb_prompt $" {
111	    xfail "run program with breakpoint commands (i value not readable)"
112	}
113	-re "$gdb_prompt $" {
114	    pass "run program with breakpoint commands"
115	}
116	eof {
117	    kfail "gdb/1489" "run program with breakpoint commands (GDB died)"
118	}
119    }
120}
121