klee
ExecutionState.h
Go to the documentation of this file.
1//===-- ExecutionState.h ----------------------------------------*- C++ -*-===//
2//
3// The KLEE Symbolic Virtual Machine
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef KLEE_EXECUTIONSTATE_H
11#define KLEE_EXECUTIONSTATE_H
12
13#include "AddressSpace.h"
14#include "MergeHandler.h"
15
17#include "klee/ADT/TreeStream.h"
19#include "klee/Expr/Expr.h"
21#include "klee/Solver/Solver.h"
22#include "klee/System/Time.h"
23
24#include <map>
25#include <memory>
26#include <set>
27#include <vector>
28
29namespace klee {
30class Array;
31class CallPathNode;
32struct Cell;
33struct KFunction;
34struct KInstruction;
35class MemoryObject;
36class PTreeNode;
37struct InstructionInfo;
38
39llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const MemoryMap &mm);
40
41struct StackFrame {
45
46 std::vector<const MemoryObject *> allocas;
48
55
56 // For vararg functions: arguments not passed via parameter are
57 // stored (packed tightly) in a local (alloca) memory object. This
58 // is set up to match the way the front-end generates vaarg code (it
59 // does not pass vaarg through as expected). VACopy is lowered inside
60 // of intrinsic lowering.
62
64 StackFrame(const StackFrame &s);
66};
67
70public:
71 enum class Kind {
72 SearchPhase, // first phase
73 CleanupPhase // second phase
74 };
75
76private:
77 const Kind kind;
78
79public:
80 // _Unwind_Exception* of the thrown exception, used in both phases
82
83 Kind getKind() const { return kind; }
84
87 virtual ~UnwindingInformation() = default;
88
89 virtual std::unique_ptr<UnwindingInformation> clone() const = 0;
90};
91
93 // Keeps track of the stack index we have so far unwound to.
94 std::size_t unwindingProgress;
95
96 // MemoryObject that contains a serialized version of the last executed
97 // landingpad, so we can clean it up after the personality fn returns.
99
101 std::size_t const unwindingProgress)
103 UnwindingInformation::Kind::SearchPhase),
105
106 std::unique_ptr<UnwindingInformation> clone() const {
107 return std::make_unique<SearchPhaseUnwindingInformation>(*this);
108 }
109
110 static bool classof(const UnwindingInformation *u) {
112 }
113};
114
116 // Phase 1 will try to find a catching landingpad.
117 // Phase 2 will unwind up to this landingpad or return from
118 // _Unwind_RaiseException if none was found.
119
120 // The selector value of the catching landingpad that was found
121 // during the search phase.
123
124 // Used to know when we have to stop unwinding and to
125 // ensure that unwinding stops at the frame for which
126 // we first found a handler in the search phase.
127 const std::size_t catchingStackIndex;
128
131 const std::size_t catchingStackIndex)
133 UnwindingInformation::Kind::CleanupPhase),
136
137 std::unique_ptr<UnwindingInformation> clone() const {
138 return std::make_unique<CleanupPhaseUnwindingInformation>(*this);
139 }
140
141 static bool classof(const UnwindingInformation *u) {
143 }
144};
145
148#ifdef KLEE_UNITTEST
149public:
150#else
151private:
152#endif
153 // copy ctor
154 ExecutionState(const ExecutionState &state);
155
156public:
157 using stack_ty = std::vector<StackFrame>;
158
159 // Execution - Control Flow specific
160
164
167
170
173 std::uint32_t incomingBBIndex;
174
175 // Overall state of the state - Data specific
176
178 std::uint32_t depth = 0;
179
182
185
187
190
194
198
200 std::map<const std::string *, std::set<std::uint32_t>> coveredLines;
201
205
207 //
208 // FIXME: Move to a shared list structure (not critical).
209 std::vector<std::pair<ref<const MemoryObject>, const Array *>> symbolics;
210
214
216 std::set<std::string> arrayNames;
217
219 std::vector<ref<MergeHandler>> openMergeStack;
220
222 std::uint64_t steppedInstructions = 0;
223
226 std::uint32_t instsSinceCovNew = 0;
227
229 std::unique_ptr<UnwindingInformation> unwindingInformation;
230
232 static std::uint32_t nextID;
233
235 std::uint32_t id = 0;
236
238 bool coveredNew = false;
239
241 bool forkDisabled = false;
242
243public:
244#ifdef KLEE_UNITTEST
245 // provide this function only in the context of unittests
246 ExecutionState() = default;
247#endif
248 // only to create the initial state
249 explicit ExecutionState(KFunction *kf);
250 // no copy assignment, use copy constructor
252 // no move ctor
253 ExecutionState(ExecutionState &&) noexcept = delete;
254 // no move assignment
255 ExecutionState& operator=(ExecutionState &&) noexcept = delete;
256 // dtor
258
260
261 void pushFrame(KInstIterator caller, KFunction *kf);
262 void popFrame();
263
264 void addSymbolic(const MemoryObject *mo, const Array *array);
265
266 void addConstraint(ref<Expr> e);
267 void addCexPreference(const ref<Expr> &cond);
268
269 bool merge(const ExecutionState &b);
270 void dumpStack(llvm::raw_ostream &out) const;
271
272 std::uint32_t getID() const { return id; };
273 void setID() { id = nextID++; };
274};
275
277 bool operator()(const ExecutionState *a, const ExecutionState *b) const {
278 return a->getID() < b->getID();
279 }
280};
281}
282
283#endif /* KLEE_EXECUTIONSTATE_H */
Implementation of the region based merging.
ExecutionState representing a path under exploration.
stack_ty stack
Stack representing the current instruction stream.
void addConstraint(ref< Expr > e)
void pushFrame(KInstIterator caller, KFunction *kf)
std::map< const std::string *, std::set< std::uint32_t > > coveredLines
Set containing which lines in which files are covered by this state.
void addSymbolic(const MemoryObject *mo, const Array *array)
static std::uint32_t nextID
the global state counter
PTreeNode * ptreeNode
Pointer to the process tree of the current state Copies of ExecutionState should not copy ptreeNode.
std::set< std::string > arrayNames
Set of used array names for this state. Used to avoid collisions.
std::uint32_t incomingBBIndex
Remember from which Basic Block control flow arrived (i.e. to select the right phi values)
ExecutionState(ExecutionState &&) noexcept=delete
std::uint32_t getID() const
std::unique_ptr< UnwindingInformation > unwindingInformation
Keep track of unwinding state while unwinding, otherwise empty.
bool forkDisabled
Disables forking for this state. Set by user code.
SolverQueryMetaData queryMetaData
Statistics and information.
ConstraintSet constraints
Constraints collected so far.
std::vector< ref< MergeHandler > > openMergeStack
The objects handling the klee_open_merge calls this state ran through.
TreeOStream pathOS
History of complete path: represents branches taken to reach/create this state (both concrete and sym...
bool merge(const ExecutionState &b)
std::vector< StackFrame > stack_ty
std::uint32_t id
the state id
AddressSpace addressSpace
Address space used by this state (e.g. Global and Heap)
std::vector< std::pair< ref< const MemoryObject >, const Array * > > symbolics
Ordered list of symbolics: used to generate test cases.
void dumpStack(llvm::raw_ostream &out) const
void addCexPreference(const ref< Expr > &cond)
TreeOStream symPathOS
History of symbolic path: represents symbolic branches taken to reach/create this state.
ExecutionState(const ExecutionState &state)
KInstIterator prevPC
Pointer to instruction which is currently executed.
bool coveredNew
Whether a new instruction was covered in this state.
std::uint64_t steppedInstructions
The numbers of times this state has run through Executor::stepInstruction.
std::uint32_t depth
Exploration depth, i.e., number of times KLEE branched for this state.
ExecutionState * branch()
ImmutableSet< ref< Expr > > cexPreferences
A set of boolean expressions the user has requested be true of a counterexample.
std::uint32_t instsSinceCovNew
Counts how many instructions were executed since the last new instruction was covered.
KInstIterator pc
Pointer to instruction to be executed after the current instruction.
ExecutionState & operator=(const ExecutionState &)=delete
Class representing symbolic expressions.
Definition: Expr.h:91
Contains information related to unwinding (Itanium ABI/2-Phase unwinding)
ref< ConstantExpr > exceptionObject
UnwindingInformation(ref< ConstantExpr > exceptionObject, Kind k)
virtual std::unique_ptr< UnwindingInformation > clone() const =0
virtual ~UnwindingInformation()=default
Definition: Ref.h:82
Definition: main.cpp:291
llvm::raw_ostream & operator<<(llvm::raw_ostream &os, const MemoryMap &mm)
ImmutableMap< const MemoryObject *, ref< ObjectState >, MemoryObjectLT > MemoryMap
Definition: AddressSpace.h:36
static bool classof(const UnwindingInformation *u)
std::unique_ptr< UnwindingInformation > clone() const
CleanupPhaseUnwindingInformation(ref< ConstantExpr > exceptionObject, ref< ConstantExpr > selectorValue, const std::size_t catchingStackIndex)
bool operator()(const ExecutionState *a, const ExecutionState *b) const
static bool classof(const UnwindingInformation *u)
std::unique_ptr< UnwindingInformation > clone() const
SearchPhaseUnwindingInformation(ref< ConstantExpr > exceptionObject, std::size_t const unwindingProgress)
std::vector< const MemoryObject * > allocas
StackFrame(KInstIterator caller, KFunction *kf)
unsigned minDistToUncoveredOnReturn
KFunction * kf
MemoryObject * varargs
KInstIterator caller
CallPathNode * callPathNode