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");
228 bool shouldPrint()
const;
231 void before(
const std::string&);
240 void before(
const std::string&,
size_t);
241 void before(
const std::string&,
size_t, uint64_t);
260 void after_exception();
280 virtual void comment(
const std::string&)
override;
291 virtual void hlt()
override;
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.
virtual BaseSemantics::SValuePtr add(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Adds two integers of equal size.
virtual BaseSemantics::SValuePtr fpIsInfinity(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Whether a floating-point value is infinity.
virtual SgAsmInstruction * currentInstruction() const override
Property: Current instruction.
virtual BaseSemantics::SValuePtr fpAdd(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Add two floating-point values.
virtual BaseSemantics::SValuePtr protoval() const override
Property: Prototypical semantic value.
virtual BaseSemantics::SValuePtr unsignedModulo(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Calculates modulo with unsigned values.
virtual BaseSemantics::SValuePtr xor_(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Computes bit-wise XOR of two values.
virtual BaseSemantics::SValuePtr fpSubtract(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Subtract one floating-point value from another.
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.
virtual BaseSemantics::SValuePtr mostSignificantSetBit(const BaseSemantics::SValuePtr &) override
Returns position of most significant set bit; zero when no bits are set.
virtual 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.
virtual BaseSemantics::SValuePtr rdtsc() override
Invoked for the x86 RDTSC 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::SValuePtr filterReturnTarget(const BaseSemantics::SValuePtr &) override
Invoked to filter return targets.
virtual void startInstruction(SgAsmInstruction *) override
Called at the beginning of every instruction.
virtual BaseSemantics::SValuePtr filterCallTarget(const BaseSemantics::SValuePtr &) override
Invoked to filter call targets.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::StatePtr &state, const SmtSolverPtr &=SmtSolverPtr()) const override
Virtual allocating constructor.
virtual BaseSemantics::SValuePtr fpSign(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Sign of floating-point value.
virtual BaseSemantics::SValuePtr undefined_(size_t nbits) override
Returns a new undefined value.
Sawyer::Message::Stream & stream()
Property: output stream to which tracing is emitted.
virtual BaseSemantics::SValuePtr shiftLeft(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Returns arg shifted left.
const std::string & indentation() const
Property: Line prefix string.
void showingSubdomain(bool)
Property: Show subdomain name in output.
virtual BaseSemantics::SValuePtr rotateLeft(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Rotate bits to the left.
virtual BaseSemantics::SValuePtr leastSignificantSetBit(const BaseSemantics::SValuePtr &) override
Returns position of least significant set bit; zero when no bits are set.
virtual BaseSemantics::SValuePtr signedMultiply(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Multiplies two signed values.
virtual BaseSemantics::SValuePtr fpIsZero(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Whether a floating-point value is equal to zero.
virtual BaseSemantics::SValuePtr unsignedDivide(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Divides two unsigned values.
virtual BaseSemantics::SValuePtr shiftRight(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Returns arg shifted right logically (no sign bit).
virtual BaseSemantics::SValuePtr unspecified_(size_t nbits) override
Returns a new undefined value.
virtual BaseSemantics::SValuePtr signedModulo(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Calculates modulo with signed values.
virtual SmtSolverPtr solver() const override
Property: Satisfiability module theory (SMT) solver.
virtual BaseSemantics::SValuePtr peekMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt) override
Read memory without side effects.
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.
virtual void print(std::ostream &, BaseSemantics::Formatter &) const override
Print multi-line output for this object.
virtual BaseSemantics::SValuePtr extract(const BaseSemantics::SValuePtr &, size_t begin_bit, size_t end_bit) override
Extracts bits from a value.
virtual void cpuid() override
Invoked for the x86 CPUID instruction.
virtual BaseSemantics::SValuePtr fpFromInteger(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Construct a floating-point value from an integer value.
bool showingSubdomain() const
Property: Show subdomain name in output.
virtual size_t nInsns() const override
Property: Number of instructions processed.
virtual BaseSemantics::SValuePtr equalToZero(const BaseSemantics::SValuePtr &) override
Determines whether a value is equal to zero.
bool onlyInstructions() const
Property: Show only operations for instructions.
virtual BaseSemantics::SValuePtr or_(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Computes bit-wise OR of two values.
virtual BaseSemantics::SValuePtr boolean_(bool value) override
Returns a Boolean value.
virtual BaseSemantics::SValuePtr fpConvert(const BaseSemantics::SValuePtr &, SgAsmFloatType *, SgAsmFloatType *) override
Convert from one floating-point type to another.
virtual BaseSemantics::SValuePtr concat(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Concatenates the bits of two values.
virtual BaseSemantics::SValuePtr peekRegister(RegisterDescriptor, const BaseSemantics::SValuePtr &dflt) override
Obtain a register value without side effects.
virtual void writeMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &data, const BaseSemantics::SValuePtr &cond) override
Writes a value to memory.
static RiscOperatorsPtr instance(const BaseSemantics::RiscOperatorsPtr &subdomain)
Instantiate a new RiscOperators object.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &=SmtSolverPtr()) const override
Virtual allocating constructor.
virtual BaseSemantics::SValuePtr bottom_(size_t nbits) override
Returns a data-flow bottom value.
virtual BaseSemantics::SValuePtr unsignedMultiply(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Multiply two unsigned values.
virtual BaseSemantics::SValuePtr iteWithStatus(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, IteStatus &) override
If-then-else with status.
virtual void solver(const SmtSolverPtr &) override
Property: Satisfiability module theory (SMT) solver.
const BaseSemantics::RiscOperatorsPtr & subdomain() const
Property: Subdomain to which operations are forwarded.
void checkSubdomain() const
Check that we have a valid subdomain.
virtual bool isNoopRead() const override
Property: No-op read.
virtual BaseSemantics::SValuePtr signedDivide(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Divides two signed values.
virtual BaseSemantics::SValuePtr filterIndirectJumpTarget(const BaseSemantics::SValuePtr &) override
Invoked to filter indirect jumps.
virtual void isNoopRead(bool) override
Property: No-op read.
virtual BaseSemantics::StatePtr currentState() const override
Property: Current semantic state.
virtual BaseSemantics::SValuePtr invert(const BaseSemantics::SValuePtr &) override
One's complement.
virtual BaseSemantics::SValuePtr readRegister(RegisterDescriptor, const BaseSemantics::SValuePtr &dflt) override
Reads a value from a register.
virtual void finishInstruction(SgAsmInstruction *) override
Called at the end of every instruction.
virtual void hlt() override
Invoked for the x86 HLT instruction.
virtual BaseSemantics::SValuePtr fpEffectiveExponent(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Exponent of floating-point value.
virtual BaseSemantics::SValuePtr fpRoundTowardZero(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Round toward zero.
virtual void comment(const std::string &) override
Inject a line comment into debugging streams.
virtual BaseSemantics::SValuePtr and_(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Computes bit-wise AND of two values.
virtual void writeRegister(RegisterDescriptor, const BaseSemantics::SValuePtr &) override
Writes a value to a register.
virtual BaseSemantics::SValuePtr shiftRightArithmetic(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Returns arg shifted right arithmetically (with sign bit).
virtual BaseSemantics::SValuePtr fpToInteger(const BaseSemantics::SValuePtr &, SgAsmFloatType *, const BaseSemantics::SValuePtr &) override
Construct an integer value from a floating-point value.
virtual BaseSemantics::SValuePtr negate(const BaseSemantics::SValuePtr &) override
Two's complement.
virtual void nInsns(size_t n) override
Property: Number of instructions processed.
virtual BaseSemantics::SValuePtr number_(size_t nbits, uint64_t value) override
Returns a number of the specified bit width.
virtual void currentState(const BaseSemantics::StatePtr &) override
Property: Current semantic state.
void onlyInstructions(bool)
Property: Show only operations for instructions.
void indentation(const std::string &)
Property: Line prefix string.
virtual BaseSemantics::SValuePtr signExtend(const BaseSemantics::SValuePtr &, size_t nbits) override
Sign extends a value.
virtual BaseSemantics::SValuePtr fpMultiply(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Multiply two floating-point values.
RiscOperatorsPtr Ptr
Shared-ownership pointer.
virtual BaseSemantics::SValuePtr fpSquareRoot(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Square root.
void showingInstructionVa(bool)
Property: Show instruction in output.
virtual void currentInstruction(SgAsmInstruction *) override
Property: Current instruction.
virtual BaseSemantics::SValuePtr fpIsNan(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Whether a floating-point value is a special not-a-number bit pattern.
void stream(Sawyer::Message::Stream &)
Property: output stream to which tracing is emitted.
virtual 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.
virtual BaseSemantics::SValuePtr rotateRight(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &) override
Rotate bits to the right.
virtual BaseSemantics::SValuePtr fpIsDenormalized(const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Whether a floating-point value is denormalized.
virtual BaseSemantics::SValuePtr fpDivide(const BaseSemantics::SValuePtr &, const BaseSemantics::SValuePtr &, SgAsmFloatType *) override
Divide one floating-point value by another.
virtual BaseSemantics::SValuePtr readMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt, const BaseSemantics::SValuePtr &cond) override
Reads a value from memory.
virtual void interrupt(int majr, int minr) override
Unconditionally raise an interrupt.
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.