1 # Copyright 2011-2013 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"
52 clean_restart ${executable}
55 fail "Can't run to main for ftrace tests"
59 proc run_trace_experiment {} {
62 ".*Breakpoint \[0-9\]+, begin .*" \
63 "advance to trace begin"
65 gdb_test_no_output "tstart" "start trace experiment"
68 ".*Breakpoint \[0-9\]+, end .*" \
69 "advance through tracing"
71 gdb_test "tstatus" ".*Trace .*" "check on trace status"
73 gdb_test "tstop" "" ""
76 proc test_fast_tracepoints {} {
81 gdb_test "break begin" ".*" ""
83 gdb_test "break end" ".*" ""
85 gdb_test "print gdb_agent_gdb_trampoline_buffer_error" ".*" ""
87 if { [istarget "x86_64-*-*"] || [istarget "i\[34567\]86-*-*"] } {
89 gdb_test "ftrace set_point" "Fast tracepoint .*" \
90 "fast tracepoint at a long insn"
92 gdb_trace_setactions "collect at set_point: define actions" \
94 "collect globvar, anarg" "^$"
96 # Make a test of shorter fast tracepoints, 32-bit x86 only
98 if { [istarget "i?86-*-*"] } {
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*"] } {
104 set minaddr [exec sh -c "cat /proc/sys/vm/mmap_min_addr"]
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"
112 gdb_test_multiple "ftrace four_byter" "set 4-byte fast tracepoint" {
113 -re "May not have a fast tracepoint at .*\r\n$gdb_prompt $" {
114 pass "4-byte fast tracepoint could not be set"
116 -re "Fast tracepoint .*\r\n$gdb_prompt $" {
117 pass "4-byte fast tracepoint is set"
124 gdb_trace_setactions "collect at four_byter: define actions" \
126 "collect globvar, anarg" "^$"
132 gdb_test "tfind pc *set_point" "Found trace frame .*" \
133 "tfind set_point frame, first time"
135 setup_kfail "gdb/13808" "x86_64-*-linux*"
136 gdb_test "print globvar" " = 1"
138 gdb_test "tfind pc *set_point" "Found trace frame .*" \
139 "tfind set_point frame, second time"
141 setup_kfail "gdb/13808" "x86_64-*-linux*"
142 gdb_test "print anarg" " = 200"
144 gdb_test "tfind start" "Found trace frame .*" \
149 gdb_test "tfind pc *four_byter" "Found trace frame .*" \
150 "tfind four_byter frame, first time"
152 gdb_test "print anarg" " = 101" \
153 "look at collected local, first time"
155 gdb_test "tfind pc *four_byter" "Found trace frame .*" \
156 "tfind four_byter frame, second time"
158 gdb_test "print anarg" " = 201" \
159 "look at collected local, second time"
165 gdb_reinitialize_dir $srcdir/$subdir
167 if { [gdb_test "info sharedlibrary" ".*${libipa}.*" "IPA loaded"] != 0 } {
168 untested "Could not find IPA lib loaded"
172 test_fast_tracepoints