ROSE  0.11.50.0
BasicTypes.h
1 #ifndef ROSE_BinaryAnalysis_Concolic_BasicTypes_H
2 #define ROSE_BinaryAnalysis_Concolic_BasicTypes_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_CONCOLIC_TESTING
5 
6 #include <rose_strtoull.h>
7 #include <memory>
8 
9 namespace Rose {
10 namespace BinaryAnalysis {
11 namespace Concolic {
12 
14 // Flags and enums
16 
17 enum class Update { NO, YES };
18 
19 enum class ShowEvents { NO, YES };
20 
21 enum class ShowAssertions { NO, YES };
22 
24 enum class InputType {
25  NONE,
26  PROGRAM_ARGUMENT_COUNT,
27  PROGRAM_ARGUMENT,
28  ENVIRONMENT,
29  SYSTEM_CALL_RETVAL,
30  SHARED_MEMORY_READ
31 };
32 
34 enum class IoDirection {
35  READ,
36  WRITE
37 };
38 
42 enum class When {
43  PRE,
44  POST
45 };
46 
48 enum class ConcolicPhase {
49  REPLAY,
50  EMULATION,
51  POST_EMULATION
52 };
53 
55 // Exceptions, errors, etc.
57 
60 
61 // Internal: called by Rose::Diagnostics::initialize
62 void initDiagnostics();
63 
65 class Exception: public Rose::Exception {
66 public:
67  explicit Exception(const std::string &mesg): Rose::Exception(mesg) {}
68  ~Exception() throw () {}
69 };
70 
72 // Forward references
74 
75 class Architecture;
76 using ArchitecturePtr = Sawyer::SharedPointer<Architecture>;
77 
78 class ConcolicExecutor;
79 using ConcolicExecutorPtr = Sawyer::SharedPointer<ConcolicExecutor>;
80 
81 class ConcreteExecutor;
82 using ConcreteExecutorPtr = Sawyer::SharedPointer<ConcreteExecutor>;
83 class ConcreteExecutorResult;
84 
85 class Database;
86 using DatabasePtr = Sawyer::SharedPointer<Database>;
87 
88 namespace Emulation {
89  class RiscOperators;
90  using RiscOperatorsPtr = boost::shared_ptr<class RiscOperators>;
91 }
92 
93 class ExecutionEvent;
94 using ExecutionEventPtr = Sawyer::SharedPointer<ExecutionEvent>;
95 
96 class ExecutionLocation;
97 
98 class ExecutionManager;
99 using ExecutionManagerPtr = Sawyer::SharedPointer<ExecutionManager>;
100 
101 class InputVariables;
102 
103 class LinuxExecutor;
104 using LinuxExecutorPtr = Sawyer::SharedPointer<LinuxExecutor>;
105 
106 class LinuxI386;
107 using LinuxI386Ptr = Sawyer::SharedPointer<LinuxI386>;
108 
109 class SharedMemoryCallback;
110 using SharedMemoryCallbackPtr = Sawyer::SharedPointer<SharedMemoryCallback>;
111 
112 using SharedMemoryCallbacks = Sawyer::Callbacks<SharedMemoryCallbackPtr>;
113 
114 class SharedMemoryContext;
115 
116 class Specimen;
117 using SpecimenPtr = Sawyer::SharedPointer<Specimen>;
118 
119 class SyscallCallback;
120 using SyscallCallbackPtr = std::shared_ptr<SyscallCallback>;
121 
122 using SyscallCallbacks = Sawyer::Callbacks<SyscallCallbackPtr>;
123 
124 class SyscallContext;
125 
126 class TestCase;
127 using TestCasePtr = Sawyer::SharedPointer<TestCase>;
128 
129 class TestSuite;
130 using TestSuitePtr = Sawyer::SharedPointer<TestSuite>;
131 
132 class LinuxExitStatus;
133 using LinuxExitStatusPtr = Sawyer::SharedPointer<LinuxExitStatus>;
134 
136 // Database
138 
140 template <class Tag>
141 class ObjectId: public Sawyer::Optional<size_t> {
142 public:
143  using Value = size_t;
144  using Super = Sawyer::Optional<Value>;
145  using Object = Tag;
146  using Pointer = Sawyer::SharedPointer<Tag>;
148  ObjectId() {}
149 
150  explicit
151  ObjectId(const Value& v)
152  : Super(v) {}
153 
154  ObjectId(const ObjectId& rhs)
155  : Super(rhs) {}
156 
157  explicit ObjectId(const Sawyer::Optional<size_t> &id)
158  : Super(id) {}
159 
165  explicit ObjectId(const std::string &s) {
166  char *rest = NULL;
167  uint64_t id = rose_strtoull(s.c_str(), &rest, 0);
168  while (*rest && isspace(*rest)) ++rest;
169  if (*rest)
170  throw Exception("invalid syntax for object ID: \"" + StringUtility::cEscape(s) + "\"");
171  try {
172  *this = boost::numeric_cast<Value>(id);
173  } catch (const boost::bad_numeric_cast&) {
174  throw Exception("parsed object ID out of range: \"" + StringUtility::cEscape(s) + "\"");
175  }
176  }
177 
179  ObjectId<Tag>& operator=(const ObjectId<Tag>& lhs) {
180  this->Super::operator=(lhs);
181  return *this;
182  }
183 
185  ObjectId<Tag>& operator=(const Value& v) {
186  this->Super::operator=(v);
187  return *this;
188  }
189 
190  explicit operator bool() const { // because it's not explicit in the super class due to C++03 support
191  return isEqual(Sawyer::Nothing()) ? false : true;
192  }
193 
195  template<class _Tag>
196  friend
197  bool operator<(const ObjectId<_Tag>& lhs, const ObjectId<_Tag>& rhs);
198 
199  // Useful for database operations
200  const Super& optional() const {
201  return *this;
202  }
203 };
204 
206 template<class Tag>
207 inline
208 bool operator<(const ObjectId<Tag>& lhs, const ObjectId<Tag>& rhs)
209 {
210  if (!rhs) return false;
211  if (!lhs) return true;
212 
213  return lhs.get() < rhs.get();
214 }
215 
216 using TestSuiteId = ObjectId<TestSuite>;
217 using SpecimenId = ObjectId<Specimen>;
218 using TestCaseId = ObjectId<TestCase>;
219 using ExecutionEventId = ObjectId<ExecutionEvent>;
224 template<class T>
225 struct ObjectTraits {
226  using Id = void;
227 };
228 
229 template<>
230 struct ObjectTraits<TestSuite> {
231  using Id = TestSuiteId;
232 };
233 
234 template<>
235 struct ObjectTraits<Specimen> {
236  using Id = SpecimenId;
237 };
238 
239 template<>
240 struct ObjectTraits<TestCase> {
241  using Id = TestCaseId;
242 };
243 
244 template<>
245 struct ObjectTraits<ExecutionEvent> {
246  using Id = ExecutionEventId;
247 };
248 
249 } // namespace
250 } // namespace
251 } // namespace
252 
253 #endif
254 #endif
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to concrete RISC operations.
Collection of streams.
Definition: Message.h:1606
Only query an allocation.
Definition: CodeInserter.h:15
ROSE_DLL_API Sawyer::Message::Facility mlog
Diagnostic facility for the ROSE library as a whole.
Holds a value or nothing.
Definition: Optional.h:49
Main namespace for the ROSE library.
ROSE_UTIL_API std::string cEscape(const std::string &, char context= '"')
Escapes characters that are special to C/C++.
Reference-counting intrusive smart pointer.
Definition: SharedPointer.h:68
Allocate memory for real.
Definition: CodeInserter.h:16
size_t Id
Attribute identification.
Definition: Attribute.h:140
void initDiagnostics()
Initialize diagnostics.
const char * When(int64_t)
Convert Sawyer::Message::Prefix::When enum constant to a string.
Definition: stringify.C:48097
const char * Architecture(int64_t)
Convert Rose::BinaryAnalysis::DisassemblerMips::Mips32::Architecture enum constant to a string...
Definition: stringify.C:40051
Represents no value.
Definition: Optional.h:32
Base class for all ROSE exceptions.
Definition: Rose/Exception.h:9