blob: b3c33b93f16b03d24aa93081fe4f4e8f0e31a5ce [file] [log] [blame]
Daniel Dunbara6a87f12013-01-07 20:38:55 +00001============
2Debug Checks
3============
4
5.. contents::
6 :local:
7
8The analyzer contains a number of checkers which can aid in debugging. Enable
9them by using the "-analyzer-checker=" flag, followed by the name of the
10checker.
11
12General Analysis Dumpers
13========================
14
15These checkers are used to dump the results of various infrastructural analyses
16to stderr. Some checkers also have "view" variants, which will display a graph
17using a 'dot' format viewer (such as Graphviz on OS X) instead.
18
19- debug.DumpCallGraph, debug.ViewCallGraph: Show the call graph generated for
20 the current translation unit. This is used to determine the order in which to
21 analyze functions when inlining is enabled.
22
23- debug.DumpCFG, debug.ViewCFG: Show the CFG generated for each top-level
24 function being analyzed.
25
26- debug.DumpDominators: Shows the dominance tree for the CFG of each top-level
27 function.
28
29- debug.DumpLiveVars: Show the results of live variable analysis for each
30 top-level function being analyzed.
31
32
33Path Tracking
34=============
35
36These checkers print information about the path taken by the analyzer engine.
37
38- debug.DumpCalls: Prints out every function or method call encountered during a
39 path traversal. This is indented to show the call stack, but does NOT do any
40 special handling of branches, meaning different paths could end up
41 interleaved.
42
43- debug.DumpTraversal: Prints the name of each branch statement encountered
44 during a path traversal ("IfStmt", "WhileStmt", etc). Currently used to check
45 whether the analysis engine is doing BFS or DFS.
46
47
48State Checking
49==============
50
51These checkers will print out information about the analyzer state in the form
52of analysis warnings. They are intended for use with the -verify functionality
53in regression tests.
54
55- debug.TaintTest: Prints out the word "tainted" for every expression that
56 carries taint. At the time of this writing, taint was only introduced by the
57 checks under experimental.security.taint.TaintPropagation; this checker may
58 eventually move to the security.taint package.
59
60- debug.ExprInspection: Responds to certain function calls, which are modeled
61 after builtins. These function calls should affect the program state other
62 than the evaluation of their arguments; to use them, you will need to declare
63 them within your test file. The available functions are described below.
64
65(FIXME: debug.ExprInspection should probably be renamed, since it no longer only
66inspects expressions.)
67
68
69ExprInspection checks
70---------------------
71
72- void clang_analyzer_eval(bool);
73
74 Prints TRUE if the argument is known to have a non-zero value, FALSE if the
75 argument is known to have a zero or null value, and UNKNOWN if the argument
76 isn't sufficiently constrained on this path. You can use this to test other
77 values by using expressions like "x == 5". Note that this functionality is
78 currently DISABLED in inlined functions, since different calls to the same
79 inlined function could provide different information, making it difficult to
80 write proper -verify directives.
81
82 In C, the argument can be typed as 'int' or as '_Bool'.
83
84 Example usage::
85
86 clang_analyzer_eval(x); // expected-warning{{UNKNOWN}}
87 if (!x) return;
88 clang_analyzer_eval(x); // expected-warning{{TRUE}}
89
90
91- void clang_analyzer_checkInlined(bool);
92
93 If a call occurs within an inlined function, prints TRUE or FALSE according to
94 the value of its argument. If a call occurs outside an inlined function,
95 nothing is printed.
96
97 The intended use of this checker is to assert that a function is inlined at
98 least once (by passing 'true' and expecting a warning), or to assert that a
99 function is never inlined (by passing 'false' and expecting no warning). The
100 argument is technically unnecessary but is intended to clarify intent.
101
102 You might wonder why we can't print TRUE if a function is ever inlined and
103 FALSE if it is not. The problem is that any inlined function could conceivably
104 also be analyzed as a top-level function (in which case both TRUE and FALSE
105 would be printed), depending on the value of the -analyzer-inlining option.
106
107 In C, the argument can be typed as 'int' or as '_Bool'.
108
109 Example usage::
110
111 int inlined() {
112 clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
113 return 42;
114 }
115
116 void topLevel() {
117 clang_analyzer_checkInlined(false); // no-warning (not inlined)
118 int value = inlined();
119 // This assertion will not be valid if the previous call was not inlined.
120 clang_analyzer_eval(value == 42); // expected-warning{{TRUE}}
121 }
122
123
124Statistics
125==========
126
127The debug.Stats checker collects various information about the analysis of each
128function, such as how many blocks were reached and if the analyzer timed out.
129
130There is also an additional -analyzer-stats flag, which enables various
131statistics within the analyzer engine. Note the Stats checker (which produces at
132least one bug report per function) may actually change the values reported by
133-analyzer-stats.