1 # Copyright
2022-2023 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 # Some simple tests of inferior function calls from breakpoint
17 # conditions
, in a single
-threaded inferior.
19 # Test what happens when the inferior function
(from a breakpoint
20 # condition
) either hits a nested breakpoint
, or segfaults.
24 if { [build_executable
"failed to prepare" ${binfile} "${srcfile}" \
29 set bp_1_line
[gdb_get_line_number
"First breakpoint"]
30 set bp_2_line
[gdb_get_line_number
"Second breakpoint"]
31 set segv_line
[gdb_get_line_number
"Segfault here"]
33 # Start GDB based
on TARGET_ASYNC and TARGET_NON_STOP
, and
then runto
35 proc start_gdb_and_runto_main
{ target_async target_non_stop
} {
36 save_vars
{ ::GDBFLAGS
} {
38 " -ex \"maint set target-non-stop $target_non_stop\""
40 " -ex \"maintenance set target-async ${target_async}\""
42 clean_restart $
{::binfile
}
45 if { ![runto_main
] } {
52 # Start GDB according to ASYNC_P and NON_STOP_P
, then setup a
53 # conditional breakpoint. The breakpoint condition includes an
54 # inferior function
call that will itself hit a breakpoint. Check how
55 # GDB reports this to the user.
56 proc_with_prefix run_cond_hits_breakpoint_test
{ async_p non_stop_p
} {
57 if { [start_gdb_and_runto_main $async_p $non_stop_p
] == -1 } {
61 # Setup the conditional breakpoint and record its number.
62 gdb_breakpoint
"${::srcfile}:${::bp_1_line} if (func_bp ())"
63 set bp_1_num
[get_integer_valueof
"\$bpnum" "*UNKNOWN*" \
64 "get number of first breakpoint"]
66 # Setup a breakpoint inside func_bp.
67 gdb_breakpoint
"${::srcfile}:${::bp_2_line}"
68 set bp_2_num
[get_integer_valueof
"\$bpnum" "*UNKNOWN*" \
69 "get number of second breakpoint"]
75 "Breakpoint ${bp_2_num}, func_bp \\(\\) at \[^\r\n\]+:${::bp_2_line}" \
76 "${::decimal}\\s+\[^\r\n\]+Second breakpoint\[^\r\n\]+" \
77 "Error in testing condition for breakpoint ${bp_1_num}:" \
78 "The program being debugged stopped while in a function called from GDB\\." \
79 "Evaluation of the expression containing the function" \
80 "\\(func_bp\\) will be abandoned\\." \
81 "When the function is done executing, GDB will silently stop\\."]
84 # Start GDB according to ASYNC_P and NON_STOP_P
, then call an inferior
85 # function. The inferior function being called will itself have a
86 # breakpoint within it. Check how GDB reports this to the user.
87 proc_with_prefix run_call_hits_breakpoint_test
{ async_p non_stop_p
} {
88 if { [start_gdb_and_runto_main $async_p $non_stop_p
] == -1 } {
92 # Setup a breakpoint inside func_bp.
93 gdb_breakpoint
"${::srcfile}:${::bp_2_line}"
94 set bp_2_num
[get_integer_valueof
"\$bpnum" "*UNKNOWN*" \
95 "get number of second breakpoint"]
98 gdb_test
"call func_bp ()" \
101 "Breakpoint ${bp_2_num}, func_bp \\(\\) at \[^\r\n\]+:${::bp_2_line}" \
102 "${::decimal}\\s+\[^\r\n\]+Second breakpoint\[^\r\n\]+" \
103 "The program being debugged stopped while in a function called from GDB\\." \
104 "Evaluation of the expression containing the function" \
105 "\\(func_bp\\) will be abandoned\\." \
106 "When the function is done executing, GDB will silently stop\\."]
109 # Start GDB according to ASYNC_P and NON_STOP_P
, then setup a
110 # conditional breakpoint. The breakpoint condition includes an
111 # inferior function
call that segfaults. Check how GDB reports this
113 proc_with_prefix run_cond_hits_segfault_test
{ async_p non_stop_p
} {
114 if { [start_gdb_and_runto_main $async_p $non_stop_p
] == -1 } {
118 # This test relies
on the inferior segfaulting when trying to
119 # access address zero.
120 if { [is_address_zero_readable
] } {
121 unsupported
"address zero is readable"
125 # Setup the conditional breakpoint and record its number.
126 gdb_breakpoint
"${::srcfile}:${::bp_1_line} if (func_segfault ())"
127 set bp_1_num
[get_integer_valueof
"\$bpnum" "*UNKNOWN*" \
128 "get number of first breakpoint"]
130 gdb_test
"continue" \
134 "Program received signal SIGSEGV, Segmentation fault\\." \
135 "${::hex} in func_segfault \\(\\) at \[^\r\n\]+:${::segv_line}" \
136 "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+" \
137 "Error in testing condition for breakpoint ${bp_1_num}:" \
138 "The program being debugged was signaled while in a function called from GDB\\." \
139 "GDB remains in the frame where the signal was received\\." \
140 "To change this behavior use \"set unwindonsignal on\"\\." \
141 "Evaluation of the expression containing the function" \
142 "\\(func_segfault\\) will be abandoned\\." \
143 "When the function is done executing, GDB will silently stop\\."]
146 # Start GDB according to ASYNC_P and NON_STOP_P
, then call an inferior
147 # function. The inferior function will segfault. Check how GDB
148 # reports this to the user.
149 proc_with_prefix run_call_hits_segfault_test
{ async_p non_stop_p
} {
150 if { [start_gdb_and_runto_main $async_p $non_stop_p
] == -1 } {
154 # This test relies
on the inferior segfaulting when trying to
155 # access address zero.
156 if { [is_address_zero_readable
] } {
157 unsupported
"address zero is readable"
161 gdb_test
"call func_segfault ()" \
164 "Program received signal SIGSEGV, Segmentation fault\\." \
165 "${::hex} in func_segfault \\(\\) at \[^\r\n\]+:${::segv_line}" \
166 "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+" \
167 "The program being debugged was signaled while in a function called from GDB\\." \
168 "GDB remains in the frame where the signal was received\\." \
169 "To change this behavior use \"set unwindonsignal on\"\\." \
170 "Evaluation of the expression containing the function" \
171 "\\(func_segfault\\) will be abandoned\\." \
172 "When the function is done executing, GDB will silently stop\\."]
175 foreach_with_prefix target_async
{ "on" "off" } {
176 foreach_with_prefix target_non_stop
{ "on" "off" } {
177 run_cond_hits_breakpoint_test $target_async $target_non_stop
178 run_call_hits_breakpoint_test $target_async $target_non_stop
180 run_cond_hits_segfault_test $target_async $target_non_stop
181 run_call_hits_segfault_test $target_async $target_non_stop