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