1 #ifndef ROSE_BinaryAnalysis_Variables_H
2 #define ROSE_BinaryAnalysis_Variables_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/Types.h>
7 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/MemoryCellState.h>
8 #include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
9 #include <Rose/BinaryAnalysis/SymbolicExpression.h>
11 #include <Sawyer/IntervalMap.h>
12 #include <Sawyer/Message.h>
13 #include <Sawyer/Optional.h>
14 #include <Sawyer/Set.h>
16 #include <boost/serialization/access.hpp>
17 #include <boost/serialization/split_member.hpp>
20 namespace BinaryAnalysis {
59 std::string
sizeStr(uint64_t size);
67 rose_addr_t maxSizeBytes_ = 0;
72 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
74 friend class boost::serialization::access;
77 void serialize(S &s,
const unsigned ) {
78 s & BOOST_SERIALIZATION_NVP(maxSizeBytes_);
79 s & BOOST_SERIALIZATION_NVP(insnVas_);
80 s & BOOST_SERIALIZATION_NVP(ioProperties_);
81 s & BOOST_SERIALIZATION_NVP(name_);
136 const std::string&
name()
const;
137 void name(
const std::string &s);
173 int64_t frameOffset_ = 0;
176 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
178 friend class boost::serialization::access;
181 void serialize(S &s,
const unsigned version) {
183 s & BOOST_SERIALIZATION_NVP(function_);
184 s & BOOST_SERIALIZATION_NVP(frameOffset_);
186 s & BOOST_SERIALIZATION_NVP(purpose_);
258 void print(std::ostream&)
const;
281 rose_addr_t address_ = 0;
283 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
285 friend class boost::serialization::access;
288 void serialize(S &s,
const unsigned ) {
290 s & BOOST_SERIALIZATION_NVP(address_);
339 void print(std::ostream&)
const;
497 #if 0 // [Robb Matzke 2021-10-27]
575 #if 0 // [Robb Matzke 2021-10-27]
Information about a stack frame.
std::string toString() const
Printing global variable.
New frames are added at lower addresses than old frames.
friend std::ostream & operator<<(std::ostream &, const Rose::BinaryAnalysis::Variables::StackVariable &)
Print local variable descriptor.
const Settings & settings() const
Settings for this analysis.
const AddressSet & definingInstructionVas() const
Property: Addresses of instructions related to this variable.
Direction growthDirection
Direction that the stack grows when pushing a new frame.
Description of a global variable.
void initializeFrameBoundaries(const StackFrame &, const Partitioner2::Partitioner &, const Partitioner2::FunctionPtr &, StackVariable::Boundaries &boundaries)
Initilialize offsets for function prologue.
RegisterDescriptor framePointerRegister
Optional descriptor for register pointing to latest frame.
Sawyer::Message::Facility mlog
Diagnostic facility.
std::set< int64_t > findFrameOffsets(const StackFrame &, const Partitioner2::Partitioner &, SgAsmInstruction *)
Find stack variable addresses.
int64_t frameOffset
Address of boundary with respect to frame pointer.
boost::shared_ptr< class MemoryCellState > MemoryCellStatePtr
Shared-ownership pointer to a cell-based memory state.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
Base class for machine instructions.
std::string rule
Informal rule name used to detect frame characteristics.
AddressInterval interval() const
Location of variable in memory.
Analysis to find variable locations.
Sawyer::SharedPointer< VariableFinder > VariableFinderPtr
Reference counting pointer.
std::vector< Boundary > Boundaries
List of boundaries.
Describes a local or global variable.
const std::string & name() const
Property: Optional variable name.
const std::string & setDefaultName()
Give variable a defult name.
std::set< SymbolicExpression::Ptr > getMemoryAddresses(const InstructionSemantics::BaseSemantics::MemoryCellStatePtr &)
Find addresses in memory state.
void evict(const Partitioner2::FunctionPtr &)
Removed cached information.
const InstructionSemantics::BaseSemantics::InputOutputPropertySet & ioProperties() const
Property: I/O properties.
AddressToAddresses findGlobalVariableVas(const Partitioner2::Partitioner &)
Find global variable addresses.
void removeOutliers(const StackFrame &, const Partitioner2::Partitioner &, const Partitioner2::FunctionPtr &, StackVariable::Boundaries &sortedBoundaries)
Remove boundaries that are outside a stack frame.
friend std::ostream & operator<<(std::ostream &, const Rose::BinaryAnalysis::Variables::GlobalVariable &)
Print global variable descriptor.
bool operator==(const StackVariable &other) const
Compare two local variables.
void print(const StackVariables &, const Partitioner2::Partitioner &, std::ostream &out, const std::string &prefix="")
Print info about multiple local variables.
void initDiagnostics()
Initialize diagnostic output.
Main namespace for the ROSE library.
std::map< rose_addr_t, AddressSet > AddressToAddresses
Mapping from addresses to address sets.
static Ptr instance(const Settings &settings=Settings())
Allocating constructor.
StackVariable()
Default constructor.
None of the above purposes.
rose_addr_t address() const
Property: Starting address.
GlobalVariable()
Default constructor.
Normal source code level variable.
OffsetInterval interval() const
Location within the function stack frame.
std::string sizeStr(uint64_t size)
Format size as a string.
Purpose purpose() const
Property: Purpose.
BaseVariable()
Default constructor.
Sawyer::Optional< int64_t > minOffset
Minimum frame offset w.r.t.
Sawyer::Optional< int64_t > maxOffset
Maximum frame offset w.r.t.
Possible or known return address.
void print(std::ostream &) const
Printing global variable.
std::map< int64_t, AddressSet > OffsetToAddresses
Mapping from stack offsets to address sets.
Boundary between stack variables.
Describes (part of) a physical CPU register.
bool isCached(const Partitioner2::FunctionPtr &)
Test whether local variable information is cached.
static Boundary & insertBoundary(Boundaries &, int64_t frameOffset, rose_addr_t insnVa)
Insert a new boundary or adjust an existing boundary.
rose_addr_t maxSizeBytes() const
Property: Maximum variable size in bytes.
std::string offsetStr(int64_t offset)
Format a stack offset as a string.
Purpose purpose
Purpose of addresses above this boundary.
Settings that control this analysis.
const std::string & setDefaultName()
Give variable a defult name.
New frames are added at higher addresses than old frames.
bool operator!=(const StackVariable &other) const
Compare two local variables.
AddressSet definingInsns
Instructions that define this boundary.
Sawyer::Container::Set< rose_addr_t > AddressSet
Set of addresses.
std::set< rose_addr_t > findConstants(const SymbolicExpression::Ptr &)
Find address constants in an expression.
Base class for reference counted objects.
std::string toString() const
Printing local variable.
Range of values delimited by endpoints.
StackFrame detectFrameAttributes(const Partitioner2::Partitioner &, const Partitioner2::FunctionPtr &)
Figure out attributes describing the stack frame for the specified function.
int64_t frameOffset() const
Property: Frame offset.
void print(std::ostream &) const
Printing local variable.
Pointer to previous stack frame.
std::set< rose_addr_t > findAddressConstants(const InstructionSemantics::BaseSemantics::MemoryCellStatePtr &)
Find constants in memory.
Purpose
Purpose of variable.
Partitions instructions into basic blocks and functions.
Sawyer::Container::IntervalMap< AddressInterval, GlobalVariable > GlobalVariables
Maps virtual addresses to global variables.
Partitioner2::FunctionPtr functionForInstruction(const Partitioner2::Partitioner &, SgAsmInstruction *)
Function that owns an instruction.
Sawyer::Container::Interval< int64_t > OffsetInterval
Interval of signed offsets.
Sawyer::Optional< uint64_t > size
Size of the frame in bytes if known.
StackVariables findStackVariables(const Partitioner2::Partitioner &, const Partitioner2::FunctionPtr &)
Find local variables in a function.
GlobalVariables findGlobalVariables(const Partitioner2::Partitioner &)
Find global variables.
Description of a local stack variable within a function.
Settings & settings()
Settings for this analysis.
bool operator!=(const GlobalVariable &other) const
Compare two global variable descriptors.
bool operator==(const GlobalVariable &other) const
Compare two global variable descriptors.