Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2014-2020 Free Software Foundation, Inc. |
08351840 PA |
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 | # Test that "file" doesn't leave stale breakpoints planted in the | |
17 | # target. | |
18 | ||
19 | standard_testfile | |
20 | ||
d03de421 | 21 | if {[build_executable "failed to prepare" $testfile $srcfile debug]} { |
08351840 PA |
22 | return -1 |
23 | } | |
24 | ||
d03de421 PA |
25 | # Run the test proper. INITIAL_LOAD determines whether the program is |
26 | # initially loaded by the "file" command or by passing it to GDB on | |
27 | # the command line. ALWAYS_INSERT determines whether always-inserted | |
28 | # mode is on/off. BREAK_COMMAND is the break command being tested. | |
08351840 | 29 | # |
d03de421 PA |
30 | proc test_break { initial_load always_inserted break_command } { |
31 | global srcdir subdir binfile | |
32 | global gdb_prompt hex | |
33 | global GDBFLAGS | |
34 | ||
35 | append prefix "$initial_load: " | |
36 | append prefix "always-inserted $always_inserted: " | |
37 | append prefix "$break_command" | |
38 | with_test_prefix "$prefix" { | |
39 | gdb_exit | |
40 | ||
41 | set saved_gdbflags $GDBFLAGS | |
42 | ||
43 | # See "used to behave differently" further below. | |
44 | if { $initial_load == "file" } { | |
45 | gdb_start | |
46 | gdb_file_cmd $binfile | |
47 | } else { | |
48 | global last_loaded_file | |
49 | ||
50 | # gdb_file_cmd sets this. This is what gdb_reload | |
51 | # implementations use as binary. | |
52 | set last_loaded_file $binfile | |
53 | ||
54 | set GDBFLAGS "$GDBFLAGS $binfile" | |
55 | gdb_start | |
56 | } | |
08351840 | 57 | |
d03de421 PA |
58 | gdb_reinitialize_dir $srcdir/$subdir |
59 | gdb_reload | |
60 | set GDBFLAGS $saved_gdbflags | |
08351840 PA |
61 | |
62 | if ![runto_main] then { | |
bc6c7af4 | 63 | fail "can't run to main" |
08351840 PA |
64 | return |
65 | } | |
66 | ||
67 | delete_breakpoints | |
68 | ||
69 | gdb_test_no_output "set breakpoint always-inserted $always_inserted" | |
70 | ||
71 | set test "$break_command foo" | |
72 | gdb_test_multiple "$break_command foo" $test { | |
73 | -re "No hardware breakpoint support in the target.*$gdb_prompt $" { | |
74 | unsupported $test | |
75 | return | |
76 | } | |
77 | -re "Hardware breakpoints used exceeds limit.*$gdb_prompt $" { | |
78 | unsupported $test | |
79 | return | |
80 | } | |
81 | -re "Cannot insert hardware breakpoint.*$gdb_prompt $" { | |
82 | unsupported $test | |
83 | return | |
84 | } | |
85 | -re ".*reakpoint .* at .*$gdb_prompt $" { | |
86 | pass $test | |
87 | } | |
88 | } | |
89 | ||
90 | # The breakpoint shouldn't be pending now. | |
91 | gdb_test "info break" "y.*$hex.*in foo at.*" \ | |
92 | "breakpoint is not pending" | |
93 | ||
94 | # Remove the file, while the breakpoint above is inserted in a | |
95 | # function in the main objfile. GDB used to have a bug where | |
96 | # it would mark the breakpoint as uninserted, but actually | |
97 | # would leave it inserted in the target. | |
98 | set test "file" | |
99 | gdb_test_multiple "file" $test { | |
100 | -re "Are you sure you want to change the file. .*y or n. $" { | |
101 | send_gdb "y\n" | |
102 | exp_continue | |
103 | } | |
104 | -re "Discard symbol table from `.*'? .y or n. $" { | |
105 | send_gdb "y\n" | |
106 | exp_continue | |
107 | } | |
108 | -re "No symbol file now\\.\r\n$gdb_prompt $" { | |
109 | pass $test | |
110 | } | |
111 | } | |
112 | ||
d03de421 PA |
113 | # This test used to behave differently depending on whether |
114 | # the program was first loaded through "file PROGRAM" or "gdb | |
115 | # PROGRAM". | |
116 | set ws "\[ \t\]" | |
117 | gdb_test "info break" "breakpoint${ws}+keep${ws}+n${ws}+$hex${ws}*" \ | |
118 | "breakpoint is disabled" | |
08351840 PA |
119 | |
120 | # Now delete the breakpoint from GDB's tables, to make sure | |
121 | # GDB doesn't reinsert it, masking the bug (with the bug, on | |
122 | # re-insert, GDB would fill the shadow buffer with a | |
123 | # breakpoint instruction). Avoid delete_breakpoints as that | |
124 | # doesn't record a pass/fail. | |
125 | gdb_test "delete" "" "delete all breakpoints" \ | |
126 | "Delete all breakpoints.*y or n.*$" "y" | |
127 | ||
128 | # Re-add symbols back. | |
129 | set test "file \$binfile" | |
130 | gdb_test_multiple "file $binfile" $test { | |
131 | -re "Are you sure you want to change the file. .*y or n. $" { | |
132 | send_gdb "y\n" | |
133 | exp_continue | |
134 | } | |
3453e7e4 | 135 | -re "Reading symbols from.*$gdb_prompt $" { |
08351840 PA |
136 | pass $test |
137 | } | |
138 | } | |
139 | ||
140 | # Run to another function now. With the bug, GDB would trip | |
141 | # on a spurious trap at foo. | |
142 | gdb_test "b bar" ".*reakpoint .* at .*" | |
143 | gdb_test "continue" "Breakpoint .*, bar .*" | |
144 | } | |
145 | } | |
146 | ||
d03de421 PA |
147 | foreach initial_load { "cmdline" "file" } { |
148 | # While it doesn't trigger the original bug this is a regression | |
149 | # test for, test with breakpoint always-inserted off for extra | |
150 | # coverage. | |
151 | foreach always_inserted { "off" "on" } { | |
152 | test_break $initial_load $always_inserted "break" | |
153 | if {![skip_hw_breakpoint_tests]} { | |
154 | test_break $initial_load $always_inserted "hbreak" | |
155 | } | |
08351840 PA |
156 | } |
157 | } |