ROSE  0.9.9.139
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State Class Reference

Description

Base class for semantics machine states.

Binary semantic analysis usually progresses one instruction at a time–one starts with an initial state and the act of processing an instruction modifies the state. The State is the base class class for the semantic states of various instruction semantic policies. It contains storage for all the machine registers and memory.

Sometimes it's useful to have a state that contains only registers or only memory. Although this class doesn't allow its register or memory state children to be null pointers, the NullSemantics class provides register and memory states that are mostly no-ops.

States must be copyable objects. Many analyses keep a copy of the machine state for each instruction or each CFG vertex.

State objects are allocated on the heap and reference counted. The BaseSemantics::State 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 1272 of file BaseSemantics2.h.

#include <BaseSemantics2.h>

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

Classes

class  WithFormatter
 State with formatter. More...
 

Public Types

typedef StatePtr Ptr
 Shared-ownership pointer for a State. More...
 

Public Member Functions

virtual StatePtr create (const RegisterStatePtr &registers, const MemoryStatePtr &memory) const
 Virtual constructor. More...
 
virtual StatePtr clone () const
 Virtual copy constructor. More...
 
SValuePtr protoval () const
 Return the protoval. More...
 
SValuePtr get_protoval () const ROSE_DEPRECATED("use protoval instead")
 
virtual void clear ()
 Initialize state. More...
 
virtual void zero_registers ()
 Initialize all registers to zero. More...
 
virtual void clear_memory ()
 Clear all memory locations. More...
 
RegisterStatePtr registerState () const
 Property: Register state. More...
 
RegisterStatePtr get_register_state () ROSE_DEPRECATED("use registerState instead")
 
MemoryStatePtr memoryState () const
 Property: Memory state. More...
 
MemoryStatePtr get_memory_state () ROSE_DEPRECATED("use memoryState instead")
 
virtual SValuePtr readRegister (RegisterDescriptor desc, const SValuePtr &dflt, RiscOperators *ops)
 Read a value from a register. More...
 
virtual void writeRegister (RegisterDescriptor desc, const SValuePtr &value, RiscOperators *ops)
 Write a value to a register. More...
 
virtual SValuePtr readMemory (const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps)
 Read a value from memory. More...
 
virtual void writeMemory (const SValuePtr &addr, const SValuePtr &value, RiscOperators *addrOps, RiscOperators *valOps)
 Write a value to memory. More...
 
void print_registers (std::ostream &stream, const std::string &prefix="") ROSE_DEPRECATED("use printRegisters instead")
 
virtual void print_registers (std::ostream &stream, Formatter &fmt) const ROSE_DEPRECATED("use printRegisters instead")
 
void print_memory (std::ostream &stream, const std::string prefix="") const ROSE_DEPRECATED("use printMemory instead")
 
virtual void print_memory (std::ostream &stream, Formatter &fmt) const ROSE_DEPRECATED("use printMemory instead")
 
virtual bool merge (const StatePtr &other, RiscOperators *ops)
 Merge operation for data flow analysis. More...
 
void printRegisters (std::ostream &stream, const std::string &prefix="")
 Print the register contents. More...
 
virtual void printRegisters (std::ostream &stream, Formatter &fmt) const
 Print the register contents. More...
 
void printMemory (std::ostream &stream, const std::string &prefix="") const
 Print memory contents. More...
 
virtual void printMemory (std::ostream &stream, Formatter &fmt) const
 Print memory contents. More...
 
void print (std::ostream &stream, const std::string &prefix="") const
 Print the state. More...
 
virtual void print (std::ostream &, Formatter &) const
 Print the state. More...
 
WithFormatter with_format (Formatter &fmt)
 Used for printing states with formatting. More...
 
WithFormatter operator+ (Formatter &fmt)
 Used for printing states with formatting. More...
 

Static Public Member Functions

static StatePtr instance (const RegisterStatePtr &registers, const MemoryStatePtr &memory)
 Instantiate a new state object with specified register and memory states. More...
 
static StatePtr instance (const StatePtr &other)
 Instantiate a new copy of an existing state. More...
 
static StatePtr promote (const StatePtr &x)
 

Protected Member Functions

 State (const RegisterStatePtr &registers, const MemoryStatePtr &memory)
 
 State (const State &other)
 

Member Typedef Documentation

Shared-ownership pointer for a State.

See Shared ownership.

Definition at line 1315 of file BaseSemantics2.h.

Member Function Documentation

static StatePtr Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::instance ( const RegisterStatePtr registers,
const MemoryStatePtr memory 
)
inlinestatic
static StatePtr Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::instance ( const StatePtr other)
inlinestatic

Instantiate a new copy of an existing state.

Definition at line 1329 of file BaseSemantics2.h.

virtual StatePtr Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::create ( const RegisterStatePtr registers,
const MemoryStatePtr memory 
) const
inlinevirtual
virtual StatePtr Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::clone ( ) const
inlinevirtual

Virtual copy constructor.

Allocates a new state object which is a deep copy of this state. States must be copyable objects because many analyses depend on being able to make a copy of the entire semantic state at each machine instruction, at each CFG vertex, etc.

Reimplemented in Rose::BinaryAnalysis::InstructionSemantics2::PartialSymbolicSemantics::State.

Definition at line 1344 of file BaseSemantics2.h.

References Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::RegisterStateX86::instance().

SValuePtr Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::protoval ( ) const
inline

Return the protoval.

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

Definition at line 1361 of file BaseSemantics2.h.

virtual void Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::clear ( )
virtual

Initialize state.

The register and memory states are cleared.

virtual void Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::zero_registers ( )
virtual

Initialize all registers to zero.

Calls the RegisterState::zero method. Memory is not affected.

virtual void Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::clear_memory ( )
virtual

Clear all memory locations.

Calls the MemoryState::clear method. Registers are not affected.

RegisterStatePtr Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::registerState ( ) const
inline

Property: Register state.

This read-only property is the register substate of this whole state.

Definition at line 1384 of file BaseSemantics2.h.

MemoryStatePtr Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::memoryState ( ) const
inline

Property: Memory state.

This read-only property is the memory substate of this whole state.

Definition at line 1396 of file BaseSemantics2.h.

virtual SValuePtr Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::readRegister ( RegisterDescriptor  desc,
const SValuePtr dflt,
RiscOperators ops 
)
virtual

Read a value from a register.

The BaseSemantics::readRegister implementation simply delegates to the register state member of this state. See BaseSemantics::RiscOperators::readRegister for details.

virtual void Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::writeRegister ( RegisterDescriptor  desc,
const SValuePtr value,
RiscOperators ops 
)
virtual

Write a value to a register.

The BaseSemantics::writeRegister implementation simply delegates to the register state member of this state. See BaseSemantics::RiscOperators::writeRegister for details.

virtual SValuePtr Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::readMemory ( const SValuePtr address,
const SValuePtr dflt,
RiscOperators addrOps,
RiscOperators valOps 
)
virtual

Read a value from memory.

The BaseSemantics::readMemory() implementation simply delegates to the memory state member of this state. See BaseSemantics::RiscOperators::readMemory() for details.

virtual void Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::writeMemory ( const SValuePtr addr,
const SValuePtr value,
RiscOperators addrOps,
RiscOperators valOps 
)
virtual

Write a value to memory.

The BaseSemantics::writeMemory() implementation simply delegates to the memory state member of this state. See BaseSemantics::RiscOperators::writeMemory() for details.

void Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::printRegisters ( std::ostream &  stream,
const std::string &  prefix = "" 
)

Print the register contents.

This method emits one line per register and contains the register name and its value.

virtual void Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::printRegisters ( std::ostream &  stream,
Formatter fmt 
) const
virtual

Print the register contents.

This method emits one line per register and contains the register name and its value.

void Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::printMemory ( std::ostream &  stream,
const std::string &  prefix = "" 
) const

Print memory contents.

This simply calls the MemoryState::print method.

virtual void Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::printMemory ( std::ostream &  stream,
Formatter fmt 
) const
virtual

Print memory contents.

This simply calls the MemoryState::print method.

void Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::print ( std::ostream &  stream,
const std::string &  prefix = "" 
) const

Print the state.

This emits a multi-line string containing the registers and all known memory locations.

virtual void Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::print ( std::ostream &  ,
Formatter  
) const
virtual

Print the state.

This emits a multi-line string containing the registers and all known memory locations.

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

Used for printing states with formatting.

The usual way to use this is:

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

Definition at line 1490 of file BaseSemantics2.h.

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

Used for printing states with formatting.

The usual way to use this is:

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

Definition at line 1491 of file BaseSemantics2.h.

References Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::RegisterState::with_format().

virtual bool Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::State::merge ( const StatePtr other,
RiscOperators ops 
)
virtual

Merge operation for data flow analysis.

Merges the other state into this state. Returns true if this state changed, false otherwise. This method usually isn't overridden in subclasses since all the base implementation does is invoke the merge operation on the memory state and register state.


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