ROSE  0.11.58.0
Concolic/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  ARGC,
27  ARGV,
28  ENVP,
29  SYSCALL_RET,
30  SHMEM_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 using InputVariablesPtr = Sawyer::SharedPointer<InputVariables>;
103 
104 class LinuxExecutor;
105 using LinuxExecutorPtr = Sawyer::SharedPointer<LinuxExecutor>;
106 
107 class LinuxI386;
108 using LinuxI386Ptr = Sawyer::SharedPointer<LinuxI386>;
109 
110 class SharedMemoryCallback;
111 using SharedMemoryCallbackPtr = Sawyer::SharedPointer<SharedMemoryCallback>;
112 
113 using SharedMemoryCallbacks = Sawyer::Callbacks<SharedMemoryCallbackPtr>;
114 
115 class SharedMemoryContext;
116 
117 class Specimen;
118 using SpecimenPtr = Sawyer::SharedPointer<Specimen>;
119 
120 class SyscallCallback;
121 using SyscallCallbackPtr = std::shared_ptr<SyscallCallback>;
122 
123 using SyscallCallbacks = Sawyer::Callbacks<SyscallCallbackPtr>;
124 
125 class SyscallContext;
126 
127 class TestCase;
128 using TestCasePtr = Sawyer::SharedPointer<TestCase>;
129 
130 class TestSuite;
131 using TestSuitePtr = Sawyer::SharedPointer<TestSuite>;
132 
133 class LinuxExitStatus;
134 using LinuxExitStatusPtr = Sawyer::SharedPointer<LinuxExitStatus>;
135 
137 // Database
139 
141 template <class Tag>
142 class ObjectId: public Sawyer::Optional<size_t> {
143 public:
144  using Value = size_t;
145  using Super = Sawyer::Optional<Value>;
146  using Object = Tag;
147  using Pointer = Sawyer::SharedPointer<Tag>;
149  ObjectId() {}
150 
151  explicit
152  ObjectId(const Value& v)
153  : Super(v) {}
154 
155  ObjectId(const ObjectId& rhs)
156  : Super(rhs) {}
157 
158  explicit ObjectId(const Sawyer::Optional<size_t> &id)
159  : Super(id) {}
160 
166  explicit ObjectId(const std::string &s) {
167  char *rest = NULL;
168  uint64_t id = rose_strtoull(s.c_str(), &rest, 0);
169  while (*rest && isspace(*rest)) ++rest;
170  if (*rest)
171  throw Exception("invalid syntax for object ID: \"" + StringUtility::cEscape(s) + "\"");
172  try {
173  *this = boost::numeric_cast<Value>(id);
174  } catch (const boost::bad_numeric_cast&) {
175  throw Exception("parsed object ID out of range: \"" + StringUtility::cEscape(s) + "\"");
176  }
177  }
178 
180  ObjectId<Tag>& operator=(const ObjectId<Tag>& lhs) {
181  this->Super::operator=(lhs);
182  return *this;
183  }
184 
186  ObjectId<Tag>& operator=(const Value& v) {
187  this->Super::operator=(v);
188  return *this;
189  }
190 
191  explicit operator bool() const { // because it's not explicit in the super class due to C++03 support
192  return isEqual(Sawyer::Nothing()) ? false : true;
193  }
194 
196  template<class _Tag>
197  friend
198  bool operator<(const ObjectId<_Tag>& lhs, const ObjectId<_Tag>& rhs);
199 
200  // Useful for database operations
201  const Super& optional() const {
202  return *this;
203  }
204 };
205 
207 template<class Tag>
208 inline
209 bool operator<(const ObjectId<Tag>& lhs, const ObjectId<Tag>& rhs)
210 {
211  if (!rhs) return false;
212  if (!lhs) return true;
213 
214  return lhs.get() < rhs.get();
215 }
216 
217 using TestSuiteId = ObjectId<TestSuite>;
218 using SpecimenId = ObjectId<Specimen>;
219 using TestCaseId = ObjectId<TestCase>;
220 using ExecutionEventId = ObjectId<ExecutionEvent>;
225 template<class T>
226 struct ObjectTraits {
227  using Id = void;
228 };
229 
230 template<>
231 struct ObjectTraits<TestSuite> {
232  using Id = TestSuiteId;
233 };
234 
235 template<>
236 struct ObjectTraits<Specimen> {
237  using Id = SpecimenId;
238 };
239 
240 template<>
241 struct ObjectTraits<TestCase> {
242  using Id = TestCaseId;
243 };
244 
245 template<>
246 struct ObjectTraits<ExecutionEvent> {
247  using Id = ExecutionEventId;
248 };
249 
250 } // namespace
251 } // namespace
252 } // namespace
253 
254 #endif
255 #endif
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to concrete RISC operations.
const char * IoDirection(int64_t)
Convert Rose::BinaryAnalysis::Concolic::IoDirection enum constant to a string.
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.
const char * ShowAssertions(int64_t)
Convert Rose::BinaryAnalysis::Concolic::ShowAssertions enum constant to a string. ...
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++.
const char * When(int64_t)
Convert Rose::BinaryAnalysis::Concolic::When enum constant to a string.
Reference-counting intrusive smart pointer.
Definition: SharedPointer.h:68
Allocate memory for real.
Definition: CodeInserter.h:16
const char * Update(int64_t)
Convert Rose::BinaryAnalysis::Concolic::Update enum constant to a string.
const char * ConcolicPhase(int64_t)
Convert Rose::BinaryAnalysis::Concolic::ConcolicPhase enum constant to a string.
size_t Id
Attribute identification.
Definition: Attribute.h:140
const char * ShowEvents(int64_t)
Convert Rose::BinaryAnalysis::Concolic::ShowEvents enum constant to a string.
void initDiagnostics()
Initialize diagnostics.
const char * InputType(int64_t)
Convert Rose::BinaryAnalysis::Concolic::InputType enum constant to a string.
Represents no value.
Definition: Optional.h:32
Base class for all ROSE exceptions.
Definition: Rose/Exception.h:9
const char * Architecture(int64_t)
Convert Rose::BinaryAnalysis::DisassemblerMips::Mips32::Architecture enum constant to a string...