1#ifndef ROSE_BinaryAnalysis_InstructionSemantics_TraceSemantics_H
2#define ROSE_BinaryAnalysis_InstructionSemantics_TraceSemantics_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
6#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics.h>
7#include <Rose/Diagnostics.h>
10namespace BinaryAnalysis {
11namespace InstructionSemantics {
52namespace TraceSemantics {
69using RegisterState = void;
79using MemoryState = void;
104 std::string indentation_;
105 bool showingSubdomain_ =
true;
106 bool showingInstructionVa_ =
true;
107 bool onlyInstructions_ =
true;
225 const std::string &what=
"result");
231 void before(
const std::string&);
240 void before(
const std::string&,
size_t);
241 void before(
const std::string&,
size_t, uint64_t);
261 void after_exception();
Base class for exceptions thrown by instruction semantics.
Base class for most instruction semantics RISC operators.
IteStatus
Status for iteWithStatus operation.
Wraps RISC operators so they can be traced.
BaseSemantics::SValuePtr fpEffectiveExponent(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Exponent of floating-point value.
void isNoopRead(bool) override
Property: No-op read.
BaseSemantics::SValuePtr negate(const BaseSemantics::SValuePtr &) override
Two's complement.
BaseSemantics::SValuePtr unsignedExtend(const BaseSemantics::SValuePtr &, size_t nbits) override
Extend (or shrink) operand a so it is nbits wide by adding or removing high-order bits.
void interrupt(int majr, int minr) override
Unconditionally raise an interrupt.
BaseSemantics::SValuePtr filterCallTarget(const BaseSemantics::SValuePtr &) override
Invoked to filter call targets.
BaseSemantics::SValuePtr fpSquareRoot(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Square root.
BaseSemantics::SValuePtr extract(const BaseSemantics::SValuePtr &, size_t begin_bit, size_t end_bit) override
Extracts bits from a value.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::RiscOperatorsPtr &subdomain)
Wraps a subdomain's RISC operators to add tracing.
void subdomain(const BaseSemantics::RiscOperatorsPtr &subdomain)
Property: Subdomain to which operations are forwarded.
BaseSemantics::SValuePtr readRegister(RegisterDescriptor, const BaseSemantics::SValuePtr &dflt) override
Reads a value from a register.
BaseSemantics::SValuePtr fpIsZero(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Whether a floating-point value is equal to zero.
BaseSemantics::SValuePtr shiftRightArithmetic(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Returns arg shifted right arithmetically (with sign bit).
void writeMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &data, const BaseSemantics::SValuePtr &cond) override
Writes a value to memory.
BaseSemantics::SValuePtr xor_(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Computes bit-wise XOR of two values.
void currentInstruction(SgAsmInstruction *) override
Property: Current instruction.
BaseSemantics::SValuePtr addWithCarries(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, BaseSemantics::SValuePtr &) override
Add two values of equal size and a carry bit.
BaseSemantics::SValuePtr fpIsInfinity(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Whether a floating-point value is infinity.
void finishInstruction(SgAsmInstruction *) override
Called at the end of every instruction.
bool showingInstructionVa() const
Property: Show instruction in output.
static RiscOperatorsPtr promote(const BaseSemantics::RiscOperatorsPtr &)
Run-time promotion of a base RiscOperators pointer to trace operators.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::StatePtr &state, const SmtSolverPtr &=SmtSolverPtr()) const override
Virtual allocating constructor.
BaseSemantics::SValuePtr iteWithStatus(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, IteStatus &) override
If-then-else with status.
BaseSemantics::SValuePtr signedModulo(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Calculates modulo with signed values.
BaseSemantics::SValuePtr unsignedModulo(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Calculates modulo with unsigned values.
Sawyer::Message::Stream & stream()
Property: output stream to which tracing is emitted.
BaseSemantics::SValuePtr signExtend(const BaseSemantics::SValuePtr &, size_t nbits) override
Sign extends a value.
BaseSemantics::SValuePtr fpToInteger(const BaseSemantics::SValuePtr &, SgAsmFloatType *, const BaseSemantics::SValuePtr &) override
Construct an integer value from a floating-point value.
const std::string & indentation() const
Property: Line prefix string.
void showingSubdomain(bool)
Property: Show subdomain name in output.
BaseSemantics::SValuePtr fpRoundTowardZero(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Round toward zero.
BaseSemantics::SValuePtr bottom_(size_t nbits) override
Returns a data-flow bottom value.
BaseSemantics::SValuePtr fpSubtract(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Subtract one floating-point value from another.
void currentState(const BaseSemantics::StatePtr &) override
Property: Current semantic state.
BaseSemantics::SValuePtr signedDivide(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Divides two signed values.
static RiscOperatorsPtr instance(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &=SmtSolverPtr())
Instantiates a new RiscOperators object.
static RiscOperatorsPtr instance(const BaseSemantics::StatePtr &, const SmtSolverPtr &=SmtSolverPtr())
Instantiates a new RiscOperators object.
BaseSemantics::SValuePtr fpMultiply(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Multiply two floating-point values.
BaseSemantics::SValuePtr unsignedMultiply(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Multiply two unsigned values.
BaseSemantics::SValuePtr fpSign(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Sign of floating-point value.
BaseSemantics::SValuePtr filterReturnTarget(const BaseSemantics::SValuePtr &) override
Invoked to filter return targets.
BaseSemantics::SValuePtr fpAdd(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Add two floating-point values.
bool showingSubdomain() const
Property: Show subdomain name in output.
BaseSemantics::SValuePtr unsignedDivide(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Divides two unsigned values.
BaseSemantics::SValuePtr or_(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Computes bit-wise OR of two values.
void startInstruction(SgAsmInstruction *) override
Called at the beginning of every instruction.
BaseSemantics::SValuePtr unspecified_(size_t nbits) override
Returns a new undefined value.
BaseSemantics::SValuePtr fpIsNan(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Whether a floating-point value is a special not-a-number bit pattern.
BaseSemantics::SValuePtr undefined_(size_t nbits) override
Returns a new undefined value.
bool onlyInstructions() const
Property: Show only operations for instructions.
BaseSemantics::SValuePtr readMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt, const BaseSemantics::SValuePtr &cond) override
Reads a value from memory.
BaseSemantics::SValuePtr rotateRight(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Rotate bits to the right.
BaseSemantics::SValuePtr fpDivide(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Divide one floating-point value by another.
BaseSemantics::SValuePtr add(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Adds two integers of equal size.
BaseSemantics::SValuePtr fpFromInteger(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Construct a floating-point value from an integer value.
BaseSemantics::SValuePtr protoval() const override
Property: Prototypical semantic value.
BaseSemantics::SValuePtr rotateLeft(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Rotate bits to the left.
void print(std::ostream &, BaseSemantics::Formatter &) const override
Print multi-line output for this object.
SgAsmInstruction * currentInstruction() const override
Property: Current instruction.
static RiscOperatorsPtr instance(const BaseSemantics::RiscOperatorsPtr &subdomain)
Instantiate a new RiscOperators object.
BaseSemantics::SValuePtr boolean_(bool value) override
Returns a Boolean value.
void solver(const SmtSolverPtr &) override
Property: Satisfiability module theory (SMT) solver.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &=SmtSolverPtr()) const override
Virtual allocating constructor.
BaseSemantics::SValuePtr filterIndirectJumpTarget(const BaseSemantics::SValuePtr &) override
Invoked to filter indirect jumps.
BaseSemantics::SValuePtr peekOperand(size_t depth=0) override
Peeks at a value from the Frame Operand Stack.
const BaseSemantics::RiscOperatorsPtr & subdomain() const
Property: Subdomain to which operations are forwarded.
void pushOperand(const BaseSemantics::SValue::Ptr &a) override
Pushes a value to the Frame Operand Stack.
BaseSemantics::SValuePtr mostSignificantSetBit(const BaseSemantics::SValuePtr &) override
Returns position of most significant set bit; zero when no bits are set.
void checkSubdomain() const
Check that we have a valid subdomain.
BaseSemantics::SValuePtr equalToZero(const BaseSemantics::SValuePtr &) override
Determines whether a value is equal to zero.
void writeRegister(RegisterDescriptor, const BaseSemantics::SValuePtr &) override
Writes a value to a register.
BaseSemantics::SValuePtr shiftLeft(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Returns arg shifted left.
void nInsns(size_t n) override
Property: Number of instructions processed.
BaseSemantics::SValuePtr peekMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt) override
Read memory without side effects.
void hlt() override
Invoked for the x86 HLT instruction.
size_t nInsns() const override
Property: Number of instructions processed.
BaseSemantics::SValuePtr leastSignificantSetBit(const BaseSemantics::SValuePtr &) override
Returns position of least significant set bit; zero when no bits are set.
BaseSemantics::SValuePtr fpIsDenormalized(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Whether a floating-point value is denormalized.
SmtSolverPtr solver() const override
Property: Satisfiability module theory (SMT) solver.
BaseSemantics::SValuePtr number_(size_t nbits, uint64_t value) override
Returns a number of the specified bit width.
BaseSemantics::StatePtr currentState() const override
Property: Current semantic state.
BaseSemantics::SValuePtr signedMultiply(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Multiplies two signed values.
BaseSemantics::SValuePtr popOperand() override
Pops a value from the Frame Operand Stack.
BaseSemantics::SValuePtr rdtsc() override
Invoked for the x86 RDTSC instruction.
void onlyInstructions(bool)
Property: Show only operations for instructions.
void indentation(const std::string &)
Property: Line prefix string.
BaseSemantics::SValuePtr peekRegister(RegisterDescriptor, const BaseSemantics::SValuePtr &dflt) override
Obtain a register value without side effects.
RiscOperatorsPtr Ptr
Shared-ownership pointer.
void comment(const std::string &) override
Inject a line comment into debugging streams.
BaseSemantics::SValuePtr shiftRight(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Returns arg shifted right logically (no sign bit).
void showingInstructionVa(bool)
Property: Show instruction in output.
void stream(Sawyer::Message::Stream &)
Property: output stream to which tracing is emitted.
BaseSemantics::SValuePtr and_(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Computes bit-wise AND of two values.
bool isNoopRead() const override
Property: No-op read.
void cpuid() override
Invoked for the x86 CPUID instruction.
BaseSemantics::SValuePtr concat(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Concatenates the bits of two values.
BaseSemantics::SValuePtr invert(const BaseSemantics::SValuePtr &) override
One's complement.
Describes (part of) a physical CPU register.
Converts text to messages.
Base class for machine instructions.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
boost::shared_ptr< void > MemoryStatePtr
Shared-ownership pointer to trace-semantics memory state.
boost::shared_ptr< void > SValuePtr
Shared-ownership pointer to trace-semantics values.
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to trace-semantics RISC operations.
boost::shared_ptr< void > RegisterStatePtr
Shared-ownership pointer to trace-semantics register state.
std::shared_ptr< SmtSolver > SmtSolverPtr
Reference counting pointer.