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