1 # Copyright 2014-2023 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/>. */
16 # Test that "file" doesn't leave stale breakpoints planted in the
21 if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
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.
30 proc test_break { initial_load always_inserted break_command } {
31 global srcdir subdir binfile
35 append prefix "$initial_load: "
36 append prefix "always-inserted $always_inserted: "
37 append prefix "$break_command"
38 with_test_prefix "$prefix" {
41 set saved_gdbflags $GDBFLAGS
43 # See "used to behave differently" further below.
44 if { $initial_load == "file" } {
48 global last_loaded_file
50 # gdb_file_cmd sets this. This is what gdb_reload
51 # implementations use as binary.
52 set last_loaded_file $binfile
54 set GDBFLAGS "$GDBFLAGS $binfile"
58 gdb_reinitialize_dir $srcdir/$subdir
60 set GDBFLAGS $saved_gdbflags
68 gdb_test_no_output "set breakpoint always-inserted $always_inserted"
70 set test "$break_command foo"
71 gdb_test_multiple "$break_command foo" $test {
72 -re "No hardware breakpoint support in the target.*$gdb_prompt $" {
76 -re "Hardware breakpoints used exceeds limit.*$gdb_prompt $" {
80 -re "Cannot insert hardware breakpoint.*$gdb_prompt $" {
84 -re ".*reakpoint .* at .*$gdb_prompt $" {
89 # The breakpoint shouldn't be pending now.
90 gdb_test "info break" "y.*$hex.*in foo at.*" \
91 "breakpoint is not pending"
93 # Remove the file, while the breakpoint above is inserted in a
94 # function in the main objfile. GDB used to have a bug where
95 # it would mark the breakpoint as uninserted, but actually
96 # would leave it inserted in the target.
98 gdb_test_multiple "file" $test {
99 -re "Are you sure you want to change the file. .*y or n. $" {
103 -re "Discard symbol table from `.*'? .y or n. $" {
107 -re "No symbol file now\\.\r\n$gdb_prompt $" {
112 # This test used to behave differently depending on whether
113 # the program was first loaded through "file PROGRAM" or "gdb
116 gdb_test "info break" "breakpoint${ws}+keep${ws}+n${ws}+$hex${ws}*" \
117 "breakpoint is disabled"
119 # Now delete the breakpoint from GDB's tables, to make sure
120 # GDB doesn't reinsert it, masking the bug (with the bug, on
121 # re-insert, GDB would fill the shadow buffer with a
122 # breakpoint instruction). Avoid delete_breakpoints as that
123 # doesn't record a pass/fail.
124 gdb_test "delete" "" "delete all breakpoints" \
125 "Delete all breakpoints.*y or n.*$" "y"
127 # Re-add symbols back.
128 set test "file \$binfile"
129 gdb_test_multiple "file $binfile" $test {
130 -re "Are you sure you want to change the file. .*y or n. $" {
134 -re "Reading symbols from.*$gdb_prompt $" {
139 # Run to another function now. With the bug, GDB would trip
140 # on a spurious trap at foo.
141 gdb_test "b bar" ".*reakpoint .* at .*"
142 gdb_test "continue" "Breakpoint .*, bar .*"
146 foreach initial_load { "cmdline" "file" } {
147 # While it doesn't trigger the original bug this is a regression
148 # test for, test with breakpoint always-inserted off for extra
150 foreach always_inserted { "off" "on" } {
151 test_break $initial_load $always_inserted "break"
152 if {![skip_hw_breakpoint_tests]} {
153 test_break $initial_load $always_inserted "hbreak"