b35f350e4466bfacb462d230b76aead8c0cfbeef
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / stap-probe.exp
1 # Copyright (C) 2012-2020 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 standard_testfile
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 srcfile
23
24 if {[prepare_for_testing "failed to prepare" ${exec_name} $srcfile \
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 probe at PC $hex" \
34 "check argument not at probe point"
35
36 gdb_test "info probes stap" \
37 "test *user *$hex .*"
38
39 if {[runto "-pstap test:user"]} {
40 pass "run to -pstap test:user"
41 } else {
42 fail "run to -pstap test:user"
43 }
44
45 # Test probe arguments.
46 gdb_test "print \$_probe_argc" " = 1" \
47 "print \$_probe_argc for probe user"
48 gdb_test "print \$_probe_arg0 == x" " = 1" \
49 "check \$_probe_arg0 for probe user"
50 gdb_test "print \$_probe_arg1" \
51 "Invalid probe argument 1 -- probe has 1 arguments available" \
52 "check \$_probe_arg1 for probe user"
53
54 # Set a breakpoint with multiple probe locations.
55 gdb_test "break -pstap test:two" \
56 "Breakpoint \[0-9\]+ at $hex.*2 locations.*" \
57 "set multi-location probe breakpoint (probe two)"
58
59 # Reinit GDB, set a breakpoint on probe m4.
60 delete_breakpoints
61 if {[runto "-pstap test:m4"]} {
62 pass "run to -pstap test:m4"
63 } else {
64 fail "run to -pstap test:m4"
65 }
66
67 # Testing probe arguments.
68 gdb_test "print \$_probe_argc" " = 3" \
69 "print \$_probe_argc for probe m4"
70 gdb_test "print \$_probe_arg0" " = 42" \
71 "check \$_probe_arg0 for probe m4"
72 gdb_test "print (const char *) \$_probe_arg1" \
73 " = $hex .This is a test message.*" \
74 "check \$_probe_arg1 for probe m4"
75 gdb_test "print \$_probe_arg2 == v" " = 1" \
76 "check \$_probe_arg2 for probe m4"
77
78 # Reinit GDB, set a breakpoint on probe ps.
79 delete_breakpoints
80 if {[runto "-pstap test:ps"]} {
81 pass "run to -pstap test:m4"
82 } else {
83 fail "run to -pstap test:m4"
84 }
85
86 gdb_test "print \$_probe_argc" " = 3" \
87 "print \$_probe_argc for probe ps"
88 gdb_test "print (const char *) \$_probe_arg1" \
89 " = $hex .This is another test message.*" \
90 "print \$_probe_arg1 for probe ps"
91
92 return 0
93 }
94
95 proc stap_test_no_debuginfo {exec_name {arg ""}} {
96 global testfile hex
97
98 if {[prepare_for_testing "failed to prepare" ${exec_name} ${testfile}.c \
99 {$arg nodebug optimize=-O2}]} {
100 return -1
101 }
102
103 if {[runto "-pstap test:user"]} {
104 pass "run to -pstap test:user"
105 } else {
106 fail "run to -pstap test:user"
107 }
108
109 # Test probe arguments.
110 gdb_test "print \$_probe_argc" " = 1" \
111 "print \$_probe_argc for probe user"
112 gdb_test "print \$_probe_arg0 == 23" " = 1" \
113 "check \$_probe_arg0 for probe user"
114 gdb_test "print \$_probe_arg1" \
115 "Invalid probe argument 1 -- probe has 1 arguments available" \
116 "check \$_probe_arg1 for probe user"
117
118 # Set a breakpoint with multiple probe locations.
119 # In this scenario, we may expect more than 2 locations because of
120 # the optimizations (inlining, loop unrolling, etc).
121 gdb_test "break -pstap test:two" \
122 "Breakpoint .* at $hex.*\[0-9\]+ locations.*" \
123 "set multi-location probe breakpoint (probe two)"
124
125 # Reinit GDB, set a breakpoint on probe m4.
126 delete_breakpoints
127 if {[runto "-pstap test:m4"]} {
128 pass "run to -pstap test:m4"
129 } else {
130 fail "run to -pstap test:m4"
131 }
132
133 # Testing probe arguments.
134 gdb_test "print \$_probe_argc" " = 3" \
135 "print \$_probe_argc for probe m4"
136 gdb_test "print \$_probe_arg0" " = 42" \
137 "check \$_probe_arg0 for probe m4"
138 gdb_test "print (const char *) \$_probe_arg1" \
139 " = $hex .This is a test message.*" \
140 "check \$_probe_arg1 for probe m4"
141 gdb_test "print \$_probe_arg2 == 0" " = 1" \
142 "check \$_probe_arg2 for probe m4"
143
144 # Reinit GDB, set a breakpoint on probe ps.
145 delete_breakpoints
146 if {[runto "-pstap test:ps"]} {
147 pass "run to -pstap test:m4"
148 } else {
149 fail "run to -pstap test:m4"
150 }
151
152 gdb_test "print \$_probe_argc" " = 3" \
153 "print \$_probe_argc for probe ps"
154 gdb_test "print (const char *) \$_probe_arg1" \
155 " = $hex .This is another test message.*" \
156 "print \$_probe_arg1 for probe ps"
157
158 return 0
159 }
160
161 with_test_prefix "without semaphore, not optimized" {
162 if {[stap_test "stap-probe-nosem-noopt"] == -1} {
163 untested "stap probe test failed"
164 return -1
165 }
166 }
167
168 with_test_prefix "with semaphore, not optimized" {
169 stap_test "stap-probe-sem-noopt" "-DUSE_PROBES"
170 }
171
172 with_test_prefix "without semaphore, optimized" {
173 stap_test_no_debuginfo "stap-probe-nosem-opt"
174 }
175
176 with_test_prefix "with semaphore, optimized" {
177 stap_test_no_debuginfo "stap-probe-sem-opt" "-DUSE_PROBES"
178 }
This page took 0.033755 seconds and 3 git commands to generate.