klee
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SpecialFunctionHandler.h
Go to the documentation of this file.
1 //===-- SpecialFunctionHandler.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_SPECIALFUNCTIONHANDLER_H
11 #define KLEE_SPECIALFUNCTIONHANDLER_H
12 
13 #include <iterator>
14 #include <map>
15 #include <vector>
16 #include <string>
17 
18 namespace llvm {
19  class Function;
20 }
21 
22 namespace klee {
23  class Executor;
24  class Expr;
25  class ExecutionState;
26  struct KInstruction;
27  template<typename T> class ref;
28 
30  public:
32  KInstruction *target,
33  std::vector<ref<Expr> >
34  &arguments);
35  typedef std::map<const llvm::Function*,
36  std::pair<Handler,bool> > handlers_ty;
37 
40 
41  struct HandlerInfo {
42  const char *name;
47  };
48 
49  // const_iterator to iterate over stored HandlerInfo
50  // FIXME: Implement >, >=, <=, < operators
51  class const_iterator : public std::iterator<std::random_access_iterator_tag, HandlerInfo>
52  {
53  private:
54  value_type* base;
55  int index;
56  public:
57  const_iterator(value_type* hi) : base(hi), index(0) {};
58  const_iterator& operator++(); // pre-fix
59  const_iterator operator++(int); // post-fix
60  const value_type& operator*() { return base[index];}
61  const value_type* operator->() { return &(base[index]);}
62  const value_type& operator[](int i) { return base[i];}
63  bool operator==(const_iterator& rhs) { return (rhs.base + rhs.index) == (this->base + this->index);}
64  bool operator!=(const_iterator& rhs) { return !(*this == rhs);}
65  };
66 
67  static const_iterator begin();
68  static const_iterator end();
69  static int size();
70 
71 
72 
73  public:
74  SpecialFunctionHandler(Executor &_executor);
75 
80  void prepare();
81 
84  void bind();
85 
86  bool handle(ExecutionState &state,
87  llvm::Function *f,
88  KInstruction *target,
89  std::vector< ref<Expr> > &arguments);
90 
91  /* Convenience routines */
92 
93  std::string readStringAtAddress(ExecutionState &state, ref<Expr> address);
94 
95  /* Handlers */
96 
97 #define HANDLER(name) void name(ExecutionState &state, \
98  KInstruction *target, \
99  std::vector< ref<Expr> > &arguments)
100  HANDLER(handleAbort);
101  HANDLER(handleAssert);
102  HANDLER(handleAssertFail);
103  HANDLER(handleAssume);
104  HANDLER(handleCalloc);
105  HANDLER(handleCheckMemoryAccess);
106  HANDLER(handleDefineFixedObject);
107  HANDLER(handleDelete);
108  HANDLER(handleDeleteArray);
109  HANDLER(handleExit);
110  HANDLER(handleAliasFunction);
111  HANDLER(handleFree);
112  HANDLER(handleGetErrno);
113  HANDLER(handleGetObjSize);
114  HANDLER(handleGetValue);
115  HANDLER(handleIsSymbolic);
116  HANDLER(handleMakeSymbolic);
117  HANDLER(handleMalloc);
118  HANDLER(handleMarkGlobal);
119  HANDLER(handleMerge);
120  HANDLER(handleNew);
121  HANDLER(handleNewArray);
122  HANDLER(handlePreferCex);
123  HANDLER(handlePrintExpr);
124  HANDLER(handlePrintRange);
125  HANDLER(handleRange);
126  HANDLER(handleRealloc);
127  HANDLER(handleReportError);
128  HANDLER(handleRevirtObjects);
129  HANDLER(handleSetForking);
130  HANDLER(handleSilentExit);
131  HANDLER(handleStackTrace);
132  HANDLER(handleUnderConstrained);
133  HANDLER(handleWarning);
134  HANDLER(handleWarningOnce);
135 #undef HANDLER
136  };
137 } // End klee namespace
138 
139 #endif
SpecialFunctionHandler(Executor &_executor)
#define Expr
Definition: STPBuilder.h:19
bool hasReturnValue
Intrinsic terminates the process.
void(SpecialFunctionHandler::* Handler)(ExecutionState &state, KInstruction *target, std::vector< ref< Expr > > &arguments)
std::map< const llvm::Function *, std::pair< Handler, bool > > handlers_ty
std::string readStringAtAddress(ExecutionState &state, ref< Expr > address)
bool handle(ExecutionState &state, llvm::Function *f, KInstruction *target, std::vector< ref< Expr > > &arguments)
bool doNotOverride
Intrinsic has a return value.