ROSE 2.15.0
Loading...
Searching...
No Matches
FrameState.h
1#ifndef ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_FrameState_H
2#define ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_FrameState_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
6#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/BasicTypes.h>
7#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/AddressSpace.h>
8#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/MemoryState.h>
9#include <Rose/BinaryAnalysis/ByteCode/Analysis.h>
10
11namespace Rose {
12namespace BinaryAnalysis {
13namespace InstructionSemantics {
14namespace BaseSemantics {
15
17using FrameStatePtr = boost::shared_ptr<class FrameState>;
18
25// Frame State
27
61class FrameState: public MemoryState {
62public:
65
68
69private:
70 size_t frameId_ = 0; // unique frame identifier
71 Sawyer::Optional<Address> returnAddress_ = Sawyer::Nothing(); // caller resume address
72 std::vector<SValuePtr> stack_; // operand stack for the frame
73 std::vector<SValuePtr> locals_; // local variables for the frame
74 ByteCode::Method::Ptr method_; // method associated with this invocation frame
75
77 // Serialization
78#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
79private:
80 friend class boost::serialization::access;
81
82 template<class S>
83 void serialize(S &s, const unsigned /*version*/) {
84 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(MemoryState);
85 s & BOOST_SERIALIZATION_NVP(frameId_);
86 s & BOOST_SERIALIZATION_NVP(returnAddress_);
87 s & BOOST_SERIALIZATION_NVP(stack_);
88 s & BOOST_SERIALIZATION_NVP(locals_);
89 s & BOOST_SERIALIZATION_NVP(method_);
90 }
91#endif
92
93public:
95
96protected:
97 FrameState(); // for serialization
98
99 // All memory states should be heap allocated; use instance(), create(), or clone() instead.
100 explicit FrameState(const SValue::Ptr &valProtoval, const Sawyer::Optional<Address> &, const ByteCode::Method::Ptr &);
101 explicit FrameState(const FrameState &other);
102
103public:
106
107public:
108 // documented in base class
109 MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const override;
110
111 // documented in base class
112 AddressSpacePtr clone() const override;
113
118
119public:
120 void clear() override;
121 void clearFrame();
122
123 bool merge(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override;
124
125 SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
126 RiscOperators *addrOps, RiscOperators *valOps) override;
127
128 void writeMemory(const SValuePtr &address, const SValuePtr &value,
129 RiscOperators *addrOps, RiscOperators *valOps) override;
130
131 SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
132 RiscOperators *addrOps, RiscOperators *valOps) override;
133
134 SValuePtr readLocal(size_t index) const override;
135 void writeLocal(size_t index, const SValuePtr &value) override;
136
137 SValuePtr peekOperand(size_t depth = 0) override;
139 void pushOperand(const SValuePtr &value) override;
140
141public:
142 void hash(Combinatorics::Hasher&, RiscOperators* addrOps, RiscOperators* valOps) const override;
143 void print(std::ostream&, Formatter&) const override;
144
145 ByteCode::Method::Ptr method() const;
146
147 SValuePtr createArgument(const std::string &descriptor, size_t argIdx);
148 static std::string argumentDescriptor(const std::string &descriptor, size_t argIdx);
149
150 const Sawyer::Optional<Address>& returnAddress() const;
151 void returnAddress(Address);
152
153 size_t frameId() const;
154 void frameId(size_t);
155 static size_t newFrameId();
156
157 std::string frameLabel() const;
158 std::string frameName() const;
159
160 // Short form of frameLabel
161 std::string label() const override;
162
163 static bool isCategory1(const SValuePtr&);
164 static bool isCategory2(const SValuePtr&);
165 static bool isCategory2Tail(const SValuePtr&);
166
167private:
169 void initializeForRootFrame();
170
176 void clearLocalRange(size_t begin, size_t nSlots);
177};
178
179} // namespace
180} // namespace
181} // namespace
182} // namespace
183
184#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
186#endif
187
188#endif
189#endif
std::string label() const override
Label for this address space.
bool merge(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override
Merge address spaces for data flow analysis.
SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) override
Read a value from memory without side effects.
void pushOperand(const SValuePtr &value) override
Push an operand value.
AddressSpacePtr clone() const override
Deep-copy of this address space.
void hash(Combinatorics::Hasher &, RiscOperators *addrOps, RiscOperators *valOps) const override
Hash this address space.
static FrameStatePtr promote(const AddressSpacePtr &)
Convert pointer to a FrameState pointer.
SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) override
Read a value from memory.
SValuePtr peekOperand(size_t depth=0) override
Peek at an operand value.
void print(std::ostream &, Formatter &) const override
Print an address space.
static FrameStatePtr instance(const SValuePtr &, const Sawyer::Optional< Address > &, const ByteCode::Method::Ptr &)
Instantiate a new empty frame state on the heap.
void writeMemory(const SValuePtr &address, const SValuePtr &value, RiscOperators *addrOps, RiscOperators *valOps) override
Write a value to memory.
MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const override
Virtual allocating constructor.
Base class for most instruction semantics RISC operators.
Represents no value.
Definition Optional.h:34
Holds a value or nothing.
Definition Optional.h:54
Base classes for instruction semantics.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
boost::shared_ptr< AddressSpace > AddressSpacePtr
Shared-ownership pointer for AddressSpace objects.
boost::shared_ptr< FrameState > FrameStatePtr
Shared-ownership pointer to a frame state.
std::uint64_t Address
Address.
Definition Address.h:11
The ROSE library.