1 # Copyright 2011-2015 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"
18 set executable $testfile
19 set expfile $testfile.exp
21 # Some targets have leading underscores on assembly symbols.
22 set additional_flags [gdb_target_symbol_prefix_flags]
24 if [is_amd64_regs_target] {
26 } elseif [is_x86_like_target] {
32 if [prepare_for_testing $expfile $executable $srcfile \
33 [list debug $additional_flags]] {
34 untested "failed to prepare for trace tests"
39 fail "Can't run to main to check for trace support"
43 if ![gdb_target_supports_trace] {
44 unsupported "target does not support trace"
48 set libipa [get_in_proc_agent]
49 gdb_load_shlibs $libipa
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.
55 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
56 executable [list debug $additional_flags shlib=$libipa] ] != "" } {
57 untested "failed to compile ftrace tests"
61 clean_restart ${executable}
64 fail "Can't run to main for ftrace tests"
68 if { [gdb_test "info sharedlibrary" ".*${libipa}.*" "IPA loaded"] != 0 } {
69 untested "Could not find IPA lib loaded"
73 proc test_tracepoints { trace_command condition num_frames { kfail_proc 0 } } {
74 global executable gdb_prompt
76 clean_restart ${executable}
79 fail "Can't run to main for ftrace tests"
83 gdb_test "break begin" ".*" ""
85 gdb_test "break end" ".*" ""
87 with_test_prefix "${trace_command}: ${condition}" {
89 gdb_test "${trace_command} set_point if ${condition}" \
90 "\(Fast t|T\)racepoint .*" \
93 gdb_test "continue" ".*Breakpoint \[0-9\]+, begin .*" \
94 "advance to trace begin"
96 gdb_test_no_output "tstart" "start trace experiment"
98 gdb_test_multiple "continue" "advance through tracing" {
99 -re ".*Breakpoint \[0-9\]+, end .*$gdb_prompt $" {
100 pass "advance through tracing"
102 -re "Program received signal SIGSEGV, Segmentation fault\\..*$gdb_prompt $" {
103 if { $kfail_proc != 0 } {
104 $kfail_proc $trace_command
106 fail "advance through tracing"
110 if { $kfail_proc != 0 } {
111 $kfail_proc $trace_command
114 ".*Trace .*Collected $num_frames .*" \
115 "check $num_frames frames were collected."
117 gdb_test "tstop" "" ""
121 # These callbacks identify known failures for certain architectures. They
122 # are called either if GDBserver crashes or has not traced the correct
125 proc 18955_x86_64_failure { trace_command } {
126 if { $trace_command == "ftrace" } {
127 setup_kfail "gdb/18955" "x86_64-*-linux*"
131 proc 18955_i386_failure { trace_command } {
132 if { $trace_command == "ftrace" } {
133 setup_kfail "gdb/18955" "i\[34567\]86-*-*"
137 foreach trace_command { "trace" "ftrace" } {
138 # This condition is always true as the PC should be set to the tracepoint
140 test_tracepoints $trace_command "$pcreg == *set_point" 10
142 # Can we read local variables?
143 test_tracepoints $trace_command "anarg == 100 || anarg == 200" 2 18955_x86_64_failure
144 # Can we read global variables?
145 test_tracepoints $trace_command "anarg == 100 && globvar == 1" 1 18955_x86_64_failure
147 # Test various operations to cover as many opcodes as possible.
148 test_tracepoints $trace_command "21 + 21 == 42" 10
149 test_tracepoints $trace_command "21 - 21 == 0" 10
150 test_tracepoints $trace_command "21 * 2 == 42" 10
151 test_tracepoints $trace_command "21 << 1 == 42" 10
152 test_tracepoints $trace_command "42 >> 1 == 21" 10
153 test_tracepoints $trace_command "-21 << 1 == -42" 10
154 test_tracepoints $trace_command "-42 >> 1 == -21" 10
155 test_tracepoints $trace_command "(0xabababab & 0x0000ffff) == 0xabab" 10
156 test_tracepoints $trace_command "(0xabababab | 0x0000ffff) == 0xababffff" 10
157 test_tracepoints $trace_command "(0xaaaaaaaa ^ 0x55555555) == 0xffffffff" 10
158 test_tracepoints $trace_command "~0xaaaaaaaa == 0x55555555" 10
159 test_tracepoints $trace_command "21 < 42" 10
160 test_tracepoints $trace_command "42 <= 42" 10
161 test_tracepoints $trace_command "42 >= 42" 10
162 test_tracepoints $trace_command "42 > 21" 10
163 test_tracepoints $trace_command "(21 < 42 ? 0 : 1) == 0" 10 18955_i386_failure
164 test_tracepoints $trace_command "(42 <= 42 ? 0 : 1) == 0" 10
165 test_tracepoints $trace_command "(42 >= 42 ? 0 : 1) == 0" 10
166 test_tracepoints $trace_command "(42 > 21 ? 0 : 1) == 0" 10 18955_i386_failure
167 test_tracepoints $trace_command "\$trace_timestamp >= 0" 10