ROSE 0.11.145.147
PathNode.h
1#ifndef ROSE_BinaryAnalysis_ModelChecker_PathNode_H
2#define ROSE_BinaryAnalysis_ModelChecker_PathNode_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_MODEL_CHECKER
5
6#include <Rose/BinaryAnalysis/ModelChecker/BasicTypes.h>
7#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/BasicTypes.h>
8#include <Rose/BinaryAnalysis/SmtSolver.h>
9#include <Rose/BinaryAnalysis/SymbolicExpression.h>
10
11namespace Rose {
12namespace BinaryAnalysis {
13namespace ModelChecker {
14
23class PathNode {
24public:
26 using Ptr = PathNodePtr;
27
28private:
29 const Ptr parent_; // Previous node in execution path. Null for root node.
30 const ExecutionUnitPtr executionUnit_; // The thing to execute, non-null
31
32 mutable SAWYER_THREAD_TRAITS::Mutex mutex_; // protects all following data members
33
34 // Path states are used as follows:
35 //
36 // When a path is executed, its incomingState_ is copied, modified by the thread's semantics operators, and the
37 // resulting state is stored as outgoingState_. The incomingState_ (which is shared among paths, see next bullet) is
38 // then set to null.
39 //
40 // When a path is extended by creating new paths each with an additional node, the new nodes' incomingState_ points to
41 // the original path's outgoingState_, then the original path's outgoingState_ is set to null. Thus the new paths all
42 // point to a shared incoming state.
43 InstructionSemantics::BaseSemantics::StatePtr incomingState_; // shared state before execution, then null afterward
44 InstructionSemantics::BaseSemantics::StatePtr outgoingState_; // state after execution, or null if error during execution
45
46 bool executionFailed_ = false; // true iff execution failed (and outgoingState_ therefore null)
47 std::vector<SymbolicExpression::Ptr> assertions_; // assertions for the model checker for this node of the path
48 SmtSolver::Evidence evidence_; // SMT evidence that path to and including this node is feasible
49 std::vector<TagPtr> tags_; // tags associated with this node of the path
50 uint32_t id_ = 0; // a random path ID number
51 double processingTime_ = NAN; // time required to execute and extend this node
52 double sortKey_ = NAN; // field for user-defined sorting
53
54protected:
55 PathNode() = delete;
56
60 PathNode(const ExecutionUnitPtr&);
61
65 PathNode(const Ptr &parent, const ExecutionUnitPtr&, const SymbolicExpression::Ptr &assertion,
66 const SmtSolver::Evidence&, const InstructionSemantics::BaseSemantics::StatePtr &parentOutgoingState);
67
68public:
69 ~PathNode();
70
71public:
77 static Ptr instance(const ExecutionUnitPtr&);
78
86 static Ptr instance(const Ptr &parent, const ExecutionUnitPtr&, const SymbolicExpression::Ptr &assertion,
87 const SmtSolver::Evidence&, const InstructionSemantics::BaseSemantics::StatePtr &parentOutgoingState);
88
94 uint32_t id() const;
95
106 double sortKey() const;
107 void sortKey(double);
118 Ptr parent() const;
119
128 ExecutionUnitPtr executionUnit() const;
129
136 size_t nSteps() const;
137
144 void assertion(const SymbolicExpression::Ptr&);
145
149 std::vector<SymbolicExpression::Ptr> assertions() const;
150
156 SmtSolver::Evidence evidence() const;
157
167 void execute(const SettingsPtr&, const SemanticCallbacksPtr&, const InstructionSemantics::BaseSemantics::RiscOperatorsPtr&,
168 const SmtSolver::Ptr&);
169
175 bool executionFailed() const;
176
185 InstructionSemantics::BaseSemantics::StatePtr copyOutgoingState() const;
186
187 class BorrowedOutgoingState {
188 friend class PathNode;
189 private:
190 PathNode* const node;
191 public:
192 const InstructionSemantics::BaseSemantics::StatePtr state;
193 private:
194 BorrowedOutgoingState() = delete;
195 BorrowedOutgoingState& operator=(const BorrowedOutgoingState&) = delete;
196 BorrowedOutgoingState(PathNode*, const InstructionSemantics::BaseSemantics::StatePtr&);
197 public:
198 ~BorrowedOutgoingState();
199 };
200
220 BorrowedOutgoingState borrowOutgoingState();
221
229 void releaseOutgoingState();
230
238 void appendTag(const TagPtr&);
239 void appendTags(const std::vector<TagPtr>&);
245 size_t nTags() const;
246
250 std::vector<TagPtr> tags() const;
251
257 double processingTime() const;
258
264 void incrementProcessingTime(double seconds);
265
269 Sawyer::Optional<rose_addr_t> address() const;
270
276 std::string printableName() const;
277
281 void toYamlHeader(const SettingsPtr&, std::ostream&, const std::string &prefix) const;
282
284 void toYamlSteps(const SettingsPtr&, std::ostream&, const std::string &prefix,
285 size_t stepOrigin, size_t maxSteps) const;
286
288 std::vector<Sarif::LocationPtr> toSarif(size_t maxSteps) const;
289
290private:
291 void restoreOutgoingState(const InstructionSemantics::BaseSemantics::StatePtr&);
292};
293
294} // namespace
295} // namespace
296} // namespace
297
298#endif
299#endif
Holds a value or nothing.
Definition Optional.h:56
Sawyer::SharedPointer< Node > Ptr
Reference counting pointer.
The ROSE library.
Id id(const std::string &name)
Returns the ID for an attribute name.