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 [prepare_for_testing $expfile $executable $srcfile \
25 [list debug $additional_flags]] {
26 untested "failed to prepare for trace tests"
31 fail "Can't run to main to check for trace support"
35 if ![gdb_target_supports_trace] {
36 unsupported "target does not support trace"
40 set libipa [get_in_proc_agent]
41 gdb_load_shlibs $libipa
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.
47 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
48 executable [list debug $additional_flags shlib=$libipa] ] != "" } {
49 untested "failed to compile ftrace tests"
53 clean_restart ${executable}
56 fail "Can't run to main for ftrace tests"
60 if { [gdb_test "info sharedlibrary" ".*${libipa}.*" "IPA loaded"] != 0 } {
61 untested "Could not find IPA lib loaded"
65 proc test_tracepoints { trace_command condition num_frames { kfail_proc 0 } } {
66 global executable gdb_prompt
68 clean_restart ${executable}
71 fail "Can't run to main for ftrace tests"
75 gdb_test "break begin" ".*" ""
77 gdb_test "break end" ".*" ""
79 with_test_prefix "${trace_command}: ${condition}" {
81 gdb_test "${trace_command} set_point if ${condition}" \
82 "\(Fast t|T\)racepoint .*" \
85 gdb_test "continue" ".*Breakpoint \[0-9\]+, begin .*" \
86 "advance to trace begin"
88 gdb_test_no_output "tstart" "start trace experiment"
90 gdb_test_multiple "continue" "advance through tracing" {
91 -re ".*Breakpoint \[0-9\]+, end .*$gdb_prompt $" {
92 pass "advance through tracing"
94 -re "Program received signal SIGSEGV, Segmentation fault\\..*$gdb_prompt $" {
95 if { $kfail_proc != 0 } {
96 $kfail_proc $trace_command
98 fail "advance through tracing"
102 if { $kfail_proc != 0 } {
103 $kfail_proc $trace_command
106 ".*Trace .*Collected $num_frames .*" \
107 "check $num_frames frames were collected."
109 gdb_test "tstop" "" ""
113 # These callbacks identify known failures for certain architectures. They
114 # are called either if GDBserver crashes or has not traced the correct
117 proc 18955_x86_64_failure { trace_command } {
118 if { $trace_command == "ftrace" } {
119 setup_kfail "gdb/18955" "x86_64-*-linux*"
123 proc 18955_i386_failure { trace_command } {
124 if { $trace_command == "ftrace" } {
125 setup_kfail "gdb/18955" "i\[34567\]86-*-*"
129 foreach trace_command { "trace" "ftrace" } {
130 # This condition is always true as the PC should be set to the tracepoint
132 test_tracepoints $trace_command "\$$pcreg == *set_point" 10
134 # Can we read local variables?
135 test_tracepoints $trace_command "anarg == 100 || anarg == 200" 2 18955_x86_64_failure
136 # Can we read global variables?
137 test_tracepoints $trace_command "anarg == 100 && globvar == 1" 1 18955_x86_64_failure
139 # Test various operations to cover as many opcodes as possible.
140 test_tracepoints $trace_command "21 + 21 == 42" 10
141 test_tracepoints $trace_command "21 - 21 == 0" 10
142 test_tracepoints $trace_command "21 * 2 == 42" 10
143 test_tracepoints $trace_command "21 << 1 == 42" 10
144 test_tracepoints $trace_command "42 >> 1 == 21" 10
145 test_tracepoints $trace_command "-21 << 1 == -42" 10
146 test_tracepoints $trace_command "-42 >> 1 == -21" 10
147 test_tracepoints $trace_command "(0xabababab & 0x0000ffff) == 0xabab" 10
148 test_tracepoints $trace_command "(0xabababab | 0x0000ffff) == 0xababffff" 10
149 test_tracepoints $trace_command "(0xaaaaaaaa ^ 0x55555555) == 0xffffffff" 10
150 test_tracepoints $trace_command "~0xaaaaaaaa == 0x55555555" 10
151 test_tracepoints $trace_command "21 < 42" 10
152 test_tracepoints $trace_command "42 <= 42" 10
153 test_tracepoints $trace_command "42 >= 42" 10
154 test_tracepoints $trace_command "42 > 21" 10
155 test_tracepoints $trace_command "(21 < 42 ? 0 : 1) == 0" 10 18955_i386_failure
156 test_tracepoints $trace_command "(42 <= 42 ? 0 : 1) == 0" 10
157 test_tracepoints $trace_command "(42 >= 42 ? 0 : 1) == 0" 10
158 test_tracepoints $trace_command "(42 > 21 ? 0 : 1) == 0" 10 18955_i386_failure
159 test_tracepoints $trace_command "\$trace_timestamp >= 0" 10