ROSE 2.20.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 SValuePtr currentException_; // exception currently associated with this frame
76
78 // Serialization
79#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
80private:
81 friend class boost::serialization::access;
82
83 template<class S>
84 void serialize(S &s, const unsigned /*version*/) {
85 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(MemoryState);
86 s & BOOST_SERIALIZATION_NVP(frameId_);
87 s & BOOST_SERIALIZATION_NVP(returnAddress_);
88 s & BOOST_SERIALIZATION_NVP(stack_);
89 s & BOOST_SERIALIZATION_NVP(locals_);
90 s & BOOST_SERIALIZATION_NVP(method_);
91 s & BOOST_SERIALIZATION_NVP(currentException_);
92 }
93#endif
94
95public:
97
98protected:
99 FrameState(); // for serialization
100
101 // All memory states should be heap allocated; use instance(), create(), or clone() instead.
102 explicit FrameState(const SValue::Ptr &valProtoval, const Sawyer::Optional<Address> &, const ByteCode::Method::Ptr &);
103 explicit FrameState(const FrameState &other);
104
105public:
108
109public:
110 // documented in base class
111 MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const override;
112
113 // documented in base class
114 AddressSpacePtr clone() const override;
115
120
121public:
122 void clear() override;
123 void clearFrame();
124
125 bool merge(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override;
126
127 SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
128 RiscOperators *addrOps, RiscOperators *valOps) override;
129
130 void writeMemory(const SValuePtr &address, const SValuePtr &value,
131 RiscOperators *addrOps, RiscOperators *valOps) override;
132
133 SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
134 RiscOperators *addrOps, RiscOperators *valOps) override;
135
136 SValuePtr readLocal(size_t index) const override;
137 void writeLocal(size_t index, const SValuePtr &value) override;
138
139 SValuePtr peekOperand(size_t depth = 0) override;
141 void pushOperand(const SValuePtr &value) override;
142
145 void currentException(const SValuePtr &value);
146
147public:
148 void hash(Combinatorics::Hasher&, RiscOperators* addrOps, RiscOperators* valOps) const override;
149 void print(std::ostream&, Formatter&) const override;
150
151 ByteCode::Method::Ptr method() const;
152
153 SValuePtr createArgument(const std::string &descriptor, size_t argIdx);
154 static std::string argumentDescriptor(const std::string &descriptor, size_t argIdx);
155
156 const Sawyer::Optional<Address>& returnAddress() const;
157 void returnAddress(Address);
158
159 size_t frameId() const;
160 void frameId(size_t);
161 static size_t newFrameId();
162
163 std::string frameLabel() const;
164 std::string frameName() const;
165
166 // Short form of frameLabel
167 std::string label() const override;
168
169 static bool isCategory1(const SValuePtr&);
170 static bool isCategory2(const SValuePtr&);
171 static bool isCategory2Tail(const SValuePtr&);
172
173private:
175 void initializeForRootFrame();
176
182 void clearLocalRange(size_t begin, size_t nSlots);
183};
184
185} // namespace
186} // namespace
187} // namespace
188} // namespace
189
190#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
192#endif
193
194#endif
195#endif
SValuePtr currentException() const
The exception currently associated with this frame.
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.