15#ifndef KLEE_EXECUTOR_H
16#define KLEE_EXECUTOR_H
32#include "llvm/ADT/Twine.h"
33#include "llvm/Support/raw_ostream.h"
39#include <unordered_map>
64 class ExternalDispatcher;
66 class InstructionInfoTable;
77 class SpecialFunctionHandler;
81 class TreeStreamWriter;
83 class MergingSearcher;
84 template<
class T>
class ref;
101 typedef std::pair<ExecutionState*,ExecutionState*>
StatePair;
114 std::set<ExecutionState*, ExecutionStateIDCompare>
states;
139 std::map<ExecutionState*, std::vector<SeedInfo> >
seedMap;
224 unsigned size,
bool isReadOnly);
228 const llvm::Constant *c,
238 llvm::BasicBlock *src,
243 llvm::Function *function,
247 bool isLocal,
const Array *array = 0);
257 typedef std::vector< std::pair<std::pair<const MemoryObject*, const ObjectState*>,
262 const std::string &name);
287 bool zeroMemory=
false,
289 size_t allocationAlignment=0);
303 const llvm::LandingPadInst &lpi,
304 bool &stateTerminated);
324 const std::string &name);
331 std::vector<ExecutionState *> &result,
BranchType reason);
364 return state.
stack.back().locals[target->
dest];
399 const char *purpose);
411 llvm::Instruction** lastInstruction);
429 const llvm::Twine &longMessage =
"",
430 const char *
suffix =
nullptr);
437 const llvm::Twine &info =
"");
452 template <
typename SqType,
typename TypeIt>
457 template <
typename TypeIt>
483 Executor(llvm::LLVMContext &ctx,
const InterpreterOptions &opts,
498 assert(!
replayPath &&
"cannot replay both buffer and path");
504 assert(!
replayKTest &&
"cannot replay both buffer and path");
509 llvm::Module *
setModule(std::vector<std::unique_ptr<llvm::Module>> &modules,
510 const ModuleOptions &opts)
override;
512 void useSeeds(
const std::vector<struct KTest *> *seeds)
override {
517 char **envp)
override;
539 std::vector<std::pair<std::string, std::vector<unsigned char>>> &res)
543 std::map<
const std::string *, std::set<unsigned>> &res)
BranchType
Reason an ExecutionState forked.
StateTerminationType
Reason an ExecutionState got terminated.
Provides an interface for creating and destroying Array objects.
ExecutionState representing a path under exploration.
stack_ty stack
Stack representing the current instruction stream.
std::unique_ptr< llvm::raw_ostream > debugInstFile
File to print executed instructions to.
void callExternalFunction(ExecutionState &state, KInstruction *target, llvm::Function *function, std::vector< ref< Expr > > &arguments)
void terminateStateOnExit(ExecutionState &state)
void addConstraint(ExecutionState &state, ref< Expr > condition)
ArrayCache arrayCache
Assumes ownership of the created array objects.
Cell & getArgumentCell(ExecutionState &state, KFunction *kf, unsigned index)
const InstructionInfo & getLastNonKleeInternalInstruction(const ExecutionState &state, llvm::Instruction **lastInstruction)
TreeStreamWriter * symPathWriter
std::string getAddressInfo(ExecutionState &state, ref< Expr > address) const
Get textual information regarding a memory address.
ObjectState * bindObjectInState(ExecutionState &state, const MemoryObject *mo, bool isLocal, const Array *array=0)
void initializeGlobalAlias(const llvm::Constant *c)
std::map< ExecutionState *, std::vector< SeedInfo > > seedMap
std::map< const llvm::GlobalValue *, ref< ConstantExpr > > globalAddresses
ref< klee::ConstantExpr > toConstant(ExecutionState &state, ref< Expr > e, const char *purpose)
ref< ConstantExpr > getEhTypeidFor(ref< Expr > type_info)
Return the typeid corresponding to a certain type_info
const InterpreterHandler & getHandler()
void printDebugInstructions(ExecutionState &state)
void branch(ExecutionState &state, const std::vector< ref< Expr > > &conditions, std::vector< ExecutionState * > &result, BranchType reason)
void bindArgument(KFunction *kf, unsigned index, ExecutionState &state, ref< Expr > value)
llvm::Function * getTargetFunction(llvm::Value *calledVal, ExecutionState &state)
std::vector< std::pair< std::pair< const MemoryObject *, const ObjectState * >, ExecutionState * > > ExactResolutionList
StatePair fork(ExecutionState ¤t, ref< Expr > condition, bool isInternal, BranchType reason)
size_t getAllocationAlignment(const llvm::Value *allocSite) const
std::unique_ptr< PTree > processTree
void initializeGlobalAliases()
RNG theRNG
The random number generator.
const struct KTest * replayKTest
TreeStreamWriter * pathWriter
ref< Expr > toUnique(const ExecutionState &state, ref< Expr > &e)
std::vector< ExecutionState * > addedStates
void terminateState(ExecutionState &state)
Remove state from queue and delete state.
void computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie)
std::unordered_map< std::uint64_t, llvm::Function * > legalFunctions
void computeOffsetsSeqTy(KGEPInstruction *kgepi, ref< ConstantExpr > &constantOffset, uint64_t index, const TypeIt it)
bool inhibitForking
Disables forking, set by client.
void runFunctionAsMain(llvm::Function *f, int argc, char **argv, char **envp) override
llvm::raw_string_ostream debugLogBuffer
std::vector< ref< Expr > > eh_typeids
Typeids used during exception handling.
void executeAlloc(ExecutionState &state, ref< Expr > size, bool isLocal, KInstruction *target, bool zeroMemory=false, const ObjectState *reallocFrom=0, size_t allocationAlignment=0)
void executeInstruction(ExecutionState &state, KInstruction *ki)
void setReplayKTest(const struct KTest *out) override
void executeMemoryOperation(ExecutionState &state, bool isWrite, ref< Expr > address, ref< Expr > value, KInstruction *target)
void initializeGlobals(ExecutionState &state)
std::set< ExecutionState *, ExecutionStateIDCompare > states
ref< Expr > maxStaticPctChecks(ExecutionState ¤t, ref< Expr > condition)
Expr::Width getWidthForLLVMType(llvm::Type *type) const
void setReplayPath(const std::vector< bool > *path) override
Cell & getDestCell(ExecutionState &state, KInstruction *target)
ref< klee::ConstantExpr > evalConstantExpr(const llvm::ConstantExpr *c, const KInstruction *ki=NULL)
void bindLocal(KInstruction *target, ExecutionState &state, ref< Expr > value)
void setInhibitForking(bool value) override
Executor(llvm::LLVMContext &ctx, const InterpreterOptions &opts, InterpreterHandler *ie)
void doImpliedValueConcretization(ExecutionState &state, ref< Expr > e, ref< ConstantExpr > value)
void getConstraintLog(const ExecutionState &state, std::string &res, Interpreter::LogType logFormat=Interpreter::STP) override
time::Span maxInstructionTime
Maximum time to allow for a single instruction.
void terminateStateEarly(ExecutionState &state, const llvm::Twine &message, StateTerminationType terminationType)
time::Span coreSolverTimeout
void setMergingSearcher(MergingSearcher *ms)
void bindInstructionConstants(KInstruction *KI)
MemoryObject * serializeLandingpad(ExecutionState &state, const llvm::LandingPadInst &lpi, bool &stateTerminated)
std::map< const llvm::GlobalValue *, MemoryObject * > globalObjects
Map of globals to their representative memory object.
void getCoveredLines(const ExecutionState &state, std::map< const std::string *, std::set< unsigned > > &res) override
void bindModuleConstants()
bindModuleConstants - Initialize the module constant table.
std::pair< ExecutionState *, ExecutionState * > StatePair
ref< Expr > replaceReadWithSymbolic(ExecutionState &state, ref< Expr > e)
MergingSearcher * getMergingSearcher() const
const Cell & eval(KInstruction *ki, unsigned index, ExecutionState &state) const
void terminateStateOnExecError(ExecutionState &state, const llvm::Twine &message, const llvm::Twine &info="")
void allocateGlobalObjects(ExecutionState &state)
void useSeeds(const std::vector< struct KTest * > *seeds) override
void stepInstruction(ExecutionState &state)
std::string debugBufferString
SpecialFunctionHandler * specialFunctionHandler
llvm::Module * setModule(std::vector< std::unique_ptr< llvm::Module > > &modules, const ModuleOptions &opts) override
bool getSymbolicSolution(const ExecutionState &state, std::vector< std::pair< std::string, std::vector< unsigned char > > > &res) override
void prepareForEarlyExit() override
void executeMakeSymbolic(ExecutionState &state, const MemoryObject *mo, const std::string &name)
void setPathWriter(TreeStreamWriter *tsw) override
void run(ExecutionState &initialState)
InterpreterHandler * interpreterHandler
const std::vector< bool > * replayPath
When non-null a list of branch decisions to be used for replay.
bool branchingPermitted(const ExecutionState &state) const
check if branching/forking is allowed
void terminateStateOnSolverError(ExecutionState &state, const llvm::Twine &message)
void transferToBasicBlock(llvm::BasicBlock *dst, llvm::BasicBlock *src, ExecutionState &state)
std::unique_ptr< KModule > kmodule
unsigned getSymbolicPathStreamID(const ExecutionState &state) override
void terminateStateOnUserError(ExecutionState &state, const llvm::Twine &message)
void resolveExact(ExecutionState &state, ref< Expr > p, ExactResolutionList &results, const std::string &name)
friend class OwningSearcher
MergingSearcher * mergingSearcher
void setHaltExecution(bool value) override
ExternalDispatcher * externalDispatcher
ExprOptimizer optimizer
Optimizes expressions.
void executeGetValue(ExecutionState &state, ref< Expr > e, KInstruction *target)
void unwindToNextLandingpad(ExecutionState &state)
void executeCall(ExecutionState &state, KInstruction *ki, llvm::Function *f, std::vector< ref< Expr > > &arguments)
void executeFree(ExecutionState &state, ref< Expr > address, KInstruction *target=0)
MemoryObject * addExternalObject(ExecutionState &state, void *addr, unsigned size, bool isReadOnly)
StatsTracker * statsTracker
void initializeGlobalObjects(ExecutionState &state)
void initializeGlobalObject(ExecutionState &state, ObjectState *os, const llvm::Constant *c, unsigned offset)
unsigned getPathStreamID(const ExecutionState &state) override
void terminateStateOnError(ExecutionState &state, const llvm::Twine &message, StateTerminationType terminationType, const llvm::Twine &longMessage="", const char *suffix=nullptr)
void updateStates(ExecutionState *current)
std::vector< ExecutionState * > removedStates
ref< klee::ConstantExpr > evalConstant(const llvm::Constant *c, const KInstruction *ki=NULL)
const std::vector< struct KTest * > * usingSeeds
void dumpStates()
Only for debug purposes; enable via debugger or klee-control.
int * getErrnoLocation(const ExecutionState &state) const
Returns the errno location in memory of the state.
void setSymbolicPathWriter(TreeStreamWriter *tsw) override
unsigned Width
The type of an expression is simply its width, in bits.
Represents one klee_open_merge() call. Handles merging of states that branched from it.
int const char const char * suffix
Searcher * constructUserSearcher(Executor &executor)
InstructionInfo stores debug information for a KInstruction.
unsigned getArgRegister(unsigned index)
unsigned dest
Destination register index.