On Tue, 14 Feb 2012, Terry Wilson wrote:
Let's say I want to write a patch that adds accessor functions for all the
fields in a struct. When I try to pass both a type and an identifier from one
rule to a Python script rule, it seems that I end up in an infinite loop (or at
least, 100% CPU usage that doesn't seem to go away).
What I tried to do was something like:
@s@
type t;
identifier x;
@@
struct thing {
...
t x;
...
};
@script:python p@
t << s.t;
x << s.x;
@@
print "type:", t, "identifier:", x
at which point things grind to a halt. Passing only the type or the
identifier prints what I would expect, except type rule only hits once
for each type while the identifier rule hits for each (yet, by their
nature always unique) match (which, I assume means that I completely
misunderstand what it is that coccinelle is doing!) Is there a way to do
this that I've just missed?
Could you send some C code that causes the problem (grinding to a halt)?
Intuitively the above looks fine... You can use the option -show_trying
to find out what thing it is working on. That only gives function names,
unfortunately, but it should help you narrow it down.
If the only inherited metavariable in the python rule is the identifier,
it will only run the python rule once for each identifier. Actually the
types are just thrown away, because no subsequent rule is inheriting them.
Even if there were a later rule that used the types, the python rule would
still only run once per identifier. It only runs the python rule once per
unique set of bindings of the inherited metavariables. Sometimes it is
useful to inherit metavariables that you don't use, to get around this
effect.
Also, is there a way of matching in the code any expression involving a
particular type of field of a struct? Say you have something like the
following (which doesn't work):
@@
struct *thing;
int i;
expression E;
@@
- thing->i = E
+ thing_${i}_set(thing, E)
I can do the python re-writing of the function name without problem, but
am having trouble figuring out how to just match thing->something when
it evaluates to an int.
I'm not sure to understand the problem. You want to specify the type of
thing, I guess, not thing->something? Probably if the rule is not working
it is just because it doesn't know the type of thing, because that is in a
header file that is not getting included. You could try -all_includes or
-recursive_includes. Or add more -I options. You can see where types are
known by running spatch -type_c and your C file.
julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)