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