On Thu, 21 Jan 2010, Wolfram Sang wrote:
> Hello,
>
> I am playing with coccinelle and want to debug a scenario where spatch does
> not
> yield what I'd expect. Given this SmPL-snipplet (just a test case):
>
> @@
> identifier client, data;
> @@
> i2c_set_clientdata(client, data);
> ...
> + i2c_set_clientdata(client, NULL);
> kfree(data);
>
> and checking a kernel-source file
>
> spatch -sp_file clientdata.cocci -outplace drivers/hwmon/ad7414.c
>
> I think it should give me a match (going the error-path in the
> probe_function),
> but it doesn't. Commenting out the 'return 0' in that function, it will give
> me
> the match. I did a minimal test case to check if gotos are handled properly,
> but for the testcase, it works fine.
>
> Testcase-SmPL:
>
> @@
> @@
> foo();
> ...
> + baz();
> bar();
>
> Testcase-Pseudocode:
>
> void main(void) {
>
>
> foo();
>
> if (hurz())
> goto out;
>
> blub();
> bar();
> return 0;
>
> out:
> bar();
> return 1;
>
> }
>
> So, I am stuck how to proceed. What are useful debug strategies now to see
> where I (or the program) am wrong? Pointers to documentation/threads/wiki will
> do, I just couldn't find any.
There is some documentation available from the Coccinelle home page:
http://coccinelle.lip6.fr/documentation.php
I don't think it would have helped you in this case, though...
The problem is that for transformation ... is quantified over all paths,
with the idea that when you transform, you want to be sure that the
pattern is matching in a consistent way. That is true in your toy example
- there is a bar along every path - but not true in the Linux code. What
you want, is that if there is a kfree, then the i2c_set_clientdata call
should be put in front of it. And if there is no kfree, then nothing
should happen. This is indicated by putting a ? in front of kfree. With
that, the example patch makes a transformation.
There is an option -verbose_ctl_engine to see what is happening in the
matching process. But unless you are very familiar with the temporal
logic CTL, it will not be very understandable.
julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)