ROSE 0.11.145.192
TraceSemantics.h
1#ifndef ROSE_BinaryAnalysis_InstructionSemantics_TraceSemantics_H
2#define ROSE_BinaryAnalysis_InstructionSemantics_TraceSemantics_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
6#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics.h>
7#include <Rose/Diagnostics.h>
8
9namespace Rose {
10namespace BinaryAnalysis {
11namespace InstructionSemantics {
12
52namespace TraceSemantics {
53
54
56// Semantic values
58
59using SValue = void;
60
62using SValuePtr = boost::shared_ptr<void>;
63
64
66// Register state
68
69using RegisterState = void;
70
72using RegisterStatePtr = boost::shared_ptr<void>;
73
74
76// Memory state
78
79using MemoryState = void;
80
82using MemoryStatePtr = boost::shared_ptr<void>;
83
84
86// RISC operators
88
90using RiscOperatorsPtr = boost::shared_ptr<class RiscOperators>;
91
94public:
97
100
101private:
102 BaseSemantics::RiscOperatorsPtr subdomain_; // Domain to which all our RISC operators chain
103 Sawyer::Message::Stream stream_; // stream to which output is emitted
104 std::string indentation_; // string to print at start of each line
105 bool showingSubdomain_ = true; // show subdomain name and address on each line of output?
106 bool showingInstructionVa_ = true; // show instruction VA on each line of output?
107 bool onlyInstructions_ = true; // trace only operations associated with an instruction.
108
110 // Real constructors.
111protected:
112 // use the version that takes a subdomain instead of this c'tor
114
115 // use the version that takes a subdomain instead of this c'tor.
116 explicit RiscOperators(const BaseSemantics::StatePtr &state, const SmtSolverPtr &solver = SmtSolverPtr());
117
119
120public:
121 virtual ~RiscOperators();
122
124 // Static allocating constructors.
125public:
130
135
139
141 // Virtual constructors
142public:
144 const SmtSolverPtr& = SmtSolverPtr()) const override;
145
147 const SmtSolverPtr& = SmtSolverPtr()) const override;
148
151
153 // Dynamic pointer casts
154public:
158
160 // Methods first defined at this level of the class hierarchy
161public:
170 void checkSubdomain() const;
171
185 const std::string& indentation() const;
186 void indentation(const std::string&);
194 bool showingSubdomain() const;
215 bool onlyInstructions() const;
219protected:
220 void linePrefix();
221 std::string toString(const BaseSemantics::SValuePtr&);
222 std::string toString(SgAsmFloatType*);
223 void check_equal_widths(const BaseSemantics::SValuePtr&, const BaseSemantics::SValuePtr&);
224 const BaseSemantics::SValuePtr &check_width(const BaseSemantics::SValuePtr &a, size_t nbits,
225 const std::string &what="result");
226 std::string register_name(RegisterDescriptor);
227
228 bool shouldPrint() const;
229 bool shouldPrint(SgAsmInstruction*) const;
230
231 void before(const std::string&);
232 void before(const std::string&, RegisterDescriptor);
233 void before(const std::string&, RegisterDescriptor, const BaseSemantics::SValuePtr&);
234 void before(const std::string&, RegisterDescriptor, const BaseSemantics::SValuePtr&, const BaseSemantics::SValuePtr&);
235 void before(const std::string&, RegisterDescriptor, const BaseSemantics::SValuePtr&, const BaseSemantics::SValuePtr&,
236 size_t);
237 void before(const std::string&, RegisterDescriptor, const BaseSemantics::SValuePtr&, const BaseSemantics::SValuePtr&,
239 void before(const std::string&, SgAsmInstruction*, bool showAddress);
240 void before(const std::string&, size_t);
241 void before(const std::string&, size_t, uint64_t);
242 void before(const std::string&, const BaseSemantics::SValuePtr&);
243 void before(const std::string&, const BaseSemantics::SValuePtr&, size_t);
244 void before(const std::string&, const BaseSemantics::SValuePtr&, size_t, size_t);
245 void before(const std::string&, const BaseSemantics::SValuePtr&, const BaseSemantics::SValuePtr&);
246 void before(const std::string&, const BaseSemantics::SValuePtr&, const BaseSemantics::SValuePtr&,
248 void before(const std::string&, const BaseSemantics::SValuePtr&, SgAsmFloatType*);
249 void before(const std::string&, const BaseSemantics::SValuePtr&, SgAsmFloatType*, const BaseSemantics::SValuePtr&);
250 void before(const std::string&, const BaseSemantics::SValuePtr&, SgAsmFloatType*, SgAsmFloatType*);
251 void before(const std::string&, const BaseSemantics::SValuePtr&, const BaseSemantics::SValuePtr&, SgAsmFloatType*);
252
253 void after();
254 void after(SgAsmInstruction*);
258 void after(const BaseSemantics::Exception&);
259 void after(const BaseSemantics::Exception&, SgAsmInstruction*);
260 void after_exception();
261 void after_exception(SgAsmInstruction*);
262
264 // Methods we override from our super class
265public:
266 virtual BaseSemantics::SValuePtr protoval() const override;
267 virtual void solver(const SmtSolverPtr&) override;
268 virtual SmtSolverPtr solver() const override;
269 virtual BaseSemantics::StatePtr currentState() const override;
270 virtual void currentState(const BaseSemantics::StatePtr&) override;
271 virtual void print(std::ostream&, BaseSemantics::Formatter&) const override;
272 virtual size_t nInsns() const override;
273 virtual void nInsns(size_t n) override;
274 virtual SgAsmInstruction* currentInstruction() const override;
275 virtual void currentInstruction(SgAsmInstruction*) override;
276 virtual bool isNoopRead() const override;
277 virtual void isNoopRead(bool) override;
278 virtual void startInstruction(SgAsmInstruction*) override;
279 virtual void finishInstruction(SgAsmInstruction*) override;
280 virtual void comment(const std::string&) override;
281
282 virtual BaseSemantics::SValuePtr undefined_(size_t nbits) override;
283 virtual BaseSemantics::SValuePtr unspecified_(size_t nbits) override;
284 virtual BaseSemantics::SValuePtr number_(size_t nbits, uint64_t value) override;
285 virtual BaseSemantics::SValuePtr boolean_(bool value) override;
286 virtual BaseSemantics::SValuePtr bottom_(size_t nbits) override;
287
291 virtual void hlt() override;
292 virtual void cpuid() override;
293 virtual BaseSemantics::SValuePtr rdtsc() override;
294
295 // The actual RISC operators. These are pure virtual in the base class
300 virtual BaseSemantics::SValuePtr extract(const BaseSemantics::SValuePtr&, size_t begin_bit, size_t end_bit) override;
309 const BaseSemantics::SValuePtr&) override;
312 const BaseSemantics::SValuePtr&, IteStatus&) override;
314 virtual BaseSemantics::SValuePtr signExtend(const BaseSemantics::SValuePtr&, size_t nbits) override;
318 BaseSemantics::SValuePtr&/*out*/) override;
323 const BaseSemantics::SValuePtr&) override;
325 const BaseSemantics::SValuePtr&) override;
327 const BaseSemantics::SValuePtr&) override;
329 const BaseSemantics::SValuePtr&) override;
330
331 virtual void interrupt(int majr, int minr) override;
332
335 const BaseSemantics::SValuePtr&) override;
344 SgAsmFloatType*) override;
346 SgAsmFloatType*) override;
348 SgAsmFloatType*) override;
350 SgAsmFloatType*) override;
353
355 const BaseSemantics::SValuePtr &dflt) override;
357 const BaseSemantics::SValuePtr &dflt) override;
360 const BaseSemantics::SValuePtr &dflt,
361 const BaseSemantics::SValuePtr &cond) override;
363 const BaseSemantics::SValuePtr &dflt) override;
365 const BaseSemantics::SValuePtr &data, const BaseSemantics::SValuePtr &cond) override;
366};
367
368} // namespace
369} // namespace
370} // namespace
371} // namespace
372
373#endif
374#endif
Base class for most instruction semantics RISC operators.
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.
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.
Definition Message.h:1396
Floating point types.
Base class for machine instructions.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
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.
The ROSE library.