]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.trace/signal.exp
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / signal.exp
CommitLineData
e2882c85 1# Copyright 2016-2018 Free Software Foundation, Inc.
5c5dc57f
YQ
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# 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
27# signal handler.
28
29load_lib "trace-support.exp"
30
31standard_testfile
32
5b362f04 33if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
5c5dc57f
YQ
34 return -1
35}
36
37if ![runto_main] {
bc6c7af4 38 fail "can't run to main to check for trace support"
5c5dc57f
YQ
39 return -1
40}
41
42if ![gdb_target_supports_trace] {
43 unsupported "target does not support trace"
44 return -1
45}
46
47# Step 1, find the syscall instruction address.
48
49set syscall_insn ""
50
51# Define the syscall instruction for each target.
52
53if { [istarget "i\[34567\]86-*-linux*"] || [istarget "x86_64-*-linux*"] } {
54 set syscall_insn "\[ \t\](int|syscall|sysenter)\[ \t\]"
55} elseif { [istarget "aarch64*-*-linux*"] || [istarget "arm*-*-linux*"] } {
56 set syscall_insn "\[ \t\](swi|svc)\[ \t\]"
57} else {
58 unsupported "unknown syscall instruction"
59 return -1
60}
61
62# Start with a fresh gdb.
63clean_restart ${testfile}
64if ![runto_main] {
bc6c7af4 65 fail "can't run to main"
5c5dc57f
YQ
66 return -1
67}
68
69gdb_test "break kill" "Breakpoint $decimal at .*"
70gdb_test "handle SIGABRT nostop noprint pass" ".*" "pass SIGABRT"
71
72# Hit the breakpoint on $syscall for the first time. In this time,
73# we will let PLT resolution done, and the number single steps we will
74# do later will be reduced.
75gdb_test "continue" "Continuing\\..*Breakpoint $decimal, (.* in |__libc_|)kill \\(\\).*" \
76 "continue to kill, 1st time"
77
78# Hit the breakpoint on $syscall for the second time. In this time,
79# the address of syscall insn and next insn of syscall are recorded.
80gdb_test "continue" "Continuing\\..*Breakpoint $decimal, (.* in |__libc_|)kill \\(\\).*" \
81 "continue to kill, 2nd time"
82
83gdb_test "display/i \$pc" ".*"
84
85# Single step until we see a syscall insn or we reach the
86# upper bound of loop iterations.
87set msg "find syscall insn in kill"
88set steps 0
89set max_steps 1000
90gdb_test_multiple "stepi" $msg {
91 -re ".*$syscall_insn.*$gdb_prompt $" {
92 pass $msg
93 }
94 -re "x/i .*=>.*\r\n$gdb_prompt $" {
95 incr steps
96 if {$steps == $max_steps} {
97 fail $msg
98 } else {
99 send_gdb "stepi\n"
100 exp_continue
101 }
102 }
103}
104
105if {$steps == $max_steps} {
106 return
107}
108
109# Remove the display
110gdb_test_no_output "delete display 1"
111
112set syscall_insn_addr [get_hexadecimal_valueof "\$pc" "0"]
113set syscall_insn_next 0
114set test "x/2i \$pc"
115gdb_test_multiple $test $test {
116 -re "$hex .*:\[^\r\n\]+\r\n\[ \]+($hex).*\.\r\n$gdb_prompt $" {
117 set syscall_insn_next $expect_out(1,string)
118 }
119}
120
121delete_breakpoints
122gdb_test "break start" "Breakpoint $decimal at .*"
123gdb_continue_to_breakpoint "continue to start"
124
125gdb_assert { 0 == [get_integer_valueof "counter" "1"] } "counter is zero"
126
127delete_breakpoints
128
129# Step 2, set tracepoints on syscall instruction and the next one.
130# It is more likely to get signal on these two places when GDBserver
131# is doing step-over.
132gdb_test "trace *$syscall_insn_addr" "Tracepoint $decimal at .*" \
133 "tracepoint on syscall instruction"
134set tpnum [get_integer_valueof "\$bpnum" 0]
135gdb_test "trace *$syscall_insn_next" "Tracepoint $decimal at .*" \
136 "tracepoint on instruction following syscall instruction"
137
138gdb_test "break end" "Breakpoint $decimal at .*"
139
140gdb_test_no_output "tstart"
141gdb_test "continue" ".*Breakpoint.* end .*at.*$srcfile.*" \
142 "continue to end"
143gdb_test_no_output "tstop"
144
145set iterations [get_integer_valueof "iterations" "0"]
146
147gdb_assert { $iterations == [get_integer_valueof "counter" "0"] } \
148 "iterations equals to counter"
149
150# Record the hit times of each tracepoint in this array.
151array set tracepoint_hits { }
152for { set i $tpnum } { $i < [expr $tpnum + 2] } { incr i } {
153 set tracepoint_hits($i) 0
154}
155
156while { 1 } {
157 set test "tfind"
158 set idx 0
159 gdb_test_multiple $test $test {
160 -re "Found trace frame $decimal, tracepoint ($decimal).*\r\n$gdb_prompt $" {
161 set idx [expr $expect_out(1,string)]
162 incr tracepoint_hits($idx)
163 }
164 -re "Target failed to find requested trace frame\..*\r\n$gdb_prompt $" {
165 set idx 0
166 }
167 }
168 if {$idx == 0} {
169 break
170 }
171}
172
173# Step 3, check the number of collections on each tracepoint.
174
175for { set i $tpnum } { $i < [expr $tpnum + 2] } { incr i } {
5b061e98
YQ
176
177 if { $tracepoint_hits($i) == $iterations } {
178 pass "tracepoint $i hit $iterations times"
179 } elseif { $tracepoint_hits($i) > $iterations } {
180 # GDBserver deliver the signal while stepping over tracepoint,
181 # so it is possible that a tracepoint is collected twice.
182 pass "tracepoint $i hit $iterations times (spurious collection)"
183 } else {
184 fail "tracepoint $i hit $iterations times"
185 }
5c5dc57f 186}