]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/break-unload-file.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / break-unload-file.exp
1 # Copyright 2014-2023 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 # Test that "file" doesn't leave stale breakpoints planted in the
17 # target.
18
19 standard_testfile
20
21 if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
22 return -1
23 }
24
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.
29 #
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 }
57
58 gdb_reinitialize_dir $srcdir/$subdir
59 gdb_reload
60 set GDBFLAGS $saved_gdbflags
61
62 if {![runto_main]} {
63 return
64 }
65
66 delete_breakpoints
67
68 gdb_test_no_output "set breakpoint always-inserted $always_inserted"
69
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 $" {
73 unsupported $test
74 return
75 }
76 -re "Hardware breakpoints used exceeds limit.*$gdb_prompt $" {
77 unsupported $test
78 return
79 }
80 -re "Cannot insert hardware breakpoint.*$gdb_prompt $" {
81 unsupported $test
82 return
83 }
84 -re ".*reakpoint .* at .*$gdb_prompt $" {
85 pass $test
86 }
87 }
88
89 # The breakpoint shouldn't be pending now.
90 gdb_test "info break" "y.*$hex.*in foo at.*" \
91 "breakpoint is not pending"
92
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.
97 set test "file"
98 gdb_test_multiple "file" $test {
99 -re "Are you sure you want to change the file. .*y or n. $" {
100 send_gdb "y\n"
101 exp_continue
102 }
103 -re "Discard symbol table from `.*'? .y or n. $" {
104 send_gdb "y\n"
105 exp_continue
106 }
107 -re "No symbol file now\\.\r\n$gdb_prompt $" {
108 pass $test
109 }
110 }
111
112 # This test used to behave differently depending on whether
113 # the program was first loaded through "file PROGRAM" or "gdb
114 # PROGRAM".
115 set ws "\[ \t\]"
116 gdb_test "info break" "breakpoint${ws}+keep${ws}+n${ws}+$hex${ws}*" \
117 "breakpoint is disabled"
118
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"
126
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. $" {
131 send_gdb "y\n"
132 exp_continue
133 }
134 -re "Reading symbols from.*$gdb_prompt $" {
135 pass $test
136 }
137 }
138
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 .*"
143 }
144 }
145
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
149 # coverage.
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"
154 }
155 }
156 }