]> TLD Linux GIT Repositories - packages/systemtap.git/blob - systemtap-dtrace-flexibility.patch
6cf9db008662e4f19f5cf3aa5904e033c2e5b6ff
[packages/systemtap.git] / systemtap-dtrace-flexibility.patch
1 From c486eff3f809b5ce544d5a032198e7680f2b7f2b Mon Sep 17 00:00:00 2001
2 From: Stan Cox <scox@redhat.com>
3 Date: Tue, 9 Sep 2014 15:07:44 -0400
4 Subject: [PATCH 1/3] Add -fpic -fPIC to the list of accepted but ignored
5  dtrace options.
6
7 * dtrace.in (main):  Add ignore_options.
8 ---
9  dtrace.in                           | 4 +++-
10  testsuite/systemtap.base/dtrace.exp | 8 ++++----
11  2 files changed, 7 insertions(+), 5 deletions(-)
12
13 diff --git a/dtrace.in b/dtrace.in
14 index d5f189d4fc9e..2f9fb6307e28 100644
15 --- a/dtrace.in
16 +++ b/dtrace.in
17 @@ -305,6 +305,8 @@ def main():
18      s_filename = ""
19      includes = []
20      defines = []
21 +    ignore_options = ["-64", "-32", "-fpic", "-fPIC"]
22 +
23      while i < len(sys.argv):
24          if sys.argv[i] == "-o":
25              i += 1
26 @@ -330,7 +332,7 @@ def main():
27              HAVE_PYP = False
28          elif sys.argv[i] == "--types":
29              print sys.argv[0] + ": note: obsolete option --types used"
30 -        elif sys.argv[i] == "-64" or sys.argv[i] == "-32":
31 +        elif sys.argv[i] in ignore_options:
32              pass                # dtrace users sometimes pass these flags
33          elif sys.argv[i] == "--help":
34              dtrace_help()
35 diff --git a/testsuite/systemtap.base/dtrace.exp b/testsuite/systemtap.base/dtrace.exp
36 index 252dad90ede5..e029748100d6 100644
37 --- a/testsuite/systemtap.base/dtrace.exp
38 +++ b/testsuite/systemtap.base/dtrace.exp
39 @@ -53,12 +53,12 @@ set incpath "/tmp/dtrace_inc"
40  # -----------------------------------------------------------------
41  # test command line option and file handling 
42  
43 -verbose -log "$dtrace -G -s $dpath -o XXX.o"
44 -catch {exec $dtrace -G -s $dpath -o XXX.o}
45 +verbose -log "$dtrace -G -64 -fPIC -s $dpath -o XXX.o"
46 +catch {exec $dtrace -G -64 -fPIC -s $dpath -o XXX.o}
47  if {[file exists XXX.o]} then {
48 -    pass "dtrace -G -o XXX.o"
49 +    pass "dtrace -G -64 -fPIC -o XXX.o"
50  } else {
51 -    fail "dtrace -G -o XXX.o"
52 +    fail "dtrace -G -64 -fPIC -o XXX.o"
53  }
54  exec rm -f XXX.o
55  
56 -- 
57 1.9.3
58
59
60 From 52cac9d8159a399b824201f4d2c98abe89a01767 Mon Sep 17 00:00:00 2001
61 From: Stan Cox <scox@redhat.com>
62 Date: Tue, 23 Sep 2014 13:42:54 -0400
63 Subject: [PATCH 2/3] Ignore C declarations in .d file and use string pattern
64  matching as a fallback mechanism.
65
66 * dtrace.in (_PypProvider):  SkipTo the provider{...}
67 (main): If pyparsing fails, then fallback to pattern matching.
68
69 * dtrace.exp:  Add a fallback test.
70 ---
71  dtrace.in                           | 39 +++++++++++++++++++++++++++---------
72  testsuite/systemtap.base/dtrace.exp | 40 +++++++++++++++++++++++++++++++++++++
73  2 files changed, 70 insertions(+), 9 deletions(-)
74
75 diff --git a/dtrace.in b/dtrace.in
76 index 2f9fb6307e28..04ace92181d9 100644
77 --- a/dtrace.in
78 +++ b/dtrace.in
79 @@ -29,13 +29,13 @@ try:
80      from pyparsing import alphas, cStyleComment, delimitedList, Group, \
81          Keyword, lineno, Literal, nestedExpr, nums, oneOf, OneOrMore, \
82          Optional, ParseException, ParserElement, restOfLine, restOfLine, \
83 -        Suppress, Word, ZeroOrMore
84 +        Suppress, SkipTo, Word, ZeroOrMore
85      HAVE_PYP = True
86  except ImportError:
87      HAVE_PYP = False
88  
89  
90 -# Common file creation methods for pyparsing and regexparsing
91 +# Common file creation methods for pyparsing and string pattern matching
92  
93  class _HeaderCreator(object):
94      def init_semaphores(self, fdesc):
95 @@ -149,7 +149,7 @@ class _PypProvider(_HeaderCreator):
96  
97          provider_decl = (PROVIDER + Optional(ident)
98                           + lbrace + Group(probe_decls) + rbrace + Optional(semi))
99 -        dtrace_statement = Group(decls | provider_decl)
100 +        dtrace_statement = Group (SkipTo("provider", include=False) + provider_decl)
101          self.dtrace_statements = ZeroOrMore(dtrace_statement)
102  
103          cplusplus_linecomment = Literal("//") + restOfLine
104 @@ -167,7 +167,10 @@ class _PypProvider(_HeaderCreator):
105          for asti in self.ast:
106              if len(asti) == 0:
107                  continue
108 -            elif asti[0] == "provider":
109 +            # ignore SkipTo token
110 +            if asti[0] != "provider":
111 +                del asti[0]
112 +            if asti[0] == "provider":
113                  # list of probes
114                  for prb in asti[2]:
115                      semaphores_def += self.add_semaphore(asti[1], prb[1])
116 @@ -186,15 +189,18 @@ class _PypProvider(_HeaderCreator):
117                  self.ast = self.bnf.parseFile(provider).asList()
118          except ParseException, err:
119              if len(self.current_probe):
120 -                print "%s:%s:%d: syntax error near:\nprobe %s\n" % (sys.argv[0],provider, self.current_lineno, self.current_probe)
121 +                print "Warning: %s:%s:%d: syntax error near:\nprobe %s\n" % (sys.argv[0],provider, self.current_lineno, self.current_probe)
122              else:
123 -                print "%s:%s:%d syntax error near:\n%s\n" % (sys.argv[0],provider,err.lineno, err.line)
124 -            sys.exit(1)
125 +                print "Warning: %s:%s:%d syntax error near:\n%s\n" % (sys.argv[0],provider,err.lineno, err.line)
126 +            raise ParseException, err
127    
128          probes_def = ""
129          for asti in self.ast:
130              if len(asti) == 0:
131                  continue
132 +            # ignore SkipTo token
133 +            if asti[0] != "provider":
134 +                del asti[0]
135              if asti[0] == "provider":
136                  # list of probes
137                  for prb in asti[2]:
138 @@ -369,14 +375,29 @@ def main():
139              providers = _PypProvider()
140          else:
141              providers = _ReProvider()
142 -        providers.probe_write(s_filename, filename + suffix)
143 +        while True:
144 +            try:
145 +                providers.probe_write(s_filename, filename + suffix)
146 +                break;
147 +            # complex C declarations can fool the pyparsing grammar.  
148 +            # we could increase the complexity of the grammar
149 +            # instead we fall back to string pattern matching
150 +            except ParseException, err:
151 +                print "Warning: Proceeding as if --no-pyparsing was given.\n"
152 +                providers = _ReProvider()
153      elif build_source:
154          if HAVE_PYP:
155              providers = _PypProvider()
156          else:
157              providers = _ReProvider()
158          (ignore, fname) = mkstemp(suffix=".h")
159 -        providers.probe_write(s_filename, fname)
160 +        while True:
161 +            try:
162 +                providers.probe_write(s_filename, fname)
163 +                break;
164 +            except ParseException, err:
165 +                print "Warning: Proceeding as if --no-pyparsing was given.\n"
166 +                providers = _ReProvider()
167          if not keep_temps:
168              os.remove(fname)
169          else:
170 diff --git a/testsuite/systemtap.base/dtrace.exp b/testsuite/systemtap.base/dtrace.exp
171 index e029748100d6..60cab3f5abf2 100644
172 --- a/testsuite/systemtap.base/dtrace.exp
173 +++ b/testsuite/systemtap.base/dtrace.exp
174 @@ -207,6 +207,46 @@ if { $ok == 4} {
175  }
176  exec rm -f XXX.h
177  
178 +set ok 0
179 +set pypath "/tmp/pypath.d"
180 +set $fp [open $pypath "w"]
181 +puts $fp "
182 +#include <sys/types.h>
183 +
184 +provider alpha {
185 +       probe request__start(string, uint8_t, uint16_t, int, void *);
186 +       probe request__one(string, uint8_t, uint32_t, int, int);
187 +       probe client__two(int, int);
188 +       probe client__three(int, string, pid_t, zoneid_t);
189 +       probe input__stop(int, int, uint32_t, uint32_t, int8_t, uint8_t*, double*);
190 +};
191 +
192 +#ifdef DCL_AFTER_PROVIDER
193 +typedef unsigned short int __u_short;
194 +typedef const static unsigned short __u_c_short;
195 +#endif
196 +
197 +#pragma D attributes Unknown provider alpha provider
198 +"
199 +close $fp
200 +verbose -log "$dtrace -C -h -s $pypath -o XXX.h"
201 +spawn $dtrace -C -DDCL_AFTER_PROVIDER -h -s $pypath -o XXX.h
202 +expect {
203 +    -re {Warning.*syntax error} {incr ok; exp_continue}
204 +    -re {Warning.*--no-pyparsing} {incr ok; exp_continue}
205 +    eof { }
206 +}
207 +catch {close}; catch {wait}
208 +if {[file exists XXX.h]} then {
209 +    incr ok;
210 +}
211 +if { $ok == 3} {
212 +    pass "dtrace parser check"
213 +} else {
214 +    fail "dtrace parser check $ok"
215 +}
216 +exec rm -f XXX.h
217 +
218  verbose -log "$dtrace -I$incpath -G -s $idpath"
219  catch {exec $dtrace -G -s $dpath}
220  if {[file exists test.o]} then {
221 -- 
222 1.9.3
223
224
225 From 3525152408f15e23dcffe2371bbd575f1646d691 Mon Sep 17 00:00:00 2001
226 From: Stan Cox <scox@redhat.com>
227 Date: Thu, 25 Sep 2014 13:47:04 -0400
228 Subject: [PATCH 3/3] Add pyparsing / no-parsing compatibility test.
229
230 * dtrace.exp:  Add pyparsing compatibility test.
231 ---
232  testsuite/systemtap.base/dtrace.exp | 93 ++++++++++++++++++++++++++++---------
233  1 file changed, 72 insertions(+), 21 deletions(-)
234
235 diff --git a/testsuite/systemtap.base/dtrace.exp b/testsuite/systemtap.base/dtrace.exp
236 index 60cab3f5abf2..e455c298737a 100644
237 --- a/testsuite/systemtap.base/dtrace.exp
238 +++ b/testsuite/systemtap.base/dtrace.exp
239 @@ -8,6 +8,8 @@ if {[installtest_p]} {
240      set dtrace ../dtrace
241  }
242  
243 +# Create the test .d files
244 +
245  exec mkdir -p /tmp/dtrace
246  
247  set dpath "/tmp/dtrace/test.d"
248 @@ -48,6 +50,29 @@ provider tstsyscall
249  "
250  close $fp
251  
252 +set pypath "/tmp/pypath.d"
253 +set $fp [open $pypath "w"]
254 +puts $fp "
255 +#include <sys/types.h>
256 +
257 +provider alpha {
258 +       probe request__start(string, uint8_t, uint16_t, int, void *);
259 +       probe request__one(string, uint8_t, uint32_t, int, int);
260 +       probe client__two(int, int);
261 +       probe client__three(int, string, pid_t, zoneid_t);
262 +       probe input__stop(int, int, uint32_t, uint32_t, int8_t, uint8_t*, double*);
263 +};
264 +
265 +#ifdef DCL_AFTER_PROVIDER
266 +typedef unsigned short int __u_short;
267 +typedef const static unsigned short __u_c_short;
268 +#endif
269 +
270 +#pragma D attributes Unknown provider alpha provider
271 +"
272 +close $fp
273 +
274 +
275  set incpath "/tmp/dtrace_inc"
276  
277  # -----------------------------------------------------------------
278 @@ -156,6 +181,9 @@ if { $ok != 0} {
279      fail "dtrace CFLAGS= CC="
280  }
281  
282 +# -----------------------------------------------------------------
283 +# test -h header file creation
284 +
285  set ok 0
286  verbose -log "$dtrace -C -h -s $dpath -o XXX.h"
287  catch {exec $dtrace -C -h -s $dpath -o XXX.h}
288 @@ -189,6 +217,9 @@ if { $ok == 4} {
289  }
290  exec rm -f XXX.h
291  
292 +# -----------------------------------------------------------------
293 +# test --no-pyparsing
294 +
295  set ok 0
296  verbose -log "$dtrace -C --no-pyparsing -I$incpath -h -s $idpath -o XXX.h"
297  catch {exec $dtrace -C --no-pyparsing -I$incpath -h -s $idpath -o XXX.h}
298 @@ -207,28 +238,10 @@ if { $ok == 4} {
299  }
300  exec rm -f XXX.h
301  
302 -set ok 0
303 -set pypath "/tmp/pypath.d"
304 -set $fp [open $pypath "w"]
305 -puts $fp "
306 -#include <sys/types.h>
307 -
308 -provider alpha {
309 -       probe request__start(string, uint8_t, uint16_t, int, void *);
310 -       probe request__one(string, uint8_t, uint32_t, int, int);
311 -       probe client__two(int, int);
312 -       probe client__three(int, string, pid_t, zoneid_t);
313 -       probe input__stop(int, int, uint32_t, uint32_t, int8_t, uint8_t*, double*);
314 -};
315 -
316 -#ifdef DCL_AFTER_PROVIDER
317 -typedef unsigned short int __u_short;
318 -typedef const static unsigned short __u_c_short;
319 -#endif
320 +# -----------------------------------------------------------------
321 +# test fallback to --no-pyparsing
322  
323 -#pragma D attributes Unknown provider alpha provider
324 -"
325 -close $fp
326 +set ok 0
327  verbose -log "$dtrace -C -h -s $pypath -o XXX.h"
328  spawn $dtrace -C -DDCL_AFTER_PROVIDER -h -s $pypath -o XXX.h
329  expect {
330 @@ -247,6 +260,9 @@ if { $ok == 3} {
331  }
332  exec rm -f XXX.h
333  
334 +# -----------------------------------------------------------------
335 +# test -G object file creation
336 +
337  verbose -log "$dtrace -I$incpath -G -s $idpath"
338  catch {exec $dtrace -G -s $dpath}
339  if {[file exists test.o]} then {
340 @@ -256,5 +272,40 @@ if {[file exists test.o]} then {
341  }
342  exec rm -f test.o
343  
344 +# -----------------------------------------------------------------
345 +# test dtrace for pyparsing / --no-pyparsing compatibility
346 +
347 +set ok 0
348 +set dfiles {dtrace}
349 +foreach i $dfiles {
350 +    verbose -log "$dtrace $srcdir/$subdir/$i.d"
351 +    catch {exec $dtrace -C -h -s $srcdir/$subdir/$i.d -o $i-1.h}
352 +    catch {exec $dtrace -C -h --no-pyparsing -s $srcdir/$subdir/$i.d -o $i-2.h}
353 +    spawn diff -wqs $i-1.h $i-2.h
354 +    expect {
355 +       -re {Files.*identical} {incr ok; exp_continue}
356 +       eof { }
357 +    }
358 +    catch {exec $dtrace -C -G -s $srcdir/$subdir/$i.d -o $i-1.o}
359 +    catch {exec $dtrace -C -G --no-pyparsing -s $srcdir/$subdir/$i.d -o $i-2.o}
360 +    verbose -log "exec nm $i-1.o > $i-1.od"
361 +    catch {exec nm $i-1.o > $i-1.od}
362 +    catch {exec nm $i-2.o > $i-2.od}
363 +    spawn diff -qs $i-1.od $i-2.od
364 +    expect {
365 +       -re {Files.*identical} {incr ok; exp_continue}
366 +       eof { }
367 +    }
368 +    catch {exec /bin/rm $i-1.h $i-2.h $i-1.o $i-2.o}
369 +}
370 +if { $ok == 2} {
371 +    pass "dtrace known uses"
372 +} else {
373 +    fail "dtrace known uses ${ok}"
374 +}
375 +
376 +# -----------------------------------------------------------------
377 +# cleanup
378 +
379  exec /bin/rm -r /tmp/dtrace /tmp/dtrace_inc
380  # -----------------------------------------------------------------
381 -- 
382 1.9.3
383