Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright 2011-2016 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 | |
497a5eb0 | 17 | standard_testfile |
405f8e94 | 18 | set executable $testfile |
405f8e94 SS |
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 $expfile $executable $srcfile \ | |
25 | [list debug $additional_flags]] { | |
26 | untested "failed to prepare for trace tests" | |
27 | return -1 | |
28 | } | |
29 | ||
30 | if ![runto_main] { | |
31 | fail "Can't run to main to check for trace support" | |
32 | return -1 | |
33 | } | |
34 | ||
35 | if ![gdb_target_supports_trace] { | |
36 | unsupported "target does not support trace" | |
37 | return -1 | |
38 | } | |
39 | ||
c0d4d1c0 | 40 | set libipa [get_in_proc_agent] |
405f8e94 SS |
41 | gdb_load_shlibs $libipa |
42 | ||
43 | # Can't use prepare_for_testing, because that splits compiling into | |
44 | # building objects and then linking, and we'd fail with "linker input | |
45 | # file unused because linking not done" when building the object. | |
46 | ||
47 | if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \ | |
48 | executable [list debug $additional_flags shlib=$libipa] ] != "" } { | |
49 | untested "failed to compile ftrace tests" | |
50 | return -1 | |
51 | } | |
52 | clean_restart ${executable} | |
53 | ||
54 | if ![runto_main] { | |
55 | fail "Can't run to main for ftrace tests" | |
56 | return 0 | |
57 | } | |
58 | ||
59 | proc run_trace_experiment {} { | |
60 | ||
61 | gdb_test "continue" \ | |
62 | ".*Breakpoint \[0-9\]+, begin .*" \ | |
63 | "advance to trace begin" | |
64 | ||
65 | gdb_test_no_output "tstart" "start trace experiment" | |
66 | ||
67 | gdb_test "continue" \ | |
68 | ".*Breakpoint \[0-9\]+, end .*" \ | |
69 | "advance through tracing" | |
70 | ||
71 | gdb_test "tstatus" ".*Trace .*" "check on trace status" | |
72 | ||
73 | gdb_test "tstop" "" "" | |
74 | } | |
75 | ||
76 | proc test_fast_tracepoints {} { | |
61638e15 | 77 | global gdb_prompt |
405f8e94 SS |
78 | |
79 | set fourgood 0 | |
80 | ||
81 | gdb_test "break begin" ".*" "" | |
82 | ||
83 | gdb_test "break end" ".*" "" | |
84 | ||
85 | gdb_test "print gdb_agent_gdb_trampoline_buffer_error" ".*" "" | |
86 | ||
7041adf4 | 87 | if { [istarget "x86_64-*-*"] || [istarget "i\[34567\]86-*-*"] || [is_aarch64_target] } { |
405f8e94 SS |
88 | |
89 | gdb_test "ftrace set_point" "Fast tracepoint .*" \ | |
90 | "fast tracepoint at a long insn" | |
91 | ||
92 | gdb_trace_setactions "collect at set_point: define actions" \ | |
93 | "" \ | |
94 | "collect globvar, anarg" "^$" | |
95 | ||
96 | # Make a test of shorter fast tracepoints, 32-bit x86 only | |
97 | ||
98 | if { [istarget "i?86-*-*"] } { | |
99 | ||
100 | # A Linux target needs to be able to allocate trampolines in the | |
101 | # 16-bit range, check mmap_min_addr so we can warn testers. | |
102 | if { [istarget "i?86-*-linux*"] } { | |
103 | ||
104 | set minaddr [exec sh -c "cat /proc/sys/vm/mmap_min_addr"] | |
105 | ||
106 | if { [expr $minaddr > 64512] } { | |
107 | warning "mmap_min_addr > 64512, fast tracepoint will fail" | |
108 | warning "do \"sudo sysctl -w vm.mmap_min_addr=32768\" to adjust" | |
109 | } | |
110 | } | |
111 | ||
112 | gdb_test_multiple "ftrace four_byter" "set 4-byte fast tracepoint" { | |
61638e15 | 113 | -re "May not have a fast tracepoint at .*\r\n$gdb_prompt $" { |
405f8e94 SS |
114 | pass "4-byte fast tracepoint could not be set" |
115 | } | |
61638e15 | 116 | -re "Fast tracepoint .*\r\n$gdb_prompt $" { |
405f8e94 SS |
117 | pass "4-byte fast tracepoint is set" |
118 | set fourgood 1 | |
119 | } | |
120 | } | |
121 | ||
122 | if { $fourgood } { | |
123 | ||
124 | gdb_trace_setactions "collect at four_byter: define actions" \ | |
125 | "" \ | |
126 | "collect globvar, anarg" "^$" | |
127 | } | |
128 | } | |
129 | ||
130 | run_trace_experiment | |
131 | ||
132 | gdb_test "tfind pc *set_point" "Found trace frame .*" \ | |
133 | "tfind set_point frame, first time" | |
134 | ||
bb662ca6 | 135 | setup_kfail "gdb/13808" "x86_64-*-linux*" |
405f8e94 SS |
136 | gdb_test "print globvar" " = 1" |
137 | ||
138 | gdb_test "tfind pc *set_point" "Found trace frame .*" \ | |
139 | "tfind set_point frame, second time" | |
140 | ||
bb662ca6 | 141 | setup_kfail "gdb/13808" "x86_64-*-linux*" |
405f8e94 SS |
142 | gdb_test "print anarg" " = 200" |
143 | ||
144 | gdb_test "tfind start" "Found trace frame .*" \ | |
145 | "reset tfinding" | |
146 | ||
147 | if { $fourgood } { | |
148 | ||
149 | gdb_test "tfind pc *four_byter" "Found trace frame .*" \ | |
150 | "tfind four_byter frame, first time" | |
151 | ||
152 | gdb_test "print anarg" " = 101" \ | |
153 | "look at collected local, first time" | |
154 | ||
155 | gdb_test "tfind pc *four_byter" "Found trace frame .*" \ | |
156 | "tfind four_byter frame, second time" | |
157 | ||
158 | gdb_test "print anarg" " = 201" \ | |
159 | "look at collected local, second time" | |
160 | ||
161 | } | |
4082afcc PA |
162 | |
163 | # If debugging with the remote target, try force disabling the | |
164 | # fast tracepoints RSP feature, and confirm fast tracepoints | |
165 | # can no longer be downloaded. | |
166 | set test "fast tracepoint could not be downloaded with the feature disabled" | |
167 | if [gdb_is_target_remote] { | |
168 | gdb_test "set remote fast-tracepoints-packet off" | |
169 | ||
170 | gdb_test_multiple "tstart" $test { | |
171 | -re "warning: Target does not support fast tracepoints, downloading .* as regular tracepoint.*\r\n$gdb_prompt $" { | |
172 | pass $test | |
173 | } | |
174 | } | |
175 | } else { | |
176 | unsupported $test | |
177 | } | |
405f8e94 SS |
178 | } |
179 | } | |
180 | ||
d78908cf WW |
181 | # Test compiled-condition |
182 | # CONDEXP is the condition expression to be compiled. | |
183 | # VAR is the variable to be collected for testing. | |
184 | # LIST is a list of expected values of VAR should be collected | |
185 | # based on the CONDEXP. | |
186 | proc test_ftrace_condition { condexp var list } \ | |
187 | { with_test_prefix "ond $condexp" \ | |
188 | { | |
189 | global executable | |
190 | global hex | |
191 | ||
192 | clean_restart ${executable} | |
193 | if ![runto_main] { | |
194 | fail "Can't run to main to check for trace support" | |
195 | return -1 | |
196 | } | |
197 | ||
198 | gdb_test "break end" ".*" "" | |
199 | gdb_test "tvariable \$tsv = 0" | |
200 | gdb_test "ftrace set_point if $condexp" "Fast tracepoint .*" | |
201 | gdb_trace_setactions "set action for tracepoint .*" "" \ | |
202 | "collect $var" "^$" | |
203 | ||
204 | gdb_test_no_output "tstart" "" | |
205 | gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "" | |
206 | gdb_test_no_output "tstop" "" | |
207 | ||
208 | set i 0 | |
209 | foreach expval $list { | |
210 | gdb_test "tfind" "Found trace frame $i, tracepoint .*" "tfind frame $i" | |
211 | gdb_test "print $var" "\\$\[0-9\]+ = $expval\[\r\n\]" "expect $expval" | |
212 | set i [expr $i + 1] | |
213 | } | |
214 | gdb_test "tfind" "Target failed to find requested trace frame\." | |
215 | }} | |
216 | ||
405f8e94 SS |
217 | gdb_reinitialize_dir $srcdir/$subdir |
218 | ||
c0d4d1c0 | 219 | if { [gdb_test "info sharedlibrary" ".*${libipa}.*" "IPA loaded"] != 0 } { |
405f8e94 SS |
220 | untested "Could not find IPA lib loaded" |
221 | return 1 | |
222 | } | |
223 | ||
224 | test_fast_tracepoints | |
d78908cf WW |
225 | |
226 | # Test conditional goto and simple expression. | |
227 | test_ftrace_condition "globvar > 7" "globvar" { 8 9 10 } | |
228 | test_ftrace_condition "globvar < 4" "globvar" { 1 2 3 } | |
229 | test_ftrace_condition "globvar >= 7" "globvar" { 7 8 9 10 } | |
230 | test_ftrace_condition "globvar <= 4" "globvar" { 1 2 3 4 } | |
231 | test_ftrace_condition "globvar == 5" "globvar" { 5 } | |
232 | test_ftrace_condition "globvar != 5" "globvar" { 1 2 3 4 6 7 8 9 10 } | |
233 | test_ftrace_condition "globvar > 3 && globvar < 7" "globvar" { 4 5 6 } | |
234 | test_ftrace_condition "globvar < 3 || globvar > 7" "globvar" { 1 2 8 9 10 } | |
235 | test_ftrace_condition "(globvar << 2) + 1 == 29" "globvar" { 7 } | |
236 | test_ftrace_condition "(globvar >> 2) == 2" "globvar" { 8 9 10 } | |
237 | ||
238 | # Test emit_call by accessing trace state variables. | |
239 | test_ftrace_condition "(\$tsv = \$tsv + 2) > 10" "globvar" { 6 7 8 9 10 } | |
240 | ||
241 | # This expression is used for testing emit_reg. | |
242 | if [is_amd64_regs_target] { | |
243 | set arg0exp "\$rdi" | |
244 | } elseif [is_x86_like_target] { | |
245 | set arg0exp "*(int *) (\$ebp + 8)" | |
a22279dd YQ |
246 | } elseif { [istarget "aarch64*-*-*"] } { |
247 | set arg0exp "\$x0" | |
d78908cf WW |
248 | } else { |
249 | set arg0exp "" | |
250 | } | |
251 | ||
252 | if { "$arg0exp" != "" } { | |
253 | test_ftrace_condition "($arg0exp > 500)" "globvar" { 6 7 8 9 10 } | |
254 | } |