ROSE
0.11.131.0
|
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::InstructionSemantics namespace for an overview of how the parts fit together.
#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/State.h>
Classes | |
class | WithFormatter |
State with formatter. More... | |
Public Types | |
using | Ptr = StatePtr |
Shared-ownership pointer. More... | |
Public Member Functions | |
virtual StatePtr | create (const RegisterStatePtr ®isters, const MemoryStatePtr &memory) const |
Virtual constructor. More... | |
virtual StatePtr | clone () const |
Virtual copy constructor. More... | |
SValuePtr | protoval () const |
Return the protoval. More... | |
virtual void | clear () |
Initialize state. More... | |
void | zeroRegisters () |
Initialize all registers to zero. More... | |
void | clearMemory () |
Clear all memory locations. More... | |
RegisterStatePtr | registerState () const |
Property: Register state. More... | |
MemoryStatePtr | memoryState () const |
Property: Memory state. More... | |
virtual SValuePtr | readRegister (RegisterDescriptor desc, const SValuePtr &dflt, RiscOperators *ops) |
Read a value from a register. More... | |
virtual SValuePtr | peekRegister (RegisterDescriptor desc, const SValuePtr &dflt, RiscOperators *ops) |
Read register without side effects. 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 SValuePtr | peekMemory (const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) |
Read from memory without side effects. More... | |
virtual void | writeMemory (const SValuePtr &addr, const SValuePtr &value, RiscOperators *addrOps, RiscOperators *valOps) |
Write a value to memory. More... | |
virtual void | hash (Combinatorics::Hasher &, RiscOperators *addrOps, RiscOperators *valOps) const |
Compute a hash of the state. More... | |
std::string | toString () const |
Convert the state to a string for debugging. More... | |
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... | |
WithFormatter | operator+ (const std::string &linePrefix) |
Used for printing states with formatting. More... | |
Static Public Member Functions | |
static StatePtr | instance (const RegisterStatePtr ®isters, 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 ®isters, const MemoryStatePtr &memory) | |
State (const State &other) | |
|
inlinestatic |
|
inlinevirtual |
Virtual constructor.
Reimplemented in Rose::BinaryAnalysis::InstructionSemantics::PartialSymbolicSemantics::State.
Definition at line 94 of file State.h.
References instance().
|
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::InstructionSemantics::PartialSymbolicSemantics::State.
Definition at line 101 of file State.h.
References instance().
SValuePtr Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::State::protoval | ( | ) | const |
Return the protoval.
The protoval is used to construct other values via its virtual constructors.
|
virtual |
Initialize state.
The register and memory states are cleared.
void Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::State::zeroRegisters | ( | ) |
Initialize all registers to zero.
Calls the RegisterState::zero method. Memory is not affected.
void Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::State::clearMemory | ( | ) |
Clear all memory locations.
Calls the MemoryState::clear method. Registers are not affected.
|
inline |
|
inline |
|
virtual |
Read a value from a register.
The BaseSemantics::State::readRegister implementation simply delegates to the register state member of this state. See BaseSemantics::RiscOperators::readRegister for details.
|
virtual |
Read register without side effects.
The BaseSemantics::State::peekRegister implementation simply delegates to the register state member of this state. See BaseSemantics::RiscOperators::peekRegister for details.
|
virtual |
Write a value to a register.
The BaseSemantics::State::writeRegister implementation simply delegates to the register state member of this state. See BaseSemantics::RiscOperators::writeRegister for details.
|
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 |
Read from memory without side effects.
The BaseSemantics::peekMemory() implementation simply delegates to the memory state member of this state. See BaseSemantics::RiscOperators::peekMemory() for details.
|
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.
|
virtual |
Compute a hash of the state.
The state hash is computed by combining the memory hash with the register hash.
void Rose::BinaryAnalysis::InstructionSemantics::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 |
Print the register contents.
This method emits one line per register and contains the register name and its value.
void Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::State::printMemory | ( | std::ostream & | stream, |
const std::string & | prefix = "" |
||
) | const |
Print memory contents.
This simply calls the MemoryState::print method.
|
virtual |
Print memory contents.
This simply calls the MemoryState::print method.
void Rose::BinaryAnalysis::InstructionSemantics::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 |
Print the state.
This emits a multi-line string containing the registers and all known memory locations.
std::string Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::State::toString | ( | ) | const |
Convert the state to a string for debugging.
This is intended mainly for debugging so that you can easily print the state from within a debugger.
|
inline |
Used for printing states with formatting.
The usual way to use this is:
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.
Definition at line 243 of file State.h.
Referenced by operator+().
|
inline |
Used for printing states with formatting.
The usual way to use this is:
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.
Definition at line 244 of file State.h.
References with_format().
WithFormatter Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::State::operator+ | ( | const std::string & | linePrefix | ) |
Used for printing states with formatting.
The usual way to use this is:
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.
|
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.