1 # Copyright 2022-2024 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 # Check the format of the error message given when a breakpoint
19 # In this case the breakpoint condition does not make use of inferior
20 # function calls, instead, the expression used for the breakpoint
21 # condition will throw an error when evaluated.
23 # We check that the correct breakpoint number appears in the error
24 # message, and that the error is reported at the correct source
29 if { [prepare_for_testing "failed to prepare" ${binfile} "${srcfile}" \
30 {debug c++}] == -1 } {
34 # Run to main so that we connect to the target if using 'target
35 # remote'. This means that the is_address_zero_readable, and the
36 # 'show breakpoint condition-evaluation' checks below will be
37 # performed with the remote connection in place.
38 if { ![runto_main] } {
42 # This test relies on reading address zero triggering a SIGSEGV.
43 if { [is_address_zero_readable] } {
47 proc run_test { cond_eval access_type bpexpr nloc } {
48 clean_restart ${::binfile}
50 if { ![runto_main] } {
54 if { $cond_eval ne "auto" } {
55 gdb_test_no_output "set breakpoint condition-evaluation ${cond_eval}"
58 # Setup the conditional breakpoint and record its number.
59 gdb_breakpoint "${bpexpr} if (*(${access_type} *) 0) == 0"
61 # This test aims to test that GDB displays the correct breakpoint number
62 # and location when there is an error testing a breakpoint condition,
63 # so it is important to hardcode the breakpoint number into the regex,
64 # along with the location, if applicable.
65 set bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*"]
68 # We hardcode location 2 because, for some reason, Clang will always
69 # order the debug information so we hit the second location. For
70 # simplicity the .c is ordered in such a way that GCC will also order
71 # the debug info to have us land on location 2.
75 "Error in testing condition for breakpoint ${bp_num}.2:" \
76 "Cannot access memory at address 0x0" \
78 "Breakpoint ${bp_num}.2, foo \\(c=49 ...\\) at \[^\r\n\]+:\[0-9\]+" \
79 "${::decimal}\\s+\[^\r\n\]+ breakpoint here\\. \[^\r\n\]+"]
84 "Error in testing condition for breakpoint ${bp_num}:" \
85 "Cannot access memory at address 0x0" \
87 "Breakpoint ${bp_num}, bar \\(\\) at \[^\r\n\]+:\[0-9\]+" \
88 "${::decimal}\\s+\[^\r\n\]+ breakpoint here\\. \[^\r\n\]+"]
92 # If we're using a remote target then conditions could be evaulated
93 # locally on the host, or on the remote target. Otherwise, conditions
94 # are always evaluated locally.
96 # Using "auto" will select the target if the target supports condition
97 # evaluation, otherwise, the local host will be used.
99 # So, we always include "auto", but then we look at the output of
100 # 'show breakpoint condition-evaluation', if this tells us that "auto"
101 # is using the target, then we specifically add "host" to the list of
104 set cond_eval_modes { "auto" }
106 gdb_test_multiple "show breakpoint condition-evaluation" "" {
107 -re -wrap "Breakpoint condition evaluation mode is auto \\(currently target\\)\\." {
108 lappend cond_eval_modes "host"
112 -re -wrap "Breakpoint condition evaluation mode is auto \\(currently host\\)\\." {
117 # Where the breakpoint will be placed.
118 set bp_line_multi_loc "foo"
119 set bp_line_single_loc [gdb_get_line_number "Single-location breakpoint here"]
121 foreach_with_prefix access_type { "char" "short" "int" "long long" } {
122 foreach_with_prefix cond_eval $cond_eval_modes {
123 with_test_prefix "multi-loc" {
124 run_test $cond_eval $access_type $bp_line_multi_loc 2
126 with_test_prefix "single-loc" {
127 run_test $cond_eval $access_type "${srcfile}:${bp_line_single_loc}" 1