ROSE  0.11.54.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState Class Referenceabstract

Description

Represents all memory in the state.

MemoryState objects are allocated on the heap and reference counted. The BaseSemantics::MemoryState is an abstract class that defines the interface. See the Rose::BinaryAnalysis::InstructionSemantics2 namespace for an overview of how the parts fit together.

Definition at line 25 of file MemoryState.h.

#include <MemoryState.h>

Inheritance diagram for Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState:
Inheritance graph
[legend]
Collaboration diagram for Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState:
Collaboration graph
[legend]

Classes

class  WithFormatter
 MemoryState with formatter. More...
 

Public Types

typedef MemoryStatePtr Ptr
 Shared-ownership pointer for a MemoryState. More...
 

Public Member Functions

virtual MemoryStatePtr create (const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const =0
 Virtual allocating constructor. More...
 
virtual MemoryStatePtr clone () const =0
 Virtual allocating copy constructor. More...
 
SValuePtr get_addr_protoval () const
 Return the address protoval. More...
 
SValuePtr get_val_protoval () const
 Return the value protoval. More...
 
virtual void clear ()=0
 Clear memory. More...
 
virtual bool merge (const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps)=0
 Merge memory states for data flow analysis. More...
 
virtual SValuePtr readMemory (const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps)=0
 Read a value from memory. More...
 
virtual SValuePtr peekMemory (const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps)=0
 Read a value from memory without side effects. More...
 
virtual void writeMemory (const SValuePtr &addr, const SValuePtr &value, RiscOperators *addrOps, RiscOperators *valOps)=0
 Write a value to memory. More...
 
virtual void hash (Combinatorics::Hasher &, RiscOperators *addrOps, RiscOperators *valOps) const =0
 Calculate a hash for this memory state. More...
 
MergerPtr merger () const
 Property: Merger. More...
 
void merger (const MergerPtr &)
 Property: Merger. More...
 
bool byteRestricted () const
 Indicates whether memory cell values are required to be eight bits wide. More...
 
void byteRestricted (bool b)
 Indicates whether memory cell values are required to be eight bits wide. More...
 
ByteOrder::Endianness get_byteOrder () const
 Memory byte order.
 
void set_byteOrder (ByteOrder::Endianness bo)
 Memory byte order.
 
void print (std::ostream &, const std::string prefix="") const
 Print a memory state to more than one line of output.
 
virtual void print (std::ostream &, Formatter &) const =0
 Print a memory state to more than one line of output.
 
WithFormatter with_format (Formatter &fmt)
 Used for printing memory states with formatting. More...
 
WithFormatter operator+ (Formatter &fmt)
 Used for printing memory states with formatting. More...
 
WithFormatter operator+ (const std::string &linePrefix)
 Used for printing memory states with formatting. More...
 

Static Public Member Functions

static MemoryStatePtr promote (const MemoryStatePtr &x)
 

Protected Member Functions

 MemoryState (const SValuePtr &addrProtoval, const SValuePtr &valProtoval)
 
 MemoryState (const MemoryStatePtr &other)
 

Member Typedef Documentation

Shared-ownership pointer for a MemoryState.

See Shared ownership.

Definition at line 28 of file MemoryState.h.

Member Function Documentation

virtual MemoryStatePtr Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::create ( const SValuePtr addrProtoval,
const SValuePtr valProtoval 
) const
pure virtual

Virtual allocating constructor.

Allocates and constructs a new MemoryState object having the same dynamic type as this object. A prototypical SValue must be supplied and will be used to construct any additional SValue objects needed during the operation of a MemoryState. Two prototypical values are supplied, one for addresses and another for values stored at those addresses, although they will almost always be the same.

Implemented in Rose::BinaryAnalysis::InstructionSemantics2::SymbolicSemantics::MemoryMapState, Rose::BinaryAnalysis::InstructionSemantics2::SymbolicSemantics::MemoryListState, Rose::BinaryAnalysis::InstructionSemantics2::IntervalSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics2::NullSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics2::ConcreteSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics2::NativeSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryCellList, and Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::SymbolicMemory.

virtual MemoryStatePtr Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::clone ( ) const
pure virtual
MergerPtr Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::merger ( ) const

Property: Merger.

This property is optional details about how to merge two states. It is passed down to the register and memory state merge operation and to the semantic value merge operation. Users can subclass this to hold whatever information is necessary for merging. Unless the user overrides merge functions to do something else, all merging will use the same merger object – the one set for this property.

void Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::merger ( const MergerPtr )

Property: Merger.

This property is optional details about how to merge two states. It is passed down to the register and memory state merge operation and to the semantic value merge operation. Users can subclass this to hold whatever information is necessary for merging. Unless the user overrides merge functions to do something else, all merging will use the same merger object – the one set for this property.

SValuePtr Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::get_addr_protoval ( ) const
inline

Return the address protoval.

The address protoval is used to construct other memory addresses via its virtual constructors.

Definition at line 106 of file MemoryState.h.

SValuePtr Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::get_val_protoval ( ) const
inline

Return the value protoval.

The value protoval is used to construct other stored values via its virtual constructors.

Definition at line 110 of file MemoryState.h.

virtual void Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::clear ( )
pure virtual
bool Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::byteRestricted ( ) const
inline

Indicates whether memory cell values are required to be eight bits wide.

The default is true since this simplifies the calculations for whether two memory cells are alias and how to combine the value from two or more aliasing cells. A memory that contains only eight-bit values requires that the caller concatenate/extract individual bytes when reading/writing multi-byte values.

Definition at line 122 of file MemoryState.h.

void Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::byteRestricted ( bool  b)
inline

Indicates whether memory cell values are required to be eight bits wide.

The default is true since this simplifies the calculations for whether two memory cells are alias and how to combine the value from two or more aliasing cells. A memory that contains only eight-bit values requires that the caller concatenate/extract individual bytes when reading/writing multi-byte values.

Definition at line 123 of file MemoryState.h.

virtual bool Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::merge ( const MemoryStatePtr other,
RiscOperators addrOps,
RiscOperators valOps 
)
pure virtual
virtual SValuePtr Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::readMemory ( const SValuePtr address,
const SValuePtr dflt,
RiscOperators addrOps,
RiscOperators valOps 
)
pure virtual

Read a value from memory.

Consults the memory represented by this MemoryState object and returns a semantic value. Depending on the semantic domain, the value can be a value that is already stored in the memory state, a supplied default value, a new value constructed from some combination of existing values and/or the default value, or anything else. For instance, in a symbolic domain the address could alias multiple existing memory locations and the implementation may choose to return a McCarthy expression. Additional data (such as SMT solvers) may be passed via the RiscOperators argument.

The size of the value being read does not necessarily need to be equal to the size of values stored in the memory state, though it typically is(1). For instance, an implementation may allow reading a 32-bit little endian value from a memory state that stores only bytes. A RiscOperators object is provided for use in these situations.

In order to support cases where an address does not match any existing location, the dflt value can be used to initialize a new memory location. The manner in which the default is used depends on the implementation. In any case, the width of the dflt value determines how much to read.

Footnote 1: A MemoryState::readMemory() call is the last in a sequence of delegations starting with RiscOperators::readMemory(). The designers of the MemoryState, State, and RiscOperators subclasses will need to coordinate to decide which layer should handle concatenating values from individual memory locations.

Implemented in Rose::BinaryAnalysis::InstructionSemantics2::SymbolicSemantics::MemoryListState, Rose::BinaryAnalysis::InstructionSemantics2::IntervalSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics2::ConcreteSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics2::NullSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics2::NativeSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryCellList, Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryCellMap, and Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::SymbolicMemory.

virtual SValuePtr Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::peekMemory ( const SValuePtr address,
const SValuePtr dflt,
RiscOperators addrOps,
RiscOperators valOps 
)
pure virtual
virtual void Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::writeMemory ( const SValuePtr addr,
const SValuePtr value,
RiscOperators addrOps,
RiscOperators valOps 
)
pure virtual

Write a value to memory.

Consults the memory represented by this MemoryState object and possibly inserts the specified value. The details of how a value is inserted into a memory state depends entirely on the implementation in a subclass and will probably be different for each semantic domain.

A MemoryState::writeMemory() call is the last in a sequence of delegations starting with RiscOperators::writeMemory(). The designers of the MemoryState, State, and RiscOperators will need to coordinate to decide which layer (if any) should handle splitting a multi-byte value into multiple memory locations.

Implemented in Rose::BinaryAnalysis::InstructionSemantics2::SymbolicSemantics::MemoryListState, Rose::BinaryAnalysis::InstructionSemantics2::IntervalSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics2::ConcreteSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics2::NullSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics2::NativeSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryCellList, Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryCellMap, and Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::SymbolicMemory.

virtual void Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::hash ( Combinatorics::Hasher ,
RiscOperators addrOps,
RiscOperators valOps 
) const
pure virtual

Calculate a hash for this memory state.

This hashes the addresses and values stored in memory. The goal is to be able to identify when two memory states are the "same". An analysis might be able to take shortcuts if it encounters a state that it has seen before.

Implemented in Rose::BinaryAnalysis::InstructionSemantics2::NullSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics2::ConcreteSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics2::NativeSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryCellList, Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryCellMap, and Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::SymbolicMemory.

WithFormatter Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::with_format ( Formatter fmt)
inline

Used for printing memory states with formatting.

The usual way to use this is:

MemoryStatePtr obj = ...;
Formatter fmt = ...;
std::cout <<"The value is: " <<(*obj+fmt) <<"\n";

Since specifying a line prefix string for indentation purposes is such a common use case, the indentation can be given instead of a format, as in the following code that indents the prefixes each line of the expression with four spaces.

std::cout <<"Memory state:\n" <<*(obj + " ");

Definition at line 215 of file MemoryState.h.

Referenced by operator+().

WithFormatter Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::operator+ ( Formatter fmt)
inline

Used for printing memory states with formatting.

The usual way to use this is:

MemoryStatePtr obj = ...;
Formatter fmt = ...;
std::cout <<"The value is: " <<(*obj+fmt) <<"\n";

Since specifying a line prefix string for indentation purposes is such a common use case, the indentation can be given instead of a format, as in the following code that indents the prefixes each line of the expression with four spaces.

std::cout <<"Memory state:\n" <<*(obj + " ");

Definition at line 216 of file MemoryState.h.

References with_format().

WithFormatter Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::MemoryState::operator+ ( const std::string &  linePrefix)

Used for printing memory states with formatting.

The usual way to use this is:

MemoryStatePtr obj = ...;
Formatter fmt = ...;
std::cout <<"The value is: " <<(*obj+fmt) <<"\n";

Since specifying a line prefix string for indentation purposes is such a common use case, the indentation can be given instead of a format, as in the following code that indents the prefixes each line of the expression with four spaces.

std::cout <<"Memory state:\n" <<*(obj + " ");

The documentation for this class was generated from the following file: