1 # Copyright 2011-2024 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.
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.
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/>.
15 load_lib "trace-support.exp"
17 require allow_shlib_tests
20 set executable $testfile
21 set expfile $testfile.exp
23 # Some targets have leading underscores on assembly symbols.
24 set additional_flags [gdb_target_symbol_prefix_flags]
26 require gdb_trace_common_supports_arch
28 if [prepare_for_testing "failed to prepare" $executable $srcfile \
29 [list debug $additional_flags]] {
37 if ![gdb_target_supports_trace] {
38 unsupported "target does not support trace"
42 require allow_in_proc_agent
43 set libipa [get_in_proc_agent]
44 set remote_libipa [gdb_load_shlib $libipa]
46 # Can't use prepare_for_testing, because that splits compiling into
47 # building objects and then linking, and we'd fail with "linker input
48 # file unused because linking not done" when building the object.
50 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
51 executable [list debug nopie $additional_flags shlib=$libipa] ] != "" } {
52 untested "failed to compile"
55 clean_restart ${executable}
61 proc run_trace_experiment {} {
64 ".*Breakpoint \[0-9\]+, begin .*" \
65 "advance to trace begin"
67 gdb_test_no_output "tstart" "start trace experiment"
69 # Fast tracepoint can be set in signal handler, so gdb_collect in
70 # IPA shouldn't call any non-async-signal-safe functions. It is
71 # impractical to list all non-async-signal-safe functions, and set
72 # breakpoints on them, so choose malloc only in this test.
73 gdb_test "b -q malloc"
75 # Performance-wise, gdb_collect in IPA shouldn't call any syscall
76 # in order to keep fast tracepoint fast enough.
78 set test "catch syscall"
79 gdb_test_multiple $test $test {
80 -re "The feature \'catch syscall\' is not supported.*\r\n$gdb_prompt $" {
82 -re ".*$gdb_prompt $" {
88 set test "advance through tracing"
89 gdb_test_multiple "continue" $test {
90 -re "Thread 2 .* hit Catchpoint $decimal \\(call to syscall .*\\).*\r\n$gdb_prompt $" {
91 # IPA starts a helper thread, which calls accept. Ignore it.
95 -re "Breakpoint $decimal, end .*$gdb_prompt $" {
100 gdb_test "tstatus" ".*Trace .*" "check on trace status"
102 gdb_test "tstop" "" ""
105 proc test_fast_tracepoints {} {
110 gdb_breakpoint "begin" qualified
112 gdb_breakpoint "end" qualified
114 gdb_test "print gdb_agent_gdb_trampoline_buffer_error" ".*" ""
116 gdb_test "ftrace set_point" "Fast tracepoint .*" \
117 "fast tracepoint at a long insn"
119 gdb_trace_setactions "collect at set_point: define actions" \
121 "collect globvar, anarg" "^$"
123 # Make a test of shorter fast tracepoints, 32-bit x86 only
125 if { [istarget "i?86-*-*"] } {
127 # A Linux target needs to be able to allocate trampolines in the
128 # 16-bit range, check mmap_min_addr so we can warn testers.
129 if { [istarget "i?86-*-linux*"] } {
131 set minaddr [exec sh -c "cat /proc/sys/vm/mmap_min_addr"]
133 if { [expr $minaddr > 64512] } {
134 warning "mmap_min_addr > 64512, fast tracepoint will fail"
135 warning "do \"sudo sysctl -w vm.mmap_min_addr=32768\" to adjust"
139 gdb_test_multiple "ftrace four_byter" "set 4-byte fast tracepoint" {
140 -re "May not have a fast tracepoint at .*\r\n$gdb_prompt $" {
141 pass "4-byte fast tracepoint could not be set"
143 -re "Fast tracepoint .*\r\n$gdb_prompt $" {
144 pass "4-byte fast tracepoint is set"
151 gdb_trace_setactions "collect at four_byter: define actions" \
153 "collect globvar, anarg" "^$"
159 gdb_test "tfind pc *set_point" "Found trace frame .*" \
160 "tfind set_point frame, first time"
162 gdb_test "print globvar" " = 1"
164 gdb_test "tfind pc *set_point" "Found trace frame .*" \
165 "tfind set_point frame, second time"
167 setup_kfail "gdb/13808" "x86_64-*-linux*"
168 gdb_test "print anarg" " = 200"
170 gdb_test "tfind start" "Found trace frame .*" \
175 gdb_test "tfind pc *four_byter" "Found trace frame .*" \
176 "tfind four_byter frame, first time"
178 gdb_test "print anarg" " = 101" \
179 "look at collected local, first time"
181 gdb_test "tfind pc *four_byter" "Found trace frame .*" \
182 "tfind four_byter frame, second time"
184 gdb_test "print anarg" " = 201" \
185 "look at collected local, second time"
189 # If debugging with the remote target, try force disabling the
190 # fast tracepoints RSP feature, and confirm fast tracepoints
191 # can no longer be downloaded.
192 set test "fast tracepoint could not be downloaded with the feature disabled"
193 if [gdb_protocol_is_remote] {
194 gdb_test "set remote fast-tracepoints-packet off"
196 gdb_test_multiple "tstart" $test {
197 -re "warning: Target does not support fast tracepoints, downloading .* as regular tracepoint.*\r\n$gdb_prompt $" {
206 gdb_reinitialize_dir $srcdir/$subdir
208 if { [gdb_test "info sharedlibrary" ".*${remote_libipa}.*" "IPA loaded"] != 0 } {
209 untested "could not find IPA lib loaded"
213 test_fast_tracepoints