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