ROSE 0.11.145.250
StackVariable.h
1#ifndef ROSE_BinaryAnalysis_Variables_StackVariable_H
2#define ROSE_BinaryAnalysis_Variables_StackVariable_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
6#include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
7#include <Rose/BinaryAnalysis/Variables/BaseVariable.h>
8
9#include <Sawyer/IntervalMap.h>
10
11#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
12#include <boost/serialization/access.hpp>
13#endif
14
15namespace Rose {
16namespace BinaryAnalysis {
17namespace Variables {
18
21public:
23 enum class Purpose {
28 NORMAL,
29 UNKNOWN,
30 OTHER
31 };
32
37 struct Boundary {
38 int64_t stackOffset = 0;
39 std::vector<InstructionAccess> definingInsns;
41 };
42
44 using Boundaries = std::vector<Boundary>;
45
46private:
47 Partitioner2::FunctionPtr function_; // Function in which local variable exists
48 int64_t stackOffset_ = 0; // Offset w.r.t. function's initial stack pointer
49 Purpose purpose_ = Purpose::UNKNOWN;
50
51#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
52private:
53 friend class boost::serialization::access;
54
55 template<class S>
56 void serialize(S &s, const unsigned version) {
57 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(BaseVariable);
58 s & BOOST_SERIALIZATION_NVP(function_);
59 s & BOOST_SERIALIZATION_NVP(stackOffset_);
60 if (version >= 1)
61 s & BOOST_SERIALIZATION_NVP(purpose_);
62 }
63#endif
64
65public:
70
73 const std::vector<InstructionAccess> &definingInstructions = std::vector<InstructionAccess>(),
74 const std::string &name = "");
75
77 StackVariable& operator=(const StackVariable&);
79
95 int64_t stackOffset() const;
96 void stackOffset(int64_t offset);
111 const std::string& setDefaultName();
112
119 bool operator==(const StackVariable &other) const;
120 bool operator!=(const StackVariable &other) const;
127
133 static Boundary& insertBoundary(Boundaries& /*in,out*/, int64_t stackOffset, const InstructionAccess&);
138 static void printBoundary(std::ostream&, const Boundary&, const std::string &prefix = "");
139
143 void print(std::ostream&) const;
144 std::string toString() const;
151 explicit operator bool() const {
152 return !interval().isEmpty();
153 }
154
158 bool operator!() const {
159 return interval().isEmpty();
160 }
161
163 friend std::ostream& operator<<(std::ostream&, const Rose::BinaryAnalysis::Variables::StackVariable&);
164};
165
168
173void print(const StackVariables&, const Partitioner2::PartitionerConstPtr&, std::ostream &out, const std::string &prefix = "");
174
175} // namespace
176} // namespace
177} // namespace
178
179// Class versions must be at global scope
180#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
182#endif
183
184#endif
185#endif
Base class describing a source-level variable.
Address maxSizeBytes() const
Property: Maximum variable size in bytes.
const std::string & name() const
Property: Optional variable name.
Information about how an instruction accesses a variable.
Description of a local stack variable within a function.
std::string toString() const
Printing local variable.
OffsetInterval interval() const
Location of variable w.r.t.
const std::string & setDefaultName()
Give variable a defult name.
friend std::ostream & operator<<(std::ostream &, const Rose::BinaryAnalysis::Variables::StackVariable &)
Print local variable descriptor.
static void printBoundary(std::ostream &, const Boundary &, const std::string &prefix="")
Print information about a boundary.
bool operator==(const StackVariable &other) const
Compare two local variables.
bool operator!=(const StackVariable &other) const
Compare two local variables.
static Boundary & insertBoundary(Boundaries &, int64_t stackOffset, const InstructionAccess &)
Insert a new boundary or adjust an existing boundary.
std::vector< Boundary > Boundaries
List of boundaries.
Purpose purpose() const
Property: Purpose.
void stackOffset(int64_t offset)
Property: Stack offset.
int64_t stackOffset() const
Property: Stack offset.
void print(std::ostream &) const
Printing local variable.
@ NORMAL
Normal source code level variable.
@ RETURN_ADDRESS
Possible or known return address.
@ FRAME_POINTER
Pointer to previous stack frame.
static Boundary & insertBoundaryImplied(Boundaries &, int64_t stackOffset)
Insert a new boundary or adjust an existing boundary.
StackVariable(const Partitioner2::FunctionPtr &, int64_t stackOffset, Address maxSizeBytes, Purpose, const std::vector< InstructionAccess > &definingInstructions=std::vector< InstructionAccess >(), const std::string &name="")
Construct a variable descriptor.
void purpose(Purpose p)
Property: Purpose.
void function(const Partitioner2::FunctionPtr &)
Property: Function owning the variable.
bool operator!() const
Predicate to test whether variable is invalid.
Partitioner2::FunctionPtr function() const
Property: Function owning the variable.
Range of values delimited by endpoints.
Definition Interval.h:31
bool isEmpty() const
True if interval is empty.
Definition Interval.h:230
void print(const GlobalVariables &, const Partitioner2::PartitionerConstPtr &, std::ostream &out, const std::string &prefix="")
Print info about multiple global variables.
std::uint64_t Address
Address.
Definition Address.h:11
The ROSE library.
std::vector< InstructionAccess > definingInsns
Instructions that define this boundary.
Purpose purpose
Purpose of addresses above this boundary.
int64_t stackOffset
Offset from function's initial stack pointer.