Testsuite: Fix ambiguous "break" due to libinproctrace
[binutils-gdb.git] / gdb / testsuite / gdb.trace / ftrace.exp
1 # Copyright 2011-2018 Free Software Foundation, Inc.
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 3 of the License, or
5 # (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14
15 load_lib "trace-support.exp"
16
17 standard_testfile
18 set executable $testfile
19 set expfile $testfile.exp
20
21 # Some targets have leading underscores on assembly symbols.
22 set additional_flags [gdb_target_symbol_prefix_flags]
23
24 if [prepare_for_testing "failed to prepare" $executable $srcfile \
25 [list debug $additional_flags]] {
26 return -1
27 }
28
29 if ![runto_main] {
30 fail "can't run to main to check for trace support"
31 return -1
32 }
33
34 if ![gdb_target_supports_trace] {
35 unsupported "target does not support trace"
36 return -1
37 }
38
39 set libipa [get_in_proc_agent]
40 set remote_libipa [gdb_load_shlib $libipa]
41
42 # Can't use prepare_for_testing, because that splits compiling into
43 # building objects and then linking, and we'd fail with "linker input
44 # file unused because linking not done" when building the object.
45
46 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
47 executable [list debug $additional_flags shlib=$libipa] ] != "" } {
48 untested "failed to compile"
49 return -1
50 }
51 clean_restart ${executable}
52
53 if ![runto_main] {
54 fail "can't run to main for ftrace tests"
55 return 0
56 }
57
58 proc run_trace_experiment {} {
59
60 gdb_test "continue" \
61 ".*Breakpoint \[0-9\]+, begin .*" \
62 "advance to trace begin"
63
64 gdb_test_no_output "tstart" "start trace experiment"
65
66 # Fast tracepoint can be set in signal handler, so gdb_collect in
67 # IPA shouldn't call any non-async-signal-safe functions. It is
68 # impractical to list all non-async-signal-safe functions, and set
69 # breakpoints on them, so choose malloc only in this test.
70 gdb_test "b -q malloc"
71
72 # Performance-wise, gdb_collect in IPA shouldn't call any syscall
73 # in order to keep fast tracepoint fast enough.
74 global gdb_prompt
75 set test "catch syscall"
76 gdb_test_multiple $test $test {
77 -re "The feature \'catch syscall\' is not supported.*\r\n$gdb_prompt $" {
78 }
79 -re ".*$gdb_prompt $" {
80 pass $test
81 }
82 }
83
84 global decimal
85 set test "advance through tracing"
86 gdb_test_multiple "continue" $test {
87 -re "Thread 2 .* hit Catchpoint $decimal \\(call to syscall .*\\).*\r\n$gdb_prompt $" {
88 # IPA starts a helper thread, which calls accept. Ignore it.
89 send_gdb "continue\n"
90 exp_continue
91 }
92 -re "Breakpoint $decimal, end .*$gdb_prompt $" {
93 pass $test
94 }
95 }
96
97 gdb_test "tstatus" ".*Trace .*" "check on trace status"
98
99 gdb_test "tstop" "" ""
100 }
101
102 proc test_fast_tracepoints {} {
103 global gdb_prompt
104
105 set fourgood 0
106
107 gdb_breakpoint "begin" qualified
108
109 gdb_breakpoint "end" qualified
110
111 gdb_test "print gdb_agent_gdb_trampoline_buffer_error" ".*" ""
112
113 gdb_test "ftrace set_point" "Fast tracepoint .*" \
114 "fast tracepoint at a long insn"
115
116 gdb_trace_setactions "collect at set_point: define actions" \
117 "" \
118 "collect globvar, anarg" "^$"
119
120 # Make a test of shorter fast tracepoints, 32-bit x86 only
121
122 if { [istarget "i?86-*-*"] } {
123
124 # A Linux target needs to be able to allocate trampolines in the
125 # 16-bit range, check mmap_min_addr so we can warn testers.
126 if { [istarget "i?86-*-linux*"] } {
127
128 set minaddr [exec sh -c "cat /proc/sys/vm/mmap_min_addr"]
129
130 if { [expr $minaddr > 64512] } {
131 warning "mmap_min_addr > 64512, fast tracepoint will fail"
132 warning "do \"sudo sysctl -w vm.mmap_min_addr=32768\" to adjust"
133 }
134 }
135
136 gdb_test_multiple "ftrace four_byter" "set 4-byte fast tracepoint" {
137 -re "May not have a fast tracepoint at .*\r\n$gdb_prompt $" {
138 pass "4-byte fast tracepoint could not be set"
139 }
140 -re "Fast tracepoint .*\r\n$gdb_prompt $" {
141 pass "4-byte fast tracepoint is set"
142 set fourgood 1
143 }
144 }
145
146 if { $fourgood } {
147
148 gdb_trace_setactions "collect at four_byter: define actions" \
149 "" \
150 "collect globvar, anarg" "^$"
151 }
152 }
153
154 run_trace_experiment
155
156 gdb_test "tfind pc *set_point" "Found trace frame .*" \
157 "tfind set_point frame, first time"
158
159 gdb_test "print globvar" " = 1"
160
161 gdb_test "tfind pc *set_point" "Found trace frame .*" \
162 "tfind set_point frame, second time"
163
164 setup_kfail "gdb/13808" "x86_64-*-linux*"
165 gdb_test "print anarg" " = 200"
166
167 gdb_test "tfind start" "Found trace frame .*" \
168 "reset tfinding"
169
170 if { $fourgood } {
171
172 gdb_test "tfind pc *four_byter" "Found trace frame .*" \
173 "tfind four_byter frame, first time"
174
175 gdb_test "print anarg" " = 101" \
176 "look at collected local, first time"
177
178 gdb_test "tfind pc *four_byter" "Found trace frame .*" \
179 "tfind four_byter frame, second time"
180
181 gdb_test "print anarg" " = 201" \
182 "look at collected local, second time"
183
184 }
185
186 # If debugging with the remote target, try force disabling the
187 # fast tracepoints RSP feature, and confirm fast tracepoints
188 # can no longer be downloaded.
189 set test "fast tracepoint could not be downloaded with the feature disabled"
190 if [gdb_is_target_remote] {
191 gdb_test "set remote fast-tracepoints-packet off"
192
193 gdb_test_multiple "tstart" $test {
194 -re "warning: Target does not support fast tracepoints, downloading .* as regular tracepoint.*\r\n$gdb_prompt $" {
195 pass $test
196 }
197 }
198 } else {
199 unsupported $test
200 }
201 }
202
203 gdb_reinitialize_dir $srcdir/$subdir
204
205 if { [gdb_test "info sharedlibrary" ".*${remote_libipa}.*" "IPA loaded"] != 0 } {
206 untested "could not find IPA lib loaded"
207 return 1
208 }
209
210 test_fast_tracepoints