hbreak-in-shr-unsupported.exp revision 1.6
1# Copyright 2014-2019 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 trying to inserting a hw breakpoint in a shared library
17# when the target doesn't support hw breakpoints doesn't silently
18# error out without informing the user.
19
20if {[skip_shlib_tests]} {
21    return -1
22}
23
24set main_src hbreak-in-shr-unsupported.c
25set lib_src hbreak-in-shr-unsupported-shr.c
26standard_testfile ${main_src} ${lib_src}
27set lib_basename hbreak-in-shr-unsupported-shr.so
28set lib_so [standard_output_file ${lib_basename}]
29
30set lib_opts "debug"
31set exec_opts [list debug shlib=${lib_so}]
32
33if [get_compiler_info] {
34    return -1
35}
36
37if { [gdb_compile_shlib ${srcdir}/${subdir}/${lib_src} ${lib_so} $lib_opts] != ""
38     || [gdb_compile ${srcdir}/${subdir}/${main_src} ${binfile} executable $exec_opts] != ""} {
39    untested "failed to compile"
40    return -1
41}
42
43clean_restart $binfile
44gdb_load_shlib $lib_so
45
46if ![runto_main] then {
47    fail "can't run to main"
48    return -1
49}
50
51set is_target_remote [gdb_is_target_remote]
52
53# Get main breakpoint out of the way.
54delete_breakpoints
55
56# Easier to test if GDB inserts breakpoints immediately.
57gdb_test_no_output "set breakpoint always-inserted on"
58
59# Force-disable Z1 packets, in case the target actually supports
60# these.
61if {$is_target_remote} {
62    gdb_test_no_output "set remote Z-packet off"
63}
64
65# Probe for hw breakpoints support.  With Z packets disabled, this
66# should always fail with remote targets.  For other targets, with no
67# way to force-disable hw breakpoints support, best we can do is skip
68# the remainder of the test if hardware breakpoint insertion in a
69# function in the main executable succeeds.
70set cant_insert_hbreak 0
71set supports_hbreak 0
72set test "probe hbreak support"
73gdb_test_multiple "hbreak main" $test {
74    -re "No hardware breakpoint support in the target.*$gdb_prompt $" {
75	pass $test
76    }
77    -re "Hardware breakpoints used exceeds limit.*$gdb_prompt $" {
78	pass $test
79    }
80    -re "Cannot insert hardware breakpoint.*$gdb_prompt $" {
81	set cant_insert_hbreak 1
82	set supports_hbreak 1
83	pass $test
84    }
85    -re "Hardware assisted breakpoint.*at.* file .*$srcfile, line.*$gdb_prompt $" {
86	set supports_hbreak 1
87	if {$is_target_remote} {
88	    # Z-packets have been force-disabled, so this shouldn't
89	    # happen.
90	    fail $test
91	} else {
92	    pass $test
93	}
94    }
95}
96
97if {!$supports_hbreak} {
98    unsupported "no hbreak support"
99    return
100}
101
102if {!$cant_insert_hbreak} {
103    unsupported "can't disable hw breakpoint support"
104    return
105}
106
107# Get previous hw breakpoint out of the way.
108delete_breakpoints
109
110# Without target support, this should always complain.  GDB used to
111# suppress the error if the breakpoint was set in a shared library.
112# While that makes sense for software breakpoints (the memory might be
113# unmapped), it doesn't for hardware breakpoints, as those by
114# definition are implemented using a mechanism that is not dependent
115# on being able to modify the target's memory.
116gdb_test "hbreak shrfunc" "Cannot insert hardware breakpoint.*" \
117    "hbreak shrfunc complains"
118
119gdb_test "info break" "hw breakpoint.*y.*$hex.*in shrfunc at.*" \
120    "breakpoint not pending"
121