1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
set test "sduprobes"
if {![installtest_p]} {untested $test; return}
# Compile a C program to use as the user-space probing target
set sup_srcpath "[pwd]/static_uprobes.c"
set sup_exepath "[pwd]/static_uprobes.x"
set sup_flags "additional_flags=-iquote$env(SYSTEMTAP_RUNTIME) additional_flags=-L$env(CRASH_LIBDIR) additional_flags=-lsduprobes"
set fp [open $sup_srcpath "w"]
puts $fp "
#include <stdlib.h>
#define USE_STAP_PROBE 1
#include \"sdt.h\"
foo ()
{
STAP_PROBE(tstlabel,label1);
}
bar (int i)
{
if (i == 0)
i = 1000;
STAP_PROBE1(tstlabel,label2,i);
}
baz (int i, char* s)
{
STAP_PROBE1(tstlabel,label0,i);
if (i == 0)
i = 1000;
STAP_PROBE2(tstlabel,label3,i,s);
}
buz (int parm)
{
}
main ()
{
sleep(5);
foo();
bar(2);
baz(3,\"abc\");
buz(4);
}
"
close $fp
set res [target_compile $sup_srcpath $sup_exepath executable $sup_flags]
if { $res != "" } {
verbose "target_compile failed: $res" 2
fail "compiling static_uprobes.c"
return
} else {
pass "compiling static_uprobes.c"
}
set fp [open "[pwd]/static_uprobes.stp" "w"]
puts $fp "
probe process(\"static_uprobes.x\").mark(\"label0\")
{
printf(\"In label0 probe %#x\\n\", \$arg1)
}
probe process(\"static_uprobes.x\").mark(\"label1\")
{
printf(\"In label1 probe\\n\")
}
probe process(\"static_uprobes.x\").mark(\"label2\")
{
printf(\"In label2 probe %#x\\n\", \$arg1)
}
probe process(\"static_uprobes.x\").mark(\"label3\")
{
printf(\"In label3 probe %#x %#x\\n\", \$arg1, \$arg2)
}
"
close $fp
# Try to find utrace_attach symbol in /proc/kallsyms
# copy from utrace_p5.exp
set utrace_support_found 0
set path "/proc/kallsyms"
if {! [catch {exec grep -q utrace_attach $path} dummy]} {
set utrace_support_found 1
}
if {$utrace_support_found == 0} { untested "$test"; return }
set ok 0
verbose -log "spawn stap -c $sup_exepath [pwd]/static_uprobes.stp"
spawn stap -c $sup_exepath [pwd]/static_uprobes.stp
expect {
-timeout 180
-re {In label1 probe} { incr ok; exp_continue }
-re {In label2 probe 0x2} { incr ok; exp_continue }
-re {In label0 probe 0x3} { incr ok; exp_continue }
-re {In label3 probe 0x3 0x[0-9a-f][0-9a-f]} { incr ok; exp_continue }
timeout { fail "$test (timeout)" }
eof { }
}
if {$ok == 4} { pass "$test" } { fail "$test ($ok)" }
set ok 0
# Now do a debuginfo style probe of the above test
set fp [open "[pwd]/static_uprobes.sh" "w"]
puts $fp "
ed $sup_srcpath <<HERE
/USE_STAP_PROBE/d
/buz/+1
a
DTRACE_PROBE1(tstlabel,label4,parm);
.
w
q
"
close $fp
spawn sh [pwd]/static_uprobes.sh
set fp [open "[pwd]/static_uprobes.stp" "w"]
puts $fp "
probe process(\"static_uprobes.x\").mark(\"label0\")
{
printf(\"In label0 probe %#x\\n\", \$arg1)
}
probe process(\"static_uprobes.x\").mark(\"label1\")
{
printf(\"In label1 probe\\n\")
}
probe process(\"static_uprobes.x\").mark(\"label2\")
{
printf(\"In label2 probe %#x\\n\", \$arg1)
}
probe process(\"static_uprobes.x\").mark(\"label3\")
{
printf(\"In label3 probe %#x %#x\\n\", \$arg1, \$arg2)
}
probe process(\"static_uprobes.x\").mark(\"label4\")
{
printf(\"In label4 dtrace probe %#x\\n\", \$arg1)
}
"
close $fp
set sup_flags "additional_flags=-iquote$env(SYSTEMTAP_RUNTIME) additional_flags=-g additional_flags=-O additional_flags=$env(SYSTEMTAP_RUNTIME)/sduprobes.c"
set res [target_compile $sup_srcpath $sup_exepath executable $sup_flags]
if { $res != "" } {
verbose "target_compile failed: $res" 2
fail "compiling sduprobes.c -g"
return
} else {
pass "compiling sduprobes.c -g"
}
verbose -log "spawn stap -c $sup_exepath [pwd]/static_uprobes.stp"
spawn stap -c $sup_exepath [pwd]/static_uprobes.stp
expect {
-timeout 180
-re {In label1 probe} { incr ok; exp_continue }
-re {In label2 probe 0x2} { incr ok; exp_continue }
-re {In label0 probe 0x3} { incr ok; exp_continue }
-re {In label3 probe 0x3 0x[0-9a-f][0-9a-f]} { incr ok; exp_continue }
-re {In label4 dtrace probe 0x4} { incr ok; exp_continue }
timeout { fail "$test (timeout)" }
eof { }
}
wait
if {$ok == 5} { pass "$test" } { fail "$test ($ok)" }
|