gdb/doc/ChangeLog:
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / stap-probe.exp
1 # Copyright (C) 2012 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 set testfile stap-probe
17
18 # Run the tests. We run the tests two different ways: once with a
19 # plain probe, and once with a probe that has an associated semaphore.
20 # This returns -1 on failure to compile or start, 0 otherwise.
21 proc stap_test {exec_name {arg ""}} {
22 global testfile hex
23
24 if {[prepare_for_testing ${testfile}.exp ${exec_name} ${testfile}.c \
25 [concat $arg debug]]} {
26 return -1
27 }
28
29 if ![runto_main] {
30 return -1
31 }
32
33 gdb_test "print \$_probe_argc" "No SystemTap probe at PC $hex" \
34 "check argument not at probe point"
35
36 gdb_test "info probes stap" \
37 "test *user *$hex .*" \
38 "info probes stap"
39
40 if {[runto "-pstap test:user"]} {
41 pass "run to -pstap test:user"
42 } else {
43 fail "run to -pstap test:user"
44 }
45
46 # Test probe arguments.
47 gdb_test "print \$_probe_argc" " = 1" \
48 "print \$_probe_argc for probe user"
49 gdb_test "print \$_probe_arg0 == x" " = 1" \
50 "check \$_probe_arg0 for probe user"
51 gdb_test "print \$_probe_arg1" \
52 "Invalid probe argument 1 -- probe has 1 arguments available" \
53 "check \$_probe_arg1 for probe user"
54
55 # Set a breakpoint with multiple probe locations.
56 gdb_test "break -pstap test:two" \
57 "Breakpoint \[0-9\]+ at $hex.*2 locations.*" \
58 "set multi-location probe breakpoint (probe two)"
59
60 # Reinit GDB, set a breakpoint on probe m4.
61 delete_breakpoints
62 rerun_to_main
63 if {[runto "-pstap test:m4"]} {
64 pass "run to -pstap test:m4"
65 } else {
66 fail "run to -pstap test:m4"
67 }
68
69 # Testing probe arguments.
70 gdb_test "print \$_probe_argc" " = 3" \
71 "print \$_probe_argc for probe m4"
72 gdb_test "print \$_probe_arg0" " = 42" \
73 "check \$_probe_arg0 for probe m4"
74 gdb_test "print (const char *) \$_probe_arg1" \
75 " = $hex .This is a test message.*" \
76 "check \$_probe_arg1 for probe m4"
77 gdb_test "print \$_probe_arg2 == v" " = 1" \
78 "check \$_probe_arg2 for probe m4"
79
80 # Reinit GDB, set a breakpoint on probe ps.
81 delete_breakpoints
82 rerun_to_main
83 if {[runto "-pstap test:ps"]} {
84 pass "run to -pstap test:m4"
85 } else {
86 fail "run to -pstap test:m4"
87 }
88
89 gdb_test "print \$_probe_argc" " = 3" \
90 "print \$_probe_argc for probe ps"
91 gdb_test "print (const char *) \$_probe_arg1" \
92 " = $hex .This is another test message.*" \
93 "print \$_probe_arg1 for probe ps"
94
95 return 0
96 }
97
98 proc stap_test_no_debuginfo {exec_name {arg ""}} {
99 global testfile hex
100
101 if {[prepare_for_testing ${testfile}.exp ${exec_name} ${testfile}.c \
102 {$arg nodebug optimize=-O2}]} {
103 return -1
104 }
105
106 if {[runto "-pstap test:user"]} {
107 pass "run to -pstap test:user"
108 } else {
109 fail "run to -pstap test:user"
110 }
111
112 # Test probe arguments.
113 gdb_test "print \$_probe_argc" " = 1" \
114 "print \$_probe_argc for probe user"
115 gdb_test "print \$_probe_arg0 == 23" " = 1" \
116 "check \$_probe_arg0 for probe user"
117 gdb_test "print \$_probe_arg1" \
118 "Invalid probe argument 1 -- probe has 1 arguments available" \
119 "check \$_probe_arg1 for probe user"
120
121 # Set a breakpoint with multiple probe locations.
122 # In this scenario, we may expect more than 2 locations because of
123 # the optimizations (inlining, loop unrolling, etc).
124 gdb_test "break -pstap test:two" \
125 "Breakpoint .* at $hex.*\[0-9\]+ locations.*" \
126 "set multi-location probe breakpoint (probe two)"
127
128 # Reinit GDB, set a breakpoint on probe m4.
129 delete_breakpoints
130 rerun_to_main
131 if {[runto "-pstap test:m4"]} {
132 pass "run to -pstap test:m4"
133 } else {
134 fail "run to -pstap test:m4"
135 }
136
137 # Testing probe arguments.
138 gdb_test "print \$_probe_argc" " = 3" \
139 "print \$_probe_argc for probe m4"
140 gdb_test "print \$_probe_arg0" " = 42" \
141 "check \$_probe_arg0 for probe m4"
142 gdb_test "print (const char *) \$_probe_arg1" \
143 " = $hex .This is a test message.*" \
144 "check \$_probe_arg1 for probe m4"
145 gdb_test "print \$_probe_arg2 == 0" " = 1" \
146 "check \$_probe_arg2 for probe m4"
147
148 # Reinit GDB, set a breakpoint on probe ps.
149 delete_breakpoints
150 rerun_to_main
151 if {[runto "-pstap test:ps"]} {
152 pass "run to -pstap test:m4"
153 } else {
154 fail "run to -pstap test:m4"
155 }
156
157 gdb_test "print \$_probe_argc" " = 3" \
158 "print \$_probe_argc for probe ps"
159 gdb_test "print (const char *) \$_probe_arg1" \
160 " = $hex .This is another test message.*" \
161 "print \$_probe_arg1 for probe ps"
162
163 return 0
164 }
165
166 with_test_prefix "without semaphore, not optimized" {
167 if {[stap_test "stap-probe-nosem-noopt"] == -1} {
168 untested stap-probe.exp
169 return -1
170 }
171 }
172
173 with_test_prefix "with semaphore, not optimized" {
174 stap_test "stap-probe-sem-noopt" "-DUSE_PROBES"
175 }
176
177 with_test_prefix "without semaphore, optimized" {
178 stap_test_no_debuginfo "stap-probe-nosem-opt"
179 }
180
181 with_test_prefix "with semaphore, optimized" {
182 stap_test_no_debuginfo "stap-probe-sem-opt" "-DUSE_PROBES"
183 }
This page took 0.035575 seconds and 5 git commands to generate.