A short terms answer to the performance problem is to put
disable decl_init, const_decl_init
in the initial @@ of the rule matching the structure. This turns off two
isomorphisms that really should not be applied in this code anyway.
julia
On Tue, 14 Feb 2012, Terry Wilson wrote:
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
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.
It looks to be an algorithmic issue. With a short struct, no problem. But add a
lot of fields, and it takes much longer each addition. Moving the #if 0 after
l, then m, then n was instructive (9s vs 36s, vs 160s seems rather factorial).
The struct I'm currently working on has about 80 fields, so that would explain
why it was never finishing. :-)
struct thing {
int a;
int b;
int c;
int d;
int e;
int f;
int g;
int h;
int i;
int j;
int k;
int l;
#if 0
int m;
int n;
int o;
int p;
int q;
int r;
int s;
int t;
int u;
int v;
int w;
int x;
int y;
int z;
#endif
};
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?
Yes, I'm moving away from directly accessing the struct fields to using
accessors. The accessors for the different types end up being very similar, so
just doing the types together works very well. I can go through and find the
names of all the types and limit by regex on the names of the identifiers, it
would just be easier if I could specify the type--certainly not that big of a
deal though.
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.
Actually, doing
@@
struct thing *t;
int i;
@@
- thing->i
yields the following syntax error because I guess it doesn't think of "int i"
as an identifier?:
Fatal error: exception Failure("minus: parse error:
= File "test2.cocci", line 6, column 9, charpos = 40
around = 'i', whole content = - thing->i
")
Terry
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)