dma_on_stack: &foo means it's an error too
[smatch.git] / README-smatch
blob90e69dfb001a00c15bcbd10a0756254f98471800
1     ***Compiling Smatch***
3 make
5 This compiles creates a binary called "smatch".
7     ***Using Smatch***
9 ./smatch filename.c
11 For the kernel use:  make -k CHECK=/path/to/smatch C=y bzImage | tee warns.txt
13 There is also a smatch_scripts/kchecker script for checking individual .c kernel files.
15 Most of the things that smatch prints out is not actually warnings.
16 What I was trying to do with that was catch errors where a NULL is
17 passed to a function that dereferences the parameter without checking.
18 There is a script that parses that information.
20       smatch_scripts/find_null_params.sh
22 Sorry the output is a mess right now.  This needs to be cleaned up.
24 Sometimes you it is not obvious why smatch is printing an error.
25 The --debug option is usefull here.  It prints a message on each state change.
27 Sometimes smatch segfaults.  Use valgrind to get a stack dump.  For the kernel
28 do:  make -k CHECK="valgrind /path/to/smatch" C=y failing/file.o
30     ***How Smatch Works***
32 It's basically a state machine that tracks the flow of code.
34 int a;  <- state is unitialized.
36 if (b) {
37        a = foo();  <- state is initialized. 
38        if (a) {
39               bar(a);  <- state is non zero.
40        }
42 baz(a);  <- state is undefined.  possibly unitialized, zero, or non-zero
44 The core parts of smatch understand how code flows, if conditions, loops,
45 and merging states back together.  The checker bits keep track of states
46 that they are interested in and print error messages and so on.
48     ***Coding Smatch***
50 The core smatch files start with "smatch_" the check scripts are named 
51 "check_*.c".  There is a template check script called check_template.c
52 that is designed to teach the basics.  Rename it and edit out the bits
53 you want.
56 The first file you should look at is smatch.h.  All the
57 functions for check scripts are at the top.
59 Smatch is based on sparse.  You will want to understand a couple sparse 
60 data types: 
61      struct expression from expression.h
62      struct symbol from symbol.h
63      struct statement from parse.h
65 More complicated scripts are also going to need functions from smatch_slist.h