Enable fast tracepoint tests
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / trace-condition.exp
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.
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 standard_testfile
18 set executable $testfile
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 [is_amd64_regs_target] {
25 set pcreg "\$rip"
26 } elseif [is_x86_like_target] {
27 set pcreg "\$eip"
28 } elseif [is_aarch64_target] {
29 set pcreg "\$pc"
30 } else {
31 set pcreg "\$pc"
32 }
33
34 if [prepare_for_testing $expfile $executable $srcfile \
35 [list debug $additional_flags]] {
36 untested "failed to prepare for trace tests"
37 return -1
38 }
39
40 if ![runto_main] {
41 fail "Can't run to main to check for trace support"
42 return -1
43 }
44
45 if ![gdb_target_supports_trace] {
46 unsupported "target does not support trace"
47 return -1
48 }
49
50 set libipa [get_in_proc_agent]
51 gdb_load_shlibs $libipa
52
53 # Can't use prepare_for_testing, because that splits compiling into
54 # building objects and then linking, and we'd fail with "linker input
55 # file unused because linking not done" when building the object.
56
57 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
58 executable [list debug $additional_flags shlib=$libipa] ] != "" } {
59 untested "failed to compile ftrace tests"
60 return -1
61 }
62
63 clean_restart ${executable}
64
65 if ![runto_main] {
66 fail "Can't run to main for ftrace tests"
67 return 0
68 }
69
70 if { [gdb_test "info sharedlibrary" ".*${libipa}.*" "IPA loaded"] != 0 } {
71 untested "Could not find IPA lib loaded"
72 return 1
73 }
74
75 proc test_tracepoints { trace_command condition num_frames { kfail_proc 0 } } {
76 global executable gdb_prompt
77
78 clean_restart ${executable}
79
80 if ![runto_main] {
81 fail "Can't run to main for ftrace tests"
82 return 0
83 }
84
85 gdb_test "break begin" ".*" ""
86
87 gdb_test "break end" ".*" ""
88
89 with_test_prefix "${trace_command}: ${condition}" {
90
91 gdb_test "${trace_command} set_point if ${condition}" \
92 "\(Fast t|T\)racepoint .*" \
93 "set tracepoint"
94
95 gdb_test "continue" ".*Breakpoint \[0-9\]+, begin .*" \
96 "advance to trace begin"
97
98 gdb_test_no_output "tstart" "start trace experiment"
99
100 gdb_test_multiple "continue" "advance through tracing" {
101 -re ".*Breakpoint \[0-9\]+, end .*$gdb_prompt $" {
102 pass "advance through tracing"
103 }
104 -re "Program received signal SIGSEGV, Segmentation fault\\..*$gdb_prompt $" {
105 if { $kfail_proc != 0 } {
106 $kfail_proc $trace_command
107 }
108 fail "advance through tracing"
109 }
110 }
111
112 if { $kfail_proc != 0 } {
113 $kfail_proc $trace_command
114 }
115 gdb_test "tstatus" \
116 ".*Trace .*Collected $num_frames .*" \
117 "check $num_frames frames were collected."
118
119 gdb_test "tstop" "" ""
120 }
121 }
122
123 # These callbacks identify known failures for certain architectures. They
124 # are called either if GDBserver crashes or has not traced the correct
125 # number of frames.
126
127 proc 18955_x86_64_failure { trace_command } {
128 if { $trace_command == "ftrace" } {
129 setup_kfail "gdb/18955" "x86_64-*-linux*"
130 }
131 }
132
133 proc 18955_i386_failure { trace_command } {
134 if { $trace_command == "ftrace" } {
135 setup_kfail "gdb/18955" "i\[34567\]86-*-*"
136 }
137 }
138
139 foreach trace_command { "trace" "ftrace" } {
140 # This condition is always true as the PC should be set to the tracepoint
141 # address when hit.
142 test_tracepoints $trace_command "$pcreg == *set_point" 10
143
144 # Can we read local variables?
145 test_tracepoints $trace_command "anarg == 100 || anarg == 200" 2 18955_x86_64_failure
146 # Can we read global variables?
147 test_tracepoints $trace_command "anarg == 100 && globvar == 1" 1 18955_x86_64_failure
148
149 # Test various operations to cover as many opcodes as possible.
150 test_tracepoints $trace_command "21 + 21 == 42" 10
151 test_tracepoints $trace_command "21 - 21 == 0" 10
152 test_tracepoints $trace_command "21 * 2 == 42" 10
153 test_tracepoints $trace_command "21 << 1 == 42" 10
154 test_tracepoints $trace_command "42 >> 1 == 21" 10
155 test_tracepoints $trace_command "-21 << 1 == -42" 10
156 test_tracepoints $trace_command "-42 >> 1 == -21" 10
157 test_tracepoints $trace_command "(0xabababab & 0x0000ffff) == 0xabab" 10
158 test_tracepoints $trace_command "(0xabababab | 0x0000ffff) == 0xababffff" 10
159 test_tracepoints $trace_command "(0xaaaaaaaa ^ 0x55555555) == 0xffffffff" 10
160 test_tracepoints $trace_command "~0xaaaaaaaa == 0x55555555" 10
161 test_tracepoints $trace_command "21 < 42" 10
162 test_tracepoints $trace_command "42 <= 42" 10
163 test_tracepoints $trace_command "42 >= 42" 10
164 test_tracepoints $trace_command "42 > 21" 10
165 test_tracepoints $trace_command "(21 < 42 ? 0 : 1) == 0" 10 18955_i386_failure
166 test_tracepoints $trace_command "(42 <= 42 ? 0 : 1) == 0" 10
167 test_tracepoints $trace_command "(42 >= 42 ? 0 : 1) == 0" 10
168 test_tracepoints $trace_command "(42 > 21 ? 0 : 1) == 0" 10 18955_i386_failure
169 test_tracepoints $trace_command "\$trace_timestamp >= 0" 10
170 }
This page took 0.050733 seconds and 5 git commands to generate.