Fix more cases of improper test names
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / signal.exp
1 # Copyright 2016 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 # 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
29 load_lib "trace-support.exp"
30
31 standard_testfile
32
33 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
34 return -1
35 }
36
37 if ![runto_main] {
38 fail "can't run to main to check for trace support"
39 return -1
40 }
41
42 if ![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
49 set syscall_insn ""
50
51 # Define the syscall instruction for each target.
52
53 if { [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.
63 clean_restart ${testfile}
64 if ![runto_main] {
65 fail "can't run to main"
66 return -1
67 }
68
69 gdb_test "break kill" "Breakpoint $decimal at .*"
70 gdb_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.
75 gdb_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.
80 gdb_test "continue" "Continuing\\..*Breakpoint $decimal, (.* in |__libc_|)kill \\(\\).*" \
81 "continue to kill, 2nd time"
82
83 gdb_test "display/i \$pc" ".*"
84
85 # Single step until we see a syscall insn or we reach the
86 # upper bound of loop iterations.
87 set msg "find syscall insn in kill"
88 set steps 0
89 set max_steps 1000
90 gdb_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
105 if {$steps == $max_steps} {
106 return
107 }
108
109 # Remove the display
110 gdb_test_no_output "delete display 1"
111
112 set syscall_insn_addr [get_hexadecimal_valueof "\$pc" "0"]
113 set syscall_insn_next 0
114 set test "x/2i \$pc"
115 gdb_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
121 delete_breakpoints
122 gdb_test "break start" "Breakpoint $decimal at .*"
123 gdb_continue_to_breakpoint "continue to start"
124
125 gdb_assert { 0 == [get_integer_valueof "counter" "1"] } "counter is zero"
126
127 delete_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.
132 gdb_test "trace *$syscall_insn_addr" "Tracepoint $decimal at .*" \
133 "tracepoint on syscall instruction"
134 set tpnum [get_integer_valueof "\$bpnum" 0]
135 gdb_test "trace *$syscall_insn_next" "Tracepoint $decimal at .*" \
136 "tracepoint on instruction following syscall instruction"
137
138 gdb_test "break end" "Breakpoint $decimal at .*"
139
140 gdb_test_no_output "tstart"
141 gdb_test "continue" ".*Breakpoint.* end .*at.*$srcfile.*" \
142 "continue to end"
143 gdb_test_no_output "tstop"
144
145 set iterations [get_integer_valueof "iterations" "0"]
146
147 gdb_assert { $iterations == [get_integer_valueof "counter" "0"] } \
148 "iterations equals to counter"
149
150 # Record the hit times of each tracepoint in this array.
151 array set tracepoint_hits { }
152 for { set i $tpnum } { $i < [expr $tpnum + 2] } { incr i } {
153 set tracepoint_hits($i) 0
154 }
155
156 while { 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
175 for { set i $tpnum } { $i < [expr $tpnum + 2] } { incr i } {
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 }
186 }
This page took 0.034526 seconds and 5 git commands to generate.