1 # Copyright 2014 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 {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
25 if ![runto_main] then {
26 fail "Can't run to main"
30 # Run the test proper. ALWAYS_INSERT determines whether
31 # always-inserted mode is on/off, and BREAK_COMMAND is the break
32 # command being tested.
34 proc test_break { always_inserted break_command } {
35 global gdb_prompt binfile hex
37 with_test_prefix "always-inserted $always_inserted: $break_command" {
38 clean_restart $binfile
40 if ![runto_main] then {
41 fail "Can't run to main"
47 gdb_test_no_output "set breakpoint always-inserted $always_inserted"
49 set test "$break_command foo"
50 gdb_test_multiple "$break_command foo" $test {
51 -re "No hardware breakpoint support in the target.*$gdb_prompt $" {
55 -re "Hardware breakpoints used exceeds limit.*$gdb_prompt $" {
59 -re "Cannot insert hardware breakpoint.*$gdb_prompt $" {
63 -re ".*reakpoint .* at .*$gdb_prompt $" {
68 # The breakpoint shouldn't be pending now.
69 gdb_test "info break" "y.*$hex.*in foo at.*" \
70 "breakpoint is not pending"
72 # Remove the file, while the breakpoint above is inserted in a
73 # function in the main objfile. GDB used to have a bug where
74 # it would mark the breakpoint as uninserted, but actually
75 # would leave it inserted in the target.
77 gdb_test_multiple "file" $test {
78 -re "Are you sure you want to change the file. .*y or n. $" {
82 -re "Discard symbol table from `.*'? .y or n. $" {
86 -re "No symbol file now\\.\r\n$gdb_prompt $" {
91 gdb_test "info break" "y.*PENDING.*foo" \
92 "breakpoint is pending"
94 # Now delete the breakpoint from GDB's tables, to make sure
95 # GDB doesn't reinsert it, masking the bug (with the bug, on
96 # re-insert, GDB would fill the shadow buffer with a
97 # breakpoint instruction). Avoid delete_breakpoints as that
98 # doesn't record a pass/fail.
99 gdb_test "delete" "" "delete all breakpoints" \
100 "Delete all breakpoints.*y or n.*$" "y"
102 # Re-add symbols back.
103 set test "file \$binfile"
104 gdb_test_multiple "file $binfile" $test {
105 -re "Are you sure you want to change the file. .*y or n. $" {
109 -re "Reading symbols from.*done.*$gdb_prompt $" {
114 # Run to another function now. With the bug, GDB would trip
115 # on a spurious trap at foo.
116 gdb_test "b bar" ".*reakpoint .* at .*"
117 gdb_test "continue" "Breakpoint .*, bar .*"
121 # While it doesn't trigger the original bug this is a regression test
122 # for, test with breakpoint always-inserted off for extra coverage.
123 foreach always_inserted { "off" "on" } {
124 test_break $always_inserted "break"
125 if {![skip_hw_breakpoint_tests]} {
126 test_break $always_inserted "hbreak"