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/BasicTypes.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>
27 namespace BinaryAnalysis {
66 std::string
sizeStr(uint64_t size);
74 rose_addr_t maxSizeBytes_ = 0;
79 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
81 friend class boost::serialization::access;
84 void serialize(S &s,
const unsigned ) {
85 s & BOOST_SERIALIZATION_NVP(maxSizeBytes_);
86 s & BOOST_SERIALIZATION_NVP(insnVas_);
87 s & BOOST_SERIALIZATION_NVP(ioProperties_);
88 s & BOOST_SERIALIZATION_NVP(name_);
143 const std::string&
name()
const;
144 void name(
const std::string &s);
180 int64_t frameOffset_ = 0;
183 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
185 friend class boost::serialization::access;
188 void serialize(S &s,
const unsigned version) {
190 s & BOOST_SERIALIZATION_NVP(function_);
191 s & BOOST_SERIALIZATION_NVP(frameOffset_);
193 s & BOOST_SERIALIZATION_NVP(purpose_);
265 void print(std::ostream&)
const;
273 explicit operator bool()
const {
303 rose_addr_t address_ = 0;
305 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
307 friend class boost::serialization::access;
310 void serialize(S &s,
const unsigned ) {
312 s & BOOST_SERIALIZATION_NVP(address_);
361 void print(std::ostream&)
const;
369 explicit operator bool()
const {
469 : gvarMethod1MaxTimePerFunction(30) {}
557 #if 0 // [Robb Matzke 2021-10-27]
635 #if 0 // [Robb Matzke 2021-10-27]
684 static void merge(AddressToAddresses&,
const AddressToAddresses&);
Information about a stack frame.
std::string toString() const
Printing global variable.
New frames are added at lower addresses than old frames.
static bool regionIsFullyReadWrite(const Partitioner2::PartitionerConstPtr &, const AddressInterval &)
True if memory region is fully mapped with read and write access.
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.
RegisterDescriptor framePointerRegister
Optional descriptor for register pointing to latest frame.
Sawyer::Message::Facility mlog
Diagnostic facility.
bool isEmpty() const
True if interval is empty.
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.
bool operator!() const
Predicate to test whether variable is invalid.
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.
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 initDiagnostics()
Initialize diagnostic output.
Main namespace for the ROSE library.
std::map< rose_addr_t, AddressSet > AddressToAddresses
Mapping from addresses to address sets.
AddressInterval isInconsistent(const GlobalVariables &, Sawyer::Message::Stream &)
Check that the map is consistent.
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.
StackFrame detectFrameAttributes(const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &)
Figure out attributes describing the stack frame for the specified function.
std::set< int64_t > findFrameOffsets(const StackFrame &, const Partitioner2::PartitionerConstPtr &, SgAsmInstruction *)
Find stack variable addresses.
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.
bool operator!() const
Predicate to test whether variable is invalid.
StackVariables findStackVariables(const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &)
Find local variables in a function.
Possible or known return address.
std::chrono::seconds gvarMethod1MaxTimePerFunction
Max time to spend in Method 1 global variable analysis per function.
void print(std::ostream &) const
Printing global variable.
void print(const StackVariables &, const Partitioner2::PartitionerConstPtr &, std::ostream &out, const std::string &prefix="")
Print info about multiple local variables.
std::map< int64_t, AddressSet > OffsetToAddresses
Mapping from stack offsets to address sets.
Boundary between stack variables.
static bool regionIsFullyMapped(const Partitioner2::PartitionerConstPtr &, const AddressInterval &)
True if memory region is fully mapped.
Describes (part of) a physical CPU register.
GlobalVariables findGlobalVariables(const Partitioner2::PartitionerConstPtr &)
Find global variables.
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.
static bool regionContainsInstructions(const Partitioner2::PartitionerConstPtr &, const AddressInterval &)
True if memory region contains any decoded instructions.
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.
AddressToAddresses findGlobalVariableVas(const Partitioner2::PartitionerConstPtr &)
Find global variable addresses.
int64_t frameOffset() const
Property: Frame offset.
void print(std::ostream &) const
Printing local variable.
Converts text to messages.
Partitioner2::FunctionPtr functionForInstruction(const Partitioner2::PartitionerConstPtr &, SgAsmInstruction *)
Function that owns an instruction.
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.
void erase(GlobalVariables &, const AddressInterval &toErase)
Erase some global variables.
void initializeFrameBoundaries(const StackFrame &, const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &, StackVariable::Boundaries &boundaries)
Initilialize offsets for function prologue.
void removeOutliers(const StackFrame &, const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &, StackVariable::Boundaries &sortedBoundaries)
Remove boundaries that are outside a stack frame.
Sawyer::Container::Interval< int64_t > OffsetInterval
Interval of signed offsets.
Sawyer::Optional< uint64_t > size
Size of the frame in bytes if known.
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.