Introduction to Coccinelle
Julia Lawall
University of Copenhagen/INRIA-Regal November 25, 2009
1
Introduction to Coccinelle Julia Lawall University of - - PowerPoint PPT Presentation
Introduction to Coccinelle Julia Lawall University of Copenhagen/INRIA-Regal November 25, 2009 1 Overview The structure of a semantic patch. Isomorphisms. Depends on. Dots. Nests. Positions. Python. 2 The !&
1
◮ The structure of a semantic patch. ◮ Isomorphisms. ◮ Depends on. ◮ Dots. ◮ Nests. ◮ Positions. ◮ Python. 2
3
◮ Metavariable declaration ◮ Transformation specification
4
◮ expression, statement, type, constant, local idexpression ◮ A type from the source program ◮ iterator, declarer, iterator name, declarer name, typedef
◮ - in the leftmost column for something to remove ◮ + in the leftmost column for something to add ◮ * in the leftmost column for something of interest
◮ Spaces, newlines irrelevant. 5
◮ Only consider struct device-typed expressions. ◮ Consider both structures and pointers to structures. ◮ Consider the ordering of the rules. 6
7
8
9
10
11
12
13
14
15
◮ The transformation might not be correct if kernel.h is not
◮ Problem: #include <linux/kernel.h> is far from the
16
◮ Takes a lock. ◮ Saves current interrupt status in flags. ◮ Disables interrupts.
17
◮ Calls to spin_lock_irqsave share their second
◮ Calls to spin_lock_irqsave may be separated by
◮ There should be no calls to spin_lock_irqrestore
18
19
◮ An allocation. ◮ Storage in a local variable. ◮ No use. ◮ Return of an error code (negative constant).
20
21
22
23
◮ Change all occurrences within a region of code. ◮ Example: a parameter is replaced by a call to an access
◮ Change or match at least one occurrence in a region of
◮ Change or match at least one occurrence within an
◮ Example: kfree(<+... x ...+>); 24
◮ V4L2_TUNER_MODE_MONO is 0. ◮ The test is always false. 25
◮ Search for constants that are defined to 0. ◮ Check that there is not another nonzero definition. ◮ Find a corresponding use of &.
◮ Find a use of &. ◮ Check that the constant is 0. ◮ Check that there is not another nonzero definition. ◮ Report on the bug site.
26
◮ The rule has a name: r. ◮ p is a position metavariable, so we can find the same &
27
◮ Both rules inherit C. ◮ Each rule is applied once for each value of C. ◮ The second rule puts a constraint on E.
28
◮ Python rules only inherit metavariables, using << notation. ◮ Depends on clause is evaluated for each inherited set of
◮ print_main is part of a library for printing output in Emacs
29
30