Commit | Line | Data |
---|---|---|
405f8e94 SS |
1 | # Copyright 2011 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 | set testfile "ftrace" | |
18 | set executable $testfile | |
19 | set srcfile $testfile.c | |
20 | set binfile $objdir/$subdir/$testfile | |
21 | set expfile $testfile.exp | |
22 | ||
23 | # Some targets have leading underscores on assembly symbols. | |
24 | set additional_flags [gdb_target_symbol_prefix_flags] | |
25 | ||
26 | if [prepare_for_testing $expfile $executable $srcfile \ | |
27 | [list debug $additional_flags]] { | |
28 | untested "failed to prepare for trace tests" | |
29 | return -1 | |
30 | } | |
31 | ||
32 | if ![runto_main] { | |
33 | fail "Can't run to main to check for trace support" | |
34 | return -1 | |
35 | } | |
36 | ||
37 | if ![gdb_target_supports_trace] { | |
38 | unsupported "target does not support trace" | |
39 | return -1 | |
40 | } | |
41 | ||
42 | set libipa $objdir/../gdbserver/libinproctrace.so | |
43 | gdb_load_shlibs $libipa | |
44 | ||
45 | # Can't use prepare_for_testing, because that splits compiling into | |
46 | # building objects and then linking, and we'd fail with "linker input | |
47 | # file unused because linking not done" when building the object. | |
48 | ||
49 | if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \ | |
50 | executable [list debug $additional_flags shlib=$libipa] ] != "" } { | |
51 | untested "failed to compile ftrace tests" | |
52 | return -1 | |
53 | } | |
54 | clean_restart ${executable} | |
55 | ||
56 | if ![runto_main] { | |
57 | fail "Can't run to main for ftrace tests" | |
58 | return 0 | |
59 | } | |
60 | ||
61 | proc run_trace_experiment {} { | |
62 | ||
63 | gdb_test "continue" \ | |
64 | ".*Breakpoint \[0-9\]+, begin .*" \ | |
65 | "advance to trace begin" | |
66 | ||
67 | gdb_test_no_output "tstart" "start trace experiment" | |
68 | ||
69 | gdb_test "continue" \ | |
70 | ".*Breakpoint \[0-9\]+, end .*" \ | |
71 | "advance through tracing" | |
72 | ||
73 | gdb_test "tstatus" ".*Trace .*" "check on trace status" | |
74 | ||
75 | gdb_test "tstop" "" "" | |
76 | } | |
77 | ||
78 | proc test_fast_tracepoints {} { | |
79 | ||
80 | set fourgood 0 | |
81 | ||
82 | gdb_test "break begin" ".*" "" | |
83 | ||
84 | gdb_test "break end" ".*" "" | |
85 | ||
86 | gdb_test "print gdb_agent_gdb_trampoline_buffer_error" ".*" "" | |
87 | ||
88 | if { [is_x86_like_target] } { | |
89 | ||
90 | gdb_test "ftrace set_point" "Fast tracepoint .*" \ | |
91 | "fast tracepoint at a long insn" | |
92 | ||
93 | gdb_trace_setactions "collect at set_point: define actions" \ | |
94 | "" \ | |
95 | "collect globvar, anarg" "^$" | |
96 | ||
97 | # Make a test of shorter fast tracepoints, 32-bit x86 only | |
98 | ||
99 | if { [istarget "i?86-*-*"] } { | |
100 | ||
101 | # A Linux target needs to be able to allocate trampolines in the | |
102 | # 16-bit range, check mmap_min_addr so we can warn testers. | |
103 | if { [istarget "i?86-*-linux*"] } { | |
104 | ||
105 | set minaddr [exec sh -c "cat /proc/sys/vm/mmap_min_addr"] | |
106 | ||
107 | if { [expr $minaddr > 64512] } { | |
108 | warning "mmap_min_addr > 64512, fast tracepoint will fail" | |
109 | warning "do \"sudo sysctl -w vm.mmap_min_addr=32768\" to adjust" | |
110 | } | |
111 | } | |
112 | ||
113 | gdb_test_multiple "ftrace four_byter" "set 4-byte fast tracepoint" { | |
114 | -re "May not have a fast tracepoint at .*" { | |
115 | pass "4-byte fast tracepoint could not be set" | |
116 | } | |
117 | -re "Fast tracepoint .*" { | |
118 | pass "4-byte fast tracepoint is set" | |
119 | set fourgood 1 | |
120 | } | |
121 | } | |
122 | ||
123 | if { $fourgood } { | |
124 | ||
125 | gdb_trace_setactions "collect at four_byter: define actions" \ | |
126 | "" \ | |
127 | "collect globvar, anarg" "^$" | |
128 | } | |
129 | } | |
130 | ||
131 | run_trace_experiment | |
132 | ||
133 | gdb_test "tfind pc *set_point" "Found trace frame .*" \ | |
134 | "tfind set_point frame, first time" | |
135 | ||
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 | ||
141 | gdb_test "print anarg" " = 200" | |
142 | ||
143 | gdb_test "tfind start" "Found trace frame .*" \ | |
144 | "reset tfinding" | |
145 | ||
146 | if { $fourgood } { | |
147 | ||
148 | gdb_test "tfind pc *four_byter" "Found trace frame .*" \ | |
149 | "tfind four_byter frame, first time" | |
150 | ||
151 | gdb_test "print anarg" " = 101" \ | |
152 | "look at collected local, first time" | |
153 | ||
154 | gdb_test "tfind pc *four_byter" "Found trace frame .*" \ | |
155 | "tfind four_byter frame, second time" | |
156 | ||
157 | gdb_test "print anarg" " = 201" \ | |
158 | "look at collected local, second time" | |
159 | ||
160 | } | |
161 | } | |
162 | } | |
163 | ||
164 | gdb_reinitialize_dir $srcdir/$subdir | |
165 | ||
166 | if { [gdb_test "info sharedlibrary" ".*libinproctrace\.so.*" "IPA loaded"] != 0 } { | |
167 | untested "Could not find IPA lib loaded" | |
168 | return 1 | |
169 | } | |
170 | ||
171 | test_fast_tracepoints |