ROSE 0.11.145.192
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_HAVE_BOOST_SERIALIZATION_LIB
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_HAVE_BOOST_SERIALIZATION_LIB
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
78
94 int64_t stackOffset() const;
95 void stackOffset(int64_t offset);
110 const std::string& setDefaultName();
111
118 bool operator==(const StackVariable &other) const;
119 bool operator!=(const StackVariable &other) const;
126
132 static Boundary& insertBoundary(Boundaries& /*in,out*/, int64_t stackOffset, const InstructionAccess&);
137 static void printBoundary(std::ostream&, const Boundary&, const std::string &prefix = "");
138
142 void print(std::ostream&) const;
143 std::string toString() const;
150 explicit operator bool() const {
151 return !interval().isEmpty();
152 }
153
157 bool operator!() const {
158 return interval().isEmpty();
159 }
160
162 friend std::ostream& operator<<(std::ostream&, const Rose::BinaryAnalysis::Variables::StackVariable&);
163};
164
167
172void print(const StackVariables&, const Partitioner2::PartitionerConstPtr&, std::ostream &out, const std::string &prefix = "");
173
174} // namespace
175} // namespace
176} // namespace
177
178// Class versions must be at global scope
180
181#endif
182#endif
Base class describing a source-level variable.
rose_addr_t 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, rose_addr_t 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.
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.