xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/hw-sw-break-same-address.exp (revision 924795e69c8bb3f17afd8fcbb799710cc1719dc4)
1# Copyright 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# Test that inserting a hardware and a software breakpoint at the same
17# address behaves as expected.  GDB used to consider hw and sw
18# breakpoint locations as duplicate locations, which would lead to bad
19# behavior.  See PR gdb/25741.
20
21if {[skip_hw_breakpoint_tests]} {
22    return 0
23}
24
25set test hbreak
26set srcfile ${test}.c
27if { [prepare_for_testing "failed to prepare" ${test} ${srcfile}] } {
28    return -1
29}
30
31if ![runto_main] {
32    fail "can't run to main"
33    return -1
34}
35
36delete_breakpoints
37
38gdb_test_no_output "set breakpoint always-inserted on"
39gdb_test_no_output "set breakpoint condition-evaluation host"
40gdb_test_no_output "set confirm off"
41
42# Test inserting a hw breakpoint first, then a sw breakpoint at the
43# same address.
44with_test_prefix "hw-sw" {
45    gdb_test "hbreak main" \
46	"Hardware assisted breakpoint .* at .*" \
47	"hbreak"
48
49    gdb_test "break main" \
50	"Note: breakpoint .* also set at .*\r\nBreakpoint .* at .*" \
51	"break"
52
53    # A bad GDB debugging against GDBserver would output a warning
54    # here:
55    #  delete breakpoints
56    #  warning: Error removing breakpoint 3
57    #  (gdb) FAIL: gdb.base/hw-sw-break-same-address.exp: hw-sw: delete breakpoints
58    gdb_test_no_output "delete breakpoints"
59}
60
61# Now the opposite: test inserting a sw breakpoint first, then a hw
62# breakpoint at the same address.
63with_test_prefix "sw-hw" {
64    gdb_test "break main" \
65	"Breakpoint .* at .*" \
66	"break"
67
68    gdb_test "hbreak main" \
69	"Note: breakpoint .* also set at .*\r\nHardware assisted breakpoint .* at .*" \
70	"hbreak"
71
72    gdb_test_no_output "delete breakpoints"
73}
74