1 # Copyright
2016-2022 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 # This is to test whether GDBserver or other remote stubs deliver
signal
17 # to the inferior
while step over thread. The
program signal.c sends
18 #
signal SIGABRT to itself via kill syscall. The test sets tracepoints
19 # syscall instruction and the next one
, and it is quite likely that
20 # GDBserver gets the
signal when it steps over thread and does the
21 # collection.
If GDBserver doesn
't deliver signal in thread step over,
22 # one collection is got for one tracepoint hit. Otherwise, there may
23 # be two collections for one tracepoint hit, because tracepoint is
24 # collected once before step over, the program goes into signal handler
25 # (because signal is delivered in step over), and program goes back
26 # to the tracepoint again (one more collection) after returns from
29 load_lib "trace-support.exp"
31 if [target_info exists gdb,nosignals] {
32 verbose "Skipping signal.exp because of nosignals."
38 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
46 if ![gdb_target_supports_trace] {
47 unsupported "target does not support trace"
51 # Step 1, find the syscall instruction address.
55 # Define the syscall instruction for each target.
57 if { [istarget "i\[34567\]86-*-linux*"] || [istarget "x86_64-*-linux*"] } {
58 set syscall_insn "\[ \t\](int|syscall|sysenter)\[ \t\]"
59 } elseif { [istarget "aarch64*-*-linux*"] || [istarget "arm*-*-linux*"] } {
60 set syscall_insn "\[ \t\](swi|svc)\[ \t\]"
62 unsupported "unknown syscall instruction"
66 # Start with a fresh gdb.
67 clean_restart ${testfile}
72 gdb_breakpoint "kill" qualified
73 gdb_test "handle SIGABRT nostop noprint pass" ".*" "pass SIGABRT"
75 # Hit the breakpoint on $syscall for the first time. In this time,
76 # we will let PLT resolution done, and the number single steps we will
77 # do later will be reduced.
78 gdb_test "continue" "Continuing\\..*Breakpoint $decimal, (.* in |__libc_|)kill \\(\\).*" \
79 "continue to kill, 1st time"
81 # Hit the breakpoint on $syscall for the second time. In this time,
82 # the address of syscall insn and next insn of syscall are recorded.
83 gdb_test "continue" "Continuing\\..*Breakpoint $decimal, (.* in |__libc_|)kill \\(\\).*" \
84 "continue to kill, 2nd time"
86 gdb_test "display/i \$pc" ".*"
88 # Single step until we see a syscall insn or we reach the
89 # upper bound of loop iterations.
90 set msg "find syscall insn in kill"
93 gdb_test_multiple "stepi" $msg {
94 -re ".*$syscall_insn.*$gdb_prompt $" {
97 -re "x/i .*=>.*\r\n$gdb_prompt $" {
99 if {$steps == $max_steps} {
108 if {$steps == $max_steps} {
113 gdb_test_no_output "delete display 1"
115 set syscall_insn_addr [get_hexadecimal_valueof "\$pc" "0"]
116 set syscall_insn_next 0
118 gdb_test_multiple $test $test {
119 -re "$hex .*:\[^\r\n\]+\r\n\[ \]+($hex).*\.\r\n$gdb_prompt $" {
120 set syscall_insn_next $expect_out(1,string)
125 gdb_breakpoint "start" qualified
126 gdb_continue_to_breakpoint "continue to start"
128 gdb_assert { 0 == [get_integer_valueof "counter" "1"] } "counter is zero"
132 # Step 2, set tracepoints on syscall instruction and the next one.
133 # It is more likely to get signal on these two places when GDBserver
134 # is doing step-over.
135 gdb_test "trace *$syscall_insn_addr" "Tracepoint $decimal at .*" \
136 "tracepoint on syscall instruction"
137 set tpnum [get_integer_valueof "\$bpnum" 0]
138 gdb_test "trace *$syscall_insn_next" "Tracepoint $decimal at .*" \
139 "tracepoint on instruction following syscall instruction"
141 gdb_breakpoint "end" qualified
143 gdb_test_no_output "tstart"
144 gdb_test "continue" ".*Breakpoint.* end .*at.*$srcfile.*" \
146 gdb_test_no_output "tstop"
148 set iterations [get_integer_valueof "iterations" "0"]
150 gdb_assert { $iterations == [get_integer_valueof "counter" "0"] } \
151 "iterations equals to counter"
153 # Record the hit times of each tracepoint in this array.
154 array set tracepoint_hits { }
155 for { set i $tpnum } { $i < [expr $tpnum + 2] } { incr i } {
156 set tracepoint_hits($i) 0
162 gdb_test_multiple $test $test {
163 -re "Found trace frame $decimal, tracepoint ($decimal).*\r\n$gdb_prompt $" {
164 set idx [expr $expect_out(1,string)]
165 incr tracepoint_hits($idx)
167 -re "Target failed to find requested trace frame\..*\r\n$gdb_prompt $" {
176 # Step 3, check the number of collections on each tracepoint.
178 for { set i $tpnum } { $i < [expr $tpnum + 2] } { incr i } {
180 if { $tracepoint_hits($i) == $iterations } {
181 pass "tracepoint $i hit $iterations times"
182 } elseif { $tracepoint_hits($i) > $iterations } {
183 # GDBserver deliver the signal while stepping over tracepoint,
184 # so it is possible that a tracepoint is collected twice.
185 pass "tracepoint $i hit $iterations times (spurious collection)"
187 fail "tracepoint $i hit $iterations times"