Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/labels.exp

raw
1 set test "labels"
2 if {![installtest_p]} {untested $test; return}
3 if {![utrace_p]} { untested $test; return }
4
5 # Compile a C program to use as the user-space probing target
6 set label_srcpath "[pwd]/labels.c"
7 set label_exepath "[pwd]/labels.x"
8 set label_sopath "[pwd]/labels.so"
9 set label_flags "additional_flags=-g"
10 set fp [open $label_srcpath "w"]
11 puts $fp "#include <unistd.h>
12 int
13 foo ()
14 {
15 init_an_int:
16 return 1;
17 }
18 int
19 main ()
20 {
21 sleep(5);
22 foo();
23 int a = 0;
24 int b = 0;
25 char *c;
26 init_an_int:
27 a = 2;
28 init_an_int_again:
29 b = 3;
30 c = \"abc\";
31 ptr_inited:
32 return 1;
33 }
34 "
35 close $fp
36
37 set label_stppath "[pwd]/labels.stp"
38 set fp [open $label_stppath "w"]
39 puts $fp "
40 probe process(\"labels.x\").function(\"[email protected]\").label(\"init_*\") {printf (\"VARS %s\\n\",\$\$vars)}
41 probe process(\"labels.x\").function(\"[email protected]\").label(\"ptr_inited\") {printf (\"VARS %s\\n\",\$\$vars)}
42 probe process(\"labels.x\").function(\"[email protected]\").label(\"init_an_int\") {printf (\"init_an_int\\n\")}
43 probe process(\"labels.x\").function(\"*\").label(\"*\") {printf (\"label=%s\\n\", pnlabel())}
44 "
45 close $fp
46
47 set ok 0
48
49 set res [target_compile $label_srcpath $label_exepath executable $label_flags]
50 if { $res != "" } {
51 verbose "target_compile failed: $res" 2
52 fail "compiling labels.c $label_flags"
53 catch {exec rm -f $label_srcpath $label_stppath}
54 return
55 } else {
56 pass "compiling labels.c $label_flags"
57 }
58
59 # line number error (expect no output at all, since no label found)
60
61 set ok 0
62 spawn stap --use-server-on-error=no -l "process(\"$label_exepath\").function(\"foo@${label_srcpath}:10\").label(\"*\")"
63
64 expect {
65 -timeout 180
66 -re {[^\r\n]+} { incr ok; exp_continue }
67 timeout { fail "$test (timeout)" }
68 eof { }
69 }
70 catch { close }; catch { wait }
71
72 if {$ok == 0} { pass "$test :N .label $ok" } { fail "$test :N .label $ok" }
73
74 # line number
75
76 set ok 0
77 spawn stap -l "process(\"$label_exepath\").function(\"foo@${label_srcpath}:5\").label(\"*\")"
78
79 expect {
80 -timeout 180
81 -re {process.*function.*labels.c:5...label..init_an_int} { incr ok; exp_continue }
82 timeout { fail "$test (timeout)" }
83 eof { }
84 }
85 catch { close }; catch { wait }
86
87 if {$ok == 1} { pass "$test :N .label $ok" } { fail "$test :N .label $ok" }
88
89 # list of labels
90
91 spawn stap -l "process(\"$label_exepath\").function(\"*\").label(\"*\")"
92
93 set ok 0
94 expect {
95 -timeout 180
96 -re {^process[^\r\n]*function[^\r\n]*labels.c:5...label..init_an_int..\r\n}
97 { incr ok; exp_continue }
98 -re {^process[^\r\n]*function[^\r\n]*labels.c:16...label..init_an_int..\r\n}
99 { incr ok; exp_continue }
100 -re {^process[^\r\n]*function[^\r\n]*labels.c:18...label..init_an_int_again..\r\n}
101 { incr ok; exp_continue }
102 -re {^process[^\r\n]*function[^\r\n]*labels.c:21...label..ptr_inited..\r\n}
103 { incr ok; exp_continue }
104 timeout { fail "$test (timeout)" }
105 eof { }
106 }
107 catch { close }; catch { wait }
108
109 if {$ok == 4} { pass "$test -l .label" } { fail "$test -l .label $ok" }
110
111 # label in an executable (only if we have uprobes)
112 foreach runtime [get_runtime_list] {
113 set test_name "$test exe .label"
114 if {$runtime != ""} {
115 lappend test_name $runtime
116 verbose -log "spawn stap -c $label_exepath $label_stppath --runtime=$runtime"
117 spawn stap -w -c $label_exepath $label_stppath --runtime=$runtime
118 } elseif {[uprobes_p]} {
119 verbose -log "spawn stap -c $label_exepath $label_stppath"
120 spawn stap -w -c $label_exepath $label_stppath
121 } else {
122 untested "$test_name"
123 continue
124 }
125
126 # Note that the output can come out in a bit different order
127 # depending on when the probes fire. This is reasonable since
128 # we've got 2 probes at the same probe point (.label("init_*") and
129 # .label("init_an_int"))
130 set ok 0
131 expect {
132 -timeout 180
133 -re {^init_an_int\r\n} { incr ok; exp_continue }
134 -re {^VARS a=0x0 b=0x0 c=0x[0-9a-f]+\r\n} { incr ok; exp_continue }
135 -re {^VARS a=0x2 b=0x0 c=0x[0-9a-f]+\r\n} { incr ok; exp_continue }
136 -re {^VARS a=0x2 b=0x3 c=0x[0-9a-f]+\r\n} { incr ok; exp_continue }
137 -re {^label=init_an_int\r\n} { incr ok; exp_continue }
138 -re {^label=init_an_int_again\r\n} { incr ok; exp_continue }
139 -re {^label=ptr_inited\r\n} { incr ok; exp_continue }
140 -re {^WARNING: Child process exited with status [0-9]+\r\n} { exp_continue }
141 timeout { fail "$test (timeout)" }
142 eof { }
143 }
144 catch { close }; catch { wait }
145 if {$ok == 8} { pass "$test_name" } { fail "$test_name $ok" }
146 }
147
148 # address of label in an executable
149
150 set label_shpath "[pwd]/label.sh"
151 set fp [open $label_shpath "w"]
152 puts $fp "
153 readelf --debug-dump $label_exepath | awk \"
154 /init_an_int_again/ {have_label=1}
155 /DW_AT_low_pc/ {if (have_label) {print \$3;exit;}}
156 \"
157 "
158 close $fp
159 spawn sh $label_shpath
160 expect {
161 -re {0x[0-9a-f]*}
162 }
163 catch { close }; catch { wait }
164
165 set ok 0
166 spawn stap -l "process\(\"$label_exepath\"\).statement($expect_out(0,string))"
167 expect {
168 -timeout 180
169 -re {process.*statement} { incr ok; exp_continue }
170 timeout { fail "$test (timeout)" }
171 eof { }
172 }
173 catch { close }; catch { wait }
174
175 if {$ok > 0} { pass "$test exe .statement" } { fail "$test exe .statement" }
176
177 set ok 0
178
179 set label_flags "additional_flags=-g additional_flags=-shared additional_flags=-fPIC"
180 set res [target_compile $label_srcpath $label_sopath executable $label_flags]
181 if { $res != "" } {
182 verbose "target_compile failed: $res" 2
183 fail "compiling labels.c $label_flags"
184 catch {exec rm -f $label_srcpath $label_stppath}
185 return
186 } else {
187 pass "compiling labels.c $label_flags"
188 }
189
190 # label in a shared object
191
192 spawn stap -l "process\(\"$label_sopath\"\).function\(\"\*\"\).label\(\"init_an_int_again\"\)"
193 expect {
194 -timeout 180
195 -re {process.*function} { incr ok; exp_continue }
196 timeout { fail "$test (timeout)" }
197 eof { }
198 }
199 catch { close }; catch { wait }
200
201 if {$ok == 1} { pass "$test so .label" } { fail "$test so .label $ok" }
202
203 # address of label in a shared object
204
205 set label_shpath "[pwd]/label.sh"
206 set fp [open $label_shpath "w"]
207 puts $fp "
208 readelf --debug-dump $label_sopath | awk \"
209 /init_an_int_again/ {have_label=1}
210 /DW_AT_low_pc/ {if (have_label) {print \$3;exit;}}
211 \"
212 "
213 close $fp
214 spawn sh $label_shpath
215 expect {
216 -re {0x[0-9a-f]*}
217 }
218 catch { close }; catch { wait }
219
220 set ok 0
221 spawn stap -l "process\(\"$label_sopath\"\).statement($expect_out(0,string))"
222 expect {
223 -timeout 180
224 -re {process.*statement} { incr ok; exp_continue }
225 timeout { fail "$test (timeout)" }
226 eof { }
227 }
228 catch { close }; catch { wait }
229
230 if {$ok > 0} { pass "$test so .statement" } { fail "$test so .statement" }
231
232 catch {exec rm -f $label_srcpath $label_stppath $label_exepath $label_shpath $label_sopath}