xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/cond-eval-mode.exp (revision 8b657b0747480f8989760d71343d6dd33f8d4cf9)
1#   Copyright 2012-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 'set breakpoint condition-evaluation' settings
17
18# The skip_hw_watchpoint_tests checks if watchpoints are supported by the
19# processor.  On PowerPC, the check runs a small test program under gdb
20# to determine if the Power processor supports HW watchpoints.  The check
21# must be done before starting the test so as to not disrupt the execution
22# of the actual test.
23
24set skip_hw_watchpoint_tests_p [skip_hw_watchpoint_tests]
25
26standard_testfile
27
28if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
29    return -1
30}
31
32if {![runto_main]} {
33    return 0
34}
35
36set test_host "set breakpoint condition-evaluation host"
37set test_auto "set breakpoint condition-evaluation auto"
38set test_target "set breakpoint condition-evaluation target"
39
40gdb_test_no_output $test_host
41gdb_test_no_output $test_auto
42
43# If target-side condition evaluation is not supported, this warning will be
44# displayed.
45set warning "warning: Target does not support breakpoint condition evaluation.\r\nUsing host evaluation mode instead."
46
47gdb_test_multiple $test_target $test_target {
48    -re "$warning\r\n$gdb_prompt $" {
49	unsupported $test_target
50	return -1
51    }
52
53    -re "^$test_target\r\n$gdb_prompt $" {
54	pass $test_target
55    }
56}
57
58# We now know that the target supports target-side conditional
59# evaluation.  Now make sure we can force-disable the
60# ConditionalBreakpoints RSP feature.
61if [gdb_is_target_remote] {
62    gdb_test_no_output "set remote conditional-breakpoints-packet off"
63
64    gdb_test $test_target "$warning" \
65	"set breakpoint condition-evaluation target, with support disabled"
66
67    # Confirm we can re-enable it.
68    gdb_test_no_output "set remote conditional-breakpoints-packet on"
69    gdb_test_no_output $test_target "restore $test_target"
70}
71
72# Test setting a condition in a breakpoint.  BREAK_COMMAND is the
73# break/hwatch command to test.
74#
75proc test_break { break_command } {
76    global gdb_prompt
77
78    with_test_prefix "$break_command" {
79	delete_breakpoints
80
81	gdb_test "$break_command foo" "reakpoint.* at .*"
82
83	# A condition that evals true.
84	gdb_test "condition \$bpnum cond_global==0" ".*"
85
86	set can_do_cmd 0
87
88	set test "continue"
89	gdb_test_multiple $test $test {
90	    -re "You may have requested too many.*$gdb_prompt $" {
91		pass $test
92	    }
93	    -re "Breakpoint .*, foo .*$gdb_prompt $" {
94		pass $test
95		set can_do_cmd 1
96	    }
97	}
98
99	if { !$can_do_cmd } {
100	    unsupported "no target support"
101	    return
102	}
103
104	delete_breakpoints
105
106	gdb_test "$break_command foo" ".*reakpoint .* at .*"
107
108	# A condition that evals false.
109	gdb_test "condition \$bpnum cond_global==1" ".*"
110
111	gdb_test "b bar" "Breakpoint .* at .*"
112
113	gdb_test "continue" "Breakpoint .*, bar .*"
114    }
115}
116
117# Test setting conditions in watchpoints.  WATCH_COMMAND is the watch
118# command to test.
119#
120proc test_watch { watch_command } {
121    global gdb_prompt
122    global skip_hw_watchpoint_tests_p
123
124    with_test_prefix "$watch_command" {
125	if {$skip_hw_watchpoint_tests_p} {
126	    unsupported "no target support"
127	    return
128	}
129
130	delete_breakpoints
131
132	gdb_test "$watch_command global" ".*atchpoint .*: global.*"
133
134	# A condition that evals true.
135	gdb_test "condition \$bpnum cond_global==0" ".*"
136
137	set can_do_cmd 0
138
139	set test "continue"
140	gdb_test_multiple $test $test {
141	    -re "You may have requested too many.*$gdb_prompt $" {
142		pass $test
143	    }
144	    -re "atchpoint .*: global.*$gdb_prompt $" {
145		pass $test
146		set can_do_cmd 1
147	    }
148	}
149
150	if { !$can_do_cmd } {
151	    unsupported "no target support"
152	    return
153	}
154
155	delete_breakpoints
156
157	gdb_test "$watch_command global" ".*atchpoint .*: global.*"
158
159	# A condition that evals false.
160	gdb_test "condition \$bpnum cond_global==1" ".*"
161
162	gdb_test "b bar" "Breakpoint .* at .*"
163
164	gdb_test "continue" "Breakpoint .*, bar .*"
165    }
166}
167
168foreach break_command { "break" "hbreak" } {
169    test_break $break_command
170}
171
172foreach watch_command { "watch" "rwatch" "awatch" } {
173    test_watch $watch_command
174}
175