1/// @page overview High level overview of KLEE.
2/// This document contains a high level overview of the inner workings of KLEE.
4/// KLEE implements symbolic execution by interpreting LLVM bitcode. Symbolic
5/// memory is defined by inserting special calls to KLEE (namely
7/// During execution, KLEE tracks all uses of symbolic memory. Constraints
8/// on symbolic memory usage are collected. Memory
9/// that is defined using previously declared symbolic memory become
11/// Whenever a branch refering to symbolic memory is encountered, KLEE forks
12/// the entire states and explores each side of the branch for which a possible
13/// solution to the symbolic constraints can be found.
14/// KLEE makes queries to STP to solve symbolic constraints.
16/// The rest of this document describes some of the important components of KLEE
18/// @section executor Interpreter
19/// klee::Interpreter is the main abstract class defining the interface of the
20/// bitcode interpreter. klee::Executor is the main concrete instance of this
22/// Application states (i.e. memory, registers and PC) are stored in instances of
23/// class klee::ExecutionState. There is one such instance for each path beeing
24/// executed (except when some states are merged together).
25/// On a branch, if condition is symbolic, klee::Executor::fork returns a
26/// klee::ExecutionState::StatePair which is a pair of ExecutionState to be
29/// @section memory Memory model
30/// MemoryObject's represent allocation sites in the program (calls to malloc, stack
31/// objects, global variables)
32/// and, at least conceptually, can be thought of as the unique name for the object
33/// allocated at that site.
34/// ObjectState's are used to store the actual contents of a MemoryObject in a
35/// particular ExecutionState (but
36/// can be shared). I need better names for these two things.
38/// Each ExecutionState stores a mapping of MemoryObjects -> ObjectState using the
40/// structure (implemented as an immutable tree so that copying is cheap and the
41/// shared structure is exploited).
42/// Each AddressSpace may "own" some subset of the ObjectStates in the mapping. When
44/// is duplicated it loses ownership of the ObjectState in the map. Any subsequent
45/// write to an ObjectState will
46/// create a copy of the object (AddressSpace::getWriteable). This is the COW
47/// mechanism (which gets used
48/// for all objects, not just globals).
50/// From the point of view of the state and this mapping there is no distinction
51/// between stack, heap, and global
52/// objects. The only special handling for stack objects is that the MemoryObject is
53/// marked as isLocal and the
54/// MemoryObject is stored in the StackFrame alloca list. When the StackFrame is
55/// popped these objects are
56/// then unbound so that the state can no longer access the memory directly
57/// (references to the memory object
58/// may still remain in ReadExprs, but conceptually the actual memory is no longer
61/// It is also important that the AddressSpace mapping is ordered. We use this when
62/// we need to resolve a symbolic
63/// address to an ObjectState by first getting a particular value for the symbolic
64/// address, and using that value to start
65/// looking for objects that the pointer can fall within.
66/// Difference betweens MemoryObjects and ObjectStates ?
68/// @section expression Expressions
69/// The various Expr classes mostly model the llvm instruction set. ref<Expr> is
70/// used to maintain the reference count
71/// but also embeds any constant expressions. In fact in the current code base
72/// ConstantExprs should almost never be
73/// created. Most of the Expr's are straightforward. Some of the most important ones
74/// are Concat?Expr, which join
75/// some number of bytes into a larger type, ExtractExpr which extracts smaller
76/// types from larger ones, and ReadExpr
77/// which is a symbolic array access.
79/// The way memory is implemented all accesses are broken down into byte level
80/// operations. This means that the
81/// memory system (by which I mean the ObjectState data structure) tends to use a
82/// lot of ExtractExpr and Concat?Expr,
83/// so it is very important that these expressions fold their operands when
86/// The ReadExpr is probably the most important one. Conceptually it is simply an
87/// index and a list of (index, value)
88/// updates (writes). The ReadExpr evaluates to all the values for which the two
89/// indices can be equal. The ObjectState
90/// structure uses a cache for concrete writes and for symbolic writes at concrete
91/// indices, but for writes at symbolic
92/// indices it must construct a list of such updates. These are stored in the
93/// UpdateList and UpdateNode structures
94/// which are again immutable data structures so that copy is cheap and the sharing
97/// @section searcher Searcher
98/// Base classe: klee::Searcher. The Executor uses a Searcher to select the next
99/// state (i.e. program instance following a single path) for which an
101/// will be executed. There are multiple implementations of Searcher in klee,
102/// implementing different search policies. klee::RandomSearcher selects the next state randomly.
103/// klee::DFSSearcher uses a depth first approach. klee::MergingSearcher tries