ROSE  0.11.145.0
Classes | Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
SgAsmInstruction Class Reference

Description

Base class for machine instructions.

Definition at line 39392 of file binaryInstruction.C.

Inheritance diagram for SgAsmInstruction:
Inheritance graph
[legend]
Collaboration diagram for SgAsmInstruction:
Collaboration graph
[legend]

Public Member Functions

void appendSources (SgAsmInstruction *instruction)
 
virtual std::string description () const
 Return a description of this instruction. More...
 
size_t nOperands () const
 Number of operands. More...
 
SgAsmExpressionoperand (size_t) const
 Nth operand. More...
 
virtual bool terminatesBasicBlock ()
 Determines if this instruction normally terminates a basic block. More...
 
bool isFirstInBlock ()
 Returns true if this instruction is the first instruction in a basic block. More...
 
bool isLastInBlock ()
 Returns true if this instruction is the last instruction in a basic block. More...
 
virtual Sawyer::Optional< rose_addr_t > branchTarget ()
 Obtains the virtual address for a branching instruction. More...
 
bool getBranchTarget (rose_addr_t *target) ROSE_DEPRECATED("use branchTarget instead")
 
virtual bool hasEffect ()
 Determines whether a single instruction has an effect. More...
 
virtual bool hasEffect (const std::vector< SgAsmInstruction * > &, bool allow_branch=false, bool relax_stack_semantics=false)
 Determine if an instruction sequence has an effect. More...
 
virtual std::vector< std::pair< size_t, size_t > > findNoopSubsequences (const std::vector< SgAsmInstruction * > &insns, bool allow_branch=false, bool relax_stack_semantics=false)
 Determines what subsequences of an instruction sequence have no cumulative effect. More...
 
virtual Rose::BinaryAnalysis::AddressSet getSuccessors (bool &complete)
 Control flow successors for a single instruction. More...
 
virtual Rose::BinaryAnalysis::AddressSet getSuccessors (const std::vector< SgAsmInstruction * > &basicBlock, bool &complete, const Rose::BinaryAnalysis::MemoryMap::Ptr &initial_memory=Rose::BinaryAnalysis::MemoryMap::Ptr())
 Control flow successors for a basic block. More...
 
virtual size_t get_size () const
 Returns the size of an instruction in bytes. More...
 
virtual bool isUnknown () const
 Returns true if this instruction is the special "unknown" instruction. More...
 
virtual unsigned get_anyKind () const
 Returns instruction kind for any architecture. More...
 
virtual std::string toString () const
 Converts the instruction to a string. More...
 
virtual std::set< rose_addr_t > explicitConstants () const
 Explicit constants. More...
 
bool normalizeOperands ()
 Rewrite certain addressing modes for operands. More...
 
virtual ~SgAsmInstruction ()
 Destructor. More...
 
 SgAsmInstruction ()
 Default constructor. More...
 
 SgAsmInstruction (rose_addr_t const &address, std::string const &mnemonic)
 Constructor. More...
 
std::string const & get_mnemonic () const
 Property: Instruction mnemonic string. More...
 
void set_mnemonic (std::string const &)
 Property: Instruction mnemonic string. More...
 
SgUnsignedCharList const & get_raw_bytes () const
 Property: Raw bytes of an instruction. More...
 
void set_raw_bytes (SgUnsignedCharList const &)
 Property: Raw bytes of an instruction. More...
 
SgAsmOperandList *const & get_operandList () const
 Property: AST node that holds all operands. More...
 
void set_operandList (SgAsmOperandList *const &)
 Property: AST node that holds all operands. More...
 
size_t cacheLockCount () const
 Property: Cache lock count. More...
 
void adjustCacheLockCount (int increment)
 Property: Cache lock count. More...
 
int64_t const & get_stackDeltaIn () const
 Property: Stack pointer at start of instruction relative to start of instruction's function. More...
 
void set_stackDeltaIn (int64_t const &)
 Property: Stack pointer at start of instruction relative to start of instruction's function. More...
 
SgAsmExprListExp *const & get_semantics () const
 Property: Ordered list of instruction semantics. More...
 
void set_semantics (SgAsmExprListExp *const &)
 Property: Ordered list of instruction semantics. More...
 
virtual bool isFunctionCallFast (const std::vector< SgAsmInstruction * > &, rose_addr_t *target, rose_addr_t *ret)
 Returns true if the specified basic block looks like a function call. More...
 
virtual bool isFunctionCallSlow (const std::vector< SgAsmInstruction * > &, rose_addr_t *target, rose_addr_t *ret)
 Returns true if the specified basic block looks like a function call. More...
 
virtual bool isFunctionReturnFast (const std::vector< SgAsmInstruction * > &)
 Returns true if the specified basic block looks like a function return. More...
 
virtual bool isFunctionReturnSlow (const std::vector< SgAsmInstruction * > &)
 Returns true if the specified basic block looks like a function return. More...
 
size_t semanticFailure () const
 Property: Whether instruction semantics failed at this location. More...
 
void semanticFailure (size_t)
 Property: Whether instruction semantics failed at this location. More...
 
void incrementSemanticFailure ()
 Property: Whether instruction semantics failed at this location. More...
 
- Public Member Functions inherited from SgAsmStatement
virtual ~SgAsmStatement ()
 Destructor. More...
 
rose_addr_t const & get_address () const
 Property: Starting virtual address. More...
 
void set_address (rose_addr_t const &)
 Property: Starting virtual address. More...
 
std::string const & get_comment () const
 Property: Commentary.
 
void set_comment (std::string const &)
 Property: Commentary.
 
- Public Member Functions inherited from SgAsmNode
virtual ~SgAsmNode ()
 Destructor. More...
 
Sawyer::Attribute::Storage const & attributes () const
 Attribute storage. More...
 
Sawyer::Attribute::Storageattributes ()
 Attribute storage. More...
 
- Public Member Functions inherited from SgNode
virtual SgNodecopy (SgCopyHelp &help) const
 This function clones the current IR node object recursively or not, depending on the argument. More...
 
virtual std::string class_name () const
 returns a string representing the class name More...
 
virtual VariantT variantT () const
 returns new style SageIII enum values More...
 
void * operator new (size_t size)
 returns pointer to newly allocated IR node
 
void operator delete (void *pointer, size_t size)
 deallocated memory for IR node (returns memory to memory pool for reuse)
 
void operator delete (void *pointer)
 
virtual std::vector< SgNode * > get_traversalSuccessorContainer ()
 container of pointers to AST successor nodes used in the traversal overridden in every class by generated implementation More...
 
virtual std::vector< std::string > get_traversalSuccessorNamesContainer ()
 container of names of variables or container indices used used in the traversal to access AST successor nodes overridden in every class by generated implementation More...
 
virtual size_t get_numberOfTraversalSuccessors ()
 return number of children in the traversal successor list
 
virtual SgNodeget_traversalSuccessorByIndex (size_t idx)
 index-based access to traversal successors by index number
 
virtual size_t get_childIndex (SgNode *child)
 index-based access to traversal successors by child node
 
virtual RTIReturnType roseRTI ()
 return C++ Runtime-Time-Information More...
 
virtual const char * sage_class_name () const ROSE_DEPRECATED_FUNCTION
 generates string representing the class name: (e.g. for SgNode returns "SgNode"). More...
 
void executeVisitorMemberFunction (ROSE_VisitorPattern &visitor)
 FOR INTERNAL USE Support for visitor pattern.
 
virtual void accept (ROSE_VisitorPattern &visitor)
 support for the classic visitor pattern done in GoF
 
virtual bool isInMemoryPool ()
 FOR INTERNAL USE This is used in internal tests to verify that all IR nodes are allocated from the heap. More...
 
virtual void checkDataMemberPointersIfInMemoryPool ()
 FOR INTERNAL USE This is used in internal tests to verify that all IR nodes are allocated from the heap. More...
 
virtual std::vector< std::pair< SgNode *, std::string > > returnDataMemberPointers () const
 FOR INTERNAL USE Returns STL vector of pairs of SgNode* and strings for use in AST tools More...
 
virtual void processDataMemberReferenceToPointers (ReferenceToPointerHandler *)
 FOR INTERNAL USE Processes pairs of references to SgNode* and strings for use in AST tools More...
 
virtual long getChildIndex (SgNode *childNode) const
 FOR INTERNAL USE Returns a unique index value for the childNode in the list of children at this IR node. More...
 
 SgNode (const SgNodeStorageClass &source)
 IR node constructor to support AST File I/O.
 
SgNodeaddRegExpAttribute (std::string s, AstRegExAttribute *a)
 Support for AST matching using regular expression. More...
 
void set_isModified (bool isModified)
 All nodes in the AST contain a isModified flag used to track changes to the AST. More...
 
void set_containsTransformation (bool containsTransformation)
 Many nodes can hide other AST nodes and we need to track when outer nodes contain modified nodes even if they are not themselves modified. More...
 
bool get_isModified () const
 Acess function for isModified flag. More...
 
bool get_containsTransformation () const
 Acess function for containsTransformation flag. More...
 
void set_parent (SgNode *parent)
 All nodes in the AST contain a reference to a parent node. More...
 
SgNodeget_parent () const
 Access function for parent node. More...
 
SgNodeget_raw_parent () const
 Access function for direct access to uncomputed value of parent node.
 
bool isChild (SgNode *node) const
 Query function for if the input IR nodes is a child of the current IR node.
 
virtual std::string unparseToString (SgUnparse_Info *info) const
 This function unparses the AST node (excluding comments and unnecessary white space)
 
std::string unparseToString () const
 
std::string unparseToCompleteString ()
 This function unparses the AST node (including comments and white space) More...
 
int variant () const ROSE_DEPRECATED_FUNCTION
 Older version function returns enum value "NODE". More...
 
virtual void addNewAttribute (std::string s, AstAttribute *a)
 Add a new attribute represented by the named string.
 
virtual AstAttributegetAttribute (std::string s) const
 Returns attribute of name 's'.
 
virtual void updateAttribute (std::string s, AstAttribute *a)
 Replace existing attribute of name 's' with new AstAttribute.
 
virtual void setAttribute (std::string s, AstAttribute *a)
 This is a wrapper function with the following semantics: if no attribute of name 's' exists then addNewAttribute(s,a); is called, otherwise updateAttribute(s,a); is called.
 
virtual void removeAttribute (std::string s)
 Remove attribute of name 's' if present.
 
virtual bool attributeExists (std::string s) const
 Tests if attribute of name 's' is present.
 
virtual int numberOfAttributes () const
 Returns the number of attributes on this IR node.
 
virtual AstAttributeMechanismget_attributeMechanism () const
 FOR INTERNAL USE Access function; if an attribute exists then a pointer to it is returned, else error. More...
 
virtual void set_attributeMechanism (AstAttributeMechanism *a)
 FOR INTERNAL USE Access function; sets poiner to value AstAttributeMechanism. More...
 
virtual void fixupCopy (SgNode *copy, SgCopyHelp &help) const
 
virtual Sg_File_Infoget_file_info (void) const
 File information containing filename, line number, column number, and if the SgNode is a part of a new transformation, etc.
 
virtual Sg_File_Infoget_startOfConstruct (void) const
 New function interface for Sg_File_Info data stores starting location of contruct (typically the opening brace or first letter of keyword).
 
virtual Sg_File_Infoget_endOfConstruct (void) const
 New function interface for Sg_File_Info data stores ending location of contruct (typically the closing brace).
 
VirtualCFG::CFGNode cfgForBeginning ()
 Returns the CFG node for just before this AST node.
 
VirtualCFG::CFGNode cfgForEnd ()
 Returns the CFG node for just after this AST node.
 
virtual unsigned int cfgIndexForEnd () const
 Determine the CFG index for the end of this construct.
 
virtual bool cfgIsIndexInteresting (unsigned int index) const
 Determine whether a particular CFG node index is "interesting" for this kind of node.
 
virtual unsigned int cfgFindChildIndex (SgNode *n)
 Find the index of n in this node's CFG children.
 
virtual unsigned int cfgFindNextChildIndex (SgNode *n)
 Find the index just after n in this node's CFG children.
 
virtual std::vector< VirtualCFG::CFGEdgecfgOutEdges (unsigned int index=false)
 Find the out edges of a CFG node – internal version.
 
virtual std::vector< VirtualCFG::CFGEdgecfgInEdges (unsigned int index=false)
 Find the in edges of a CFG node – internal version.
 
int numberOfNodesInSubtree ()
 Computes the number of nodes in the defined subtree of the AST. More...
 
int depthOfSubtree ()
 Computes the depth of the current defined subtree of the AST. More...
 
template<class T >
T * initParentPointer (T *child, SgNode *parent)
 Generated for tree edge data member initializations. More...
 
SgNodeget_freepointer () const
 
void set_freepointer (SgNode *freepointer)
 
virtual ~SgNode ()
 This is the destructor. More...
 
 SgNode ()
 This is the constructor. More...
 
bool get_isVisited () const ROSE_DEPRECATED_FUNCTION
 DOCS IN HEADER: Access function for p_isVisited flag used previously by the AST traversals. More...
 
void set_isVisited (bool isVisited) ROSE_DEPRECATED_FUNCTION
 Access function for p_isVisited flag used previously by the AST traversals. More...
 
template<class T >
std::enable_if< std::is_pointer< T >::value, void >::type changeChildPointer (T &edge, T const &child)
 Set a child edge in a tree to point to a specific child. More...
 
template<class T >
std::enable_if< !std::is_pointer< T >::value, void >::type changeChildPointer (T &edge, T const &child)
 Set a child edge in a tree to point to a specific child. More...
 

Static Public Attributes

static const int64_t INVALID_STACK_DELTA
 Represents an invalid stack delta. More...
 

Protected Member Functions

void initializeProperties ()
 Initialize all properties that have explicit initial values. More...
 
- Protected Member Functions inherited from SgAsmStatement
 SgAsmStatement ()
 Default constructor. More...
 
 SgAsmStatement (rose_addr_t const &address)
 Constructor. More...
 
void initializeProperties ()
 Initialize all properties that have explicit initial values. More...
 
- Protected Member Functions inherited from SgAsmNode
 SgAsmNode ()
 Default constructor. More...
 
void initializeProperties ()
 Initialize all properties that have explicit initial values. More...
 
- Protected Member Functions inherited from SgNode
virtual void post_construction_initialization ()
 Final initialization for constructors This function is called at the end of generated constructors to allow the specification writer to add special initialization functions or tests. Default is to do nothing. Otherwise it should be overridden in the spec file, in NewHeaderCode/NewOutlinedCode.
 
virtual void destructorHelper ()
 This gets called by all Rosebud-generated destructors. More...
 
virtual void debugSerializationBegin (const char *className)
 Called by generated serializers. More...
 
virtual void debugSerializationEnd (const char *className)
 Called by generated serializers. More...
 

Additional Inherited Members

- Public Types inherited from SgNode
enum  { static_variant = V_SgNode }
 static variant value
 
- Static Public Member Functions inherited from SgNode
static void deleteMemoryPool ()
 
static size_t numberOfNodes ()
 Returns the total number of IR nodes of this type.
 
static size_t memoryUsage ()
 Returns the size in bytes of the total memory allocated for all IR nodes of this type.
 
static void traverseMemoryPoolNodes (ROSE_VisitTraversal &visit)
 FOR INTERNAL USE Support for visitor pattern over all IR nodes by type of IR node.
 
static void traverseMemoryPoolVisitorPattern (ROSE_VisitorPattern &visitor)
 FOR INTERNAL USE Support for visitor pattern.
 
static void visitRepresentativeNode (ROSE_VisitTraversal &visit)
 FOR INTERNAL USE Support for type-based traversal.
 
static SgNodegetNodeByNodeId (VariantT variantT, size_t poolIdx, size_t itemIdx)
 Find a node by its variant type, pool index, and item index.
 
static SgNodegetNodeByNodeIdInternal (size_t poolIdx, size_t itemIdx)
 FOR INTERNAL USE Find an SgNode from its memory pool and location therin.
 
static std::string getNodeIdString (SgNode *sgnode)
 compute the NodeId for a particular SgNode*.
 
static std::string getNodeIdStringInternal (SgNode *sgnode)
 
static std::vector< std::string > buildCommandLineToSubstituteTransformationFile (const std::vector< std::string > &argv, std::string newFileName)
 Command line support for this compilation The command line is saved as a static variable so that it will be available to support the rewrite mechanism. More...
 
static std::vector< VariantT > getClassHierarchySubTreeFunction (VariantT v)
 
static void getClassHierarchySubTreeFunction (VariantT v, std::vector< VariantT > &)
 
static std::map< SgNode *, std::string > & get_globalMangledNameMap ()
 Access function for performance optimizing global mangled name map. More...
 
static void clearGlobalMangledNameMap ()
 Support to clear the performance optimizing global mangled name map.
 
static std::map< std::string, int > & get_shortMangledNameCache ()
 Access function for lower level optimizing of global mangled name map. More...
 
static std::map< SgNode *, std::string > & get_globalQualifiedNameMapForNames ()
 Access function for name qualification support (for names). More...
 
static void set_globalQualifiedNameMapForNames (const std::map< SgNode *, std::string > &X)
 Access function for name qualification support (for names). More...
 
static std::map< SgNode *, std::string > & get_globalQualifiedNameMapForTypes ()
 Access function for name qualification support (for type). More...
 
static void set_globalQualifiedNameMapForTypes (const std::map< SgNode *, std::string > &X)
 Access function for name qualification support (for type). More...
 
static std::map< SgNode *, std::map< SgNode *, std::string > > & get_globalQualifiedNameMapForMapsOfTypes ()
 Access function for name qualification support (for maps of types). More...
 
static void set_globalQualifiedNameMapForMapsOfTypes (const std::map< SgNode *, std::map< SgNode *, std::string > > &X)
 Access function for name qualification support (for maps of types). More...
 
static std::map< SgNode *, std::string > & get_globalQualifiedNameMapForTemplateHeaders ()
 Access function for name qualification support (for template headers in template declarations). More...
 
static void set_globalQualifiedNameMapForTemplateHeaders (const std::map< SgNode *, std::string > &X)
 Access function for name qualification support (for template headers in template declarations). More...
 
static std::map< SgNode *, std::string > & get_globalTypeNameMap ()
 Access function for name qualification support (for names of types). More...
 
static void set_globalTypeNameMap (const std::map< SgNode *, std::string > &X)
 Access function for name qualification support (for names of types). More...
 
static SgFunctionTypeTableget_globalFunctionTypeTable ()
 Access function for symbol table specific to function types.
 
static void set_globalFunctionTypeTable (SgFunctionTypeTable *globalFunctionTypeTable)
 Access function for symbol table specific to function types.
 
static SgTypeTableget_globalTypeTable ()
 Access function for symbol table specific to non-function types.
 
static void set_globalTypeTable (SgTypeTable *globalTypeTable)
 Access function for symbol table specific to non-function types.
 
static VariantT variantFromPool (SgNode const *n)
 
template<class T >
static std::enable_if< std::is_base_of< SgNode, T >::value, T * >::type createAndParent (SgNode *parent)
 Allocate and return a new node after setting its parent. More...
 
- Protected Attributes inherited from SgNode
SgNodep_parent
 This is the pointer to the parent IR node in the AST. More...
 
bool p_isModified
 Records if IR node has been modified (data members reset). More...
 
bool p_containsTransformation
 
SgNodep_freepointer
 This is the pointer to the chain of previously freed objects.
 
- Static Protected Attributes inherited from SgNode
static std::vector< std::tuple< unsigned char *, unsigned, VariantT > > all_pools
 
static SgFunctionTypeTablep_globalFunctionTypeTable
 Pointer to symbol table specific to function types.
 
static SgTypeTablep_globalTypeTable
 
static std::map< SgNode *, std::string > p_globalMangledNameMap
 Cache of mangled names to avoid regeneration of previously build mangled names or parts of mangled names. This is a performance optimization.
 
static std::map< std::string, int > p_shortMangledNameCache
 STL map used as a cache to shorten generated mangled names. This is mostly a space optimization ofr mangled names of templates.
 
static std::map< SgNode *, std::string > p_globalQualifiedNameMapForNames
 
static std::map< SgNode *, std::string > p_globalQualifiedNameMapForTypes
 
static std::map< SgNode *, std::string > p_globalQualifiedNameMapForTemplateHeaders
 
static std::map< SgNode *, std::string > p_globalTypeNameMap
 
static std::map< SgNode *, std::map< SgNode *, std::string > > p_globalQualifiedNameMapForMapsOfTypes
 

Constructor & Destructor Documentation

virtual SgAsmInstruction::~SgAsmInstruction ( )
virtual

Destructor.

SgAsmInstruction::SgAsmInstruction ( )

Default constructor.

SgAsmInstruction::SgAsmInstruction ( rose_addr_t const &  address,
std::string const &  mnemonic 
)

Constructor.

Member Function Documentation

std::string const& SgAsmInstruction::get_mnemonic ( ) const

Property: Instruction mnemonic string.

The short string that describes the instruction. When comparing instructions, it's faster to use the get_kind or get_anyKind methods instead of comparing mnemonic strings. But be aware that some architectures have mnemonics that include information about the instruction operands and this information is typically not represented by the instruction kind enum constants.

void SgAsmInstruction::set_mnemonic ( std::string const &  )

Property: Instruction mnemonic string.

The short string that describes the instruction. When comparing instructions, it's faster to use the get_kind or get_anyKind methods instead of comparing mnemonic strings. But be aware that some architectures have mnemonics that include information about the instruction operands and this information is typically not represented by the instruction kind enum constants.

SgUnsignedCharList const& SgAsmInstruction::get_raw_bytes ( ) const

Property: Raw bytes of an instruction.

These are the bytes that were actually decoded to obtain the instruction AST.

void SgAsmInstruction::set_raw_bytes ( SgUnsignedCharList const &  )

Property: Raw bytes of an instruction.

These are the bytes that were actually decoded to obtain the instruction AST.

SgAsmOperandList* const& SgAsmInstruction::get_operandList ( ) const

Property: AST node that holds all operands.

This is the SgAsmOperandList AST node that holds all the operands of this instruction. A separate node is necessary (rather than storing the operand list directly in the instruction node) due to limitations of ROSETTA.

void SgAsmInstruction::set_operandList ( SgAsmOperandList *const &  )

Property: AST node that holds all operands.

This is the SgAsmOperandList AST node that holds all the operands of this instruction. A separate node is necessary (rather than storing the operand list directly in the instruction node) due to limitations of ROSETTA.

size_t SgAsmInstruction::cacheLockCount ( ) const

Property: Cache lock count.

Number of locks held on this object, preventing the AST rooted at this node from being evicted from a cache.

Thread safety: This method is thread safe.

void SgAsmInstruction::adjustCacheLockCount ( int  increment)

Property: Cache lock count.

Number of locks held on this object, preventing the AST rooted at this node from being evicted from a cache.

Thread safety: This method is thread safe.

int64_t const& SgAsmInstruction::get_stackDeltaIn ( ) const

Property: Stack pointer at start of instruction relative to start of instruction's function.

If the stack delta was not computed, or could not be computed, or is a non-numeric value then the special value INVALID_STACK_DELTA is used.

void SgAsmInstruction::set_stackDeltaIn ( int64_t const &  )

Property: Stack pointer at start of instruction relative to start of instruction's function.

If the stack delta was not computed, or could not be computed, or is a non-numeric value then the special value INVALID_STACK_DELTA is used.

SgAsmExprListExp* const& SgAsmInstruction::get_semantics ( ) const

Property: Ordered list of instruction semantics.

If instruction semantics are available and attached to the instruction, then this subtree will contain a list of semantic side effects of the instruction. The semantics are attached by using the Rose::BinaryAnalysis::InstructionSemantics::StaticSemantics semantic domain.

void SgAsmInstruction::set_semantics ( SgAsmExprListExp *const &  )

Property: Ordered list of instruction semantics.

If instruction semantics are available and attached to the instruction, then this subtree will contain a list of semantic side effects of the instruction. The semantics are attached by using the Rose::BinaryAnalysis::InstructionSemantics::StaticSemantics semantic domain.

virtual std::string SgAsmInstruction::description ( ) const
inlinevirtual

Return a description of this instruction.

Descriptions are useful for generating comments in the disassembly listing to say what each instruction does when the audience is not well versed in that instruction set architecture. The base implementation always returns an empty string.

Reimplemented in SgAsmCilInstruction, SgAsmJvmInstruction, SgAsmM68kInstruction, SgAsmMipsInstruction, and SgAsmPowerpcInstruction.

Definition at line 39579 of file binaryInstruction.C.

size_t SgAsmInstruction::nOperands ( ) const

Number of operands.

SgAsmExpression* SgAsmInstruction::operand ( size_t  ) const

Nth operand.

If the operand index is out of range, then null is returned.

virtual bool SgAsmInstruction::terminatesBasicBlock ( )
virtual

Determines if this instruction normally terminates a basic block.

The analysis only looks at the individual instruction and therefore is not very sophisticated. For instance, a conditional branch will always terminate a basic block by this method even if its condition is opaque. The base class implementation always aborts; architecture-specific subclasses should override this to do something useful (pure virtual is not possible due to ROSETTA).

Reimplemented in SgAsmCilInstruction, SgAsmJvmInstruction, SgAsmM68kInstruction, SgAsmMipsInstruction, SgAsmNullInstruction, SgAsmPowerpcInstruction, and SgAsmX86Instruction.

virtual bool SgAsmInstruction::isFunctionCallFast ( const std::vector< SgAsmInstruction * > &  ,
rose_addr_t *  target,
rose_addr_t *  ret 
)
virtual

Returns true if the specified basic block looks like a function call.

This instruction object is only used to select the appropriate virtual method; the basic block to be analyzed is the first argument to the function. If the basic block looks like a function call then this method returns true. If (and only if) the target address is known (i.e., the address of the called function) then target is set to this address (otherwise target is unmodified). If the return address is known or can be guessed, then return_va is initialized to the return address, which is normally the fall-through address of the last instruction; otherwise the return_va is unmodified.

The "fast" and "slow" versions differ only in what kind of anlysis they do. The "fast" version typically looks only at instruction patterns while the slow version might incur more expense by looking at instruction semantics.

Reimplemented in SgAsmCilInstruction, SgAsmJvmInstruction, SgAsmM68kInstruction, SgAsmMipsInstruction, SgAsmNullInstruction, SgAsmPowerpcInstruction, and SgAsmX86Instruction.

virtual bool SgAsmInstruction::isFunctionCallSlow ( const std::vector< SgAsmInstruction * > &  ,
rose_addr_t *  target,
rose_addr_t *  ret 
)
virtual

Returns true if the specified basic block looks like a function call.

This instruction object is only used to select the appropriate virtual method; the basic block to be analyzed is the first argument to the function. If the basic block looks like a function call then this method returns true. If (and only if) the target address is known (i.e., the address of the called function) then target is set to this address (otherwise target is unmodified). If the return address is known or can be guessed, then return_va is initialized to the return address, which is normally the fall-through address of the last instruction; otherwise the return_va is unmodified.

The "fast" and "slow" versions differ only in what kind of anlysis they do. The "fast" version typically looks only at instruction patterns while the slow version might incur more expense by looking at instruction semantics.

Reimplemented in SgAsmCilInstruction, SgAsmJvmInstruction, SgAsmM68kInstruction, SgAsmMipsInstruction, SgAsmNullInstruction, SgAsmPowerpcInstruction, and SgAsmX86Instruction.

virtual bool SgAsmInstruction::isFunctionReturnFast ( const std::vector< SgAsmInstruction * > &  )
virtual

Returns true if the specified basic block looks like a function return.

This instruction object is only used to select the appropriate virtual method; the basic block to be analyzed is the first argument to the function.

The "fast" and "slow" versions differ only in what kind of anlysis they do. The "fast" version typically looks only at instruction patterns while the slow version might incur more expense by looking at instruction semantics.

Reimplemented in SgAsmCilInstruction, SgAsmJvmInstruction, SgAsmM68kInstruction, SgAsmMipsInstruction, SgAsmNullInstruction, SgAsmPowerpcInstruction, and SgAsmX86Instruction.

virtual bool SgAsmInstruction::isFunctionReturnSlow ( const std::vector< SgAsmInstruction * > &  )
virtual

Returns true if the specified basic block looks like a function return.

This instruction object is only used to select the appropriate virtual method; the basic block to be analyzed is the first argument to the function.

The "fast" and "slow" versions differ only in what kind of anlysis they do. The "fast" version typically looks only at instruction patterns while the slow version might incur more expense by looking at instruction semantics.

Reimplemented in SgAsmCilInstruction, SgAsmJvmInstruction, SgAsmM68kInstruction, SgAsmMipsInstruction, SgAsmNullInstruction, SgAsmPowerpcInstruction, and SgAsmX86Instruction.

bool SgAsmInstruction::isFirstInBlock ( )

Returns true if this instruction is the first instruction in a basic block.

This method looks only at the AST to make this determination.

bool SgAsmInstruction::isLastInBlock ( )

Returns true if this instruction is the last instruction in a basic block.

This method looks only at the AST to make this determination.

virtual Sawyer::Optional<rose_addr_t> SgAsmInstruction::branchTarget ( )
virtual

Obtains the virtual address for a branching instruction.

Returns the branch target address if this instruction is a branching instruction and the target is known; otherwise returns nothing.

Reimplemented in SgAsmCilInstruction, SgAsmJvmInstruction, SgAsmM68kInstruction, SgAsmMipsInstruction, SgAsmNullInstruction, and SgAsmX86Instruction.

virtual bool SgAsmInstruction::hasEffect ( )
virtual

Determines whether a single instruction has an effect.

An instruction has an effect if it does anything other than setting the instruction pointer to a concrete value. Instructions that have no effect are called "no-ops". The x86 NOP instruction is an example of a no-op, but there are others also.

The following information about x86 no-ops is largely from Cory Cohen at CMU/SEI. In the discussion that follows, we are careful to distinguish between NOP (the mneumonic for instructions 90, and 0f1f) and "no-op" (any instruction whose only effect is to advance the instruction pointer).

Opcode bytes Intel assembly syntax
-------------------- ----------------------
90 nop
89c0 mov eax,eax Intel's old recommended two-byte no-op was to
89c9 mov ecx,ecx move a register to itself... The second byte of these are mod/rm
89d2 mov edx,edx bytes, and can generally be substituded wherever you see 0xc0 in
89db mov ebx,ebx subsequent examples.
89e4 mov esp,esp
89ed mov ebp,ebp
89f6 mov esi,esi
89ff mov edi,edi
88c0 mov al,al The above are also available in 8-bit form with a leading byte of 0x88
6689c0 mov ax,ax and with an operand size prefix (0x66).
66666689c0 mov ax,ax The prefixes can be repeated. One source seemed to imply that up to
three are reliably supported by the actual Intel processors. ROSE
supports any number up to the maximum instruction size (varies by mode).
6688c0 mov al,al The operand size prefix can even be nonsensical.
8ac0 mov al,al These are also presumabely no-ops. As with most instructions, these
8bc0 mov eax,eax will accept operand size prefixes as well.
f090 lock nop Most of these instructions will accept a lock prefix as well, which does
f0f090 lock nop not materially affect the result. As before, they can occur repeatedly,
f066f090 lock nop and even in wacky combinations.
f066f06666f0f066f090 lock nop
f290 repne nop Cory Cohen strongly suspects that the other instruction prefixes are
f390 rep nop ignored as well, although to be complete, we might want to conduct a
2690 es nop few tests into the behavior of common processors.
2e90 cs nop
3690 ss nop
3e90 ds nop
6490 fs nop
6590 gs nop
6790 nop
8d00 lea eax,[eax] Intel's old recommendation for larger no-ops was to use the LEA
8d09 lea ecx,[ecx] instruction in various dereferencing modes.
8d12 lea edx,[edx]
8d1b lea ebx,[ebx]
8d36 lea esi,[esi]
8d3f lea edi,[edi]
8d4000 lea eax,[eax+0x0]
8d4900 lea ecx,[ecx+0x0]
8d5200 lea edx,[edx+0x0]
8d5b00 lea ebx,[ebx+0x0]
8d7600 lea esi,[esi+0x0]
8d7f00 lea edi,[edi+0x0]
8d8000000000 lea eax,[eax+0x0] This last block is really the [reg*0x1+0x0] dereferencing mode.
8d8900000000 lea ecx,[ecx+0x0]
8d9200000000 lea edx,[edx+0x0]
8d9b00000000 lea ebx,[ebx+0x0]
8db600000000 lea esi,[esi+0x0]
8dbf00000000 lea edi,[edi+0x0]
8d0420 lea eax,[eax] Then there's funky equivalents involving SIB bytes.
8d0c21 lea ecx,[ecx]
8d1422 lea edx,[edx]
8d1c23 lea ebx,[ebx]
8d2424 lea esp,[esp]
8d3426 lea esi,[esi]
8d3c27 lea edi,[edi]
8d442000 lea eax,[eax+0x0]
8d4c2100 lea ecx,[ecx+0x0]
8d542200 lea edx,[edx+0x0]
8d5c2300 lea ebx,[ebx+0x0]
8d642400 lea esp,[esp+0x0]
8d742600 lea esi,[esi+0x0]
8d7c2700 lea edi,[edi+0x0]
8d842000000000 lea eax,[eax+0x0]
8d8c2100000000 lea ecx,[ecx+0x0]
8d942200000000 lea edx,[edx+0x0]
8d9c2300000000 lea ebx,[ebx+0x0]
8da42400000000 lea esp,[esp+0x0]
8db42600000000 lea esi,[esi+0x0]
8dbc2700000000 lea edi,[edi+0x0]
8d2c2d00000000 lea ebp,[ebp+0x0] The EBP variants don't exactly follow the pattern above.
8d6c2500 lea ebp,[ebp+0x0]
8dac2500000000 lea ebp,[ebp+0x0]
0f1f00 nop [eax] P4+ adds the 0f1f instruction. Each of these can be prefixed with the
0f1f4000 nop [eax+0x0] 0x66 operand size prefix. In fact, Intel recommends doing this now
0f1f440000 nop [eax+0x0] for the optimally efficient 6- and 9-byte sequences.
0f1f8000000000 nop [eax+0x0]
0f1f840000000000 nop [eax+0x0]
0f0dxx nop [xxx] The latest version of the manual implies that this sequence is also
reserved for NOP, although I can find almost no references to it except
in the latest instruction manual on page A-13 of volume 2B. It's also
mentioned on x86asm.net. [CORY 2010-04]
d9d0 fnop These aren't really no-ops on the chip, but are no-ops from the
9b wait program's perspective. Most of these instructions are related to
0f08 invd improving cache efficiency and performance, but otherwise do not
0f09 wbinvd affect the program behavior.
0f01c9 mwait
0f0138 invlpg [eax]
0f01bf00000000 invlpg [edi+0x0] and more...
0f18 /0 prefetchnta [xxx]
0f18 /1 prefetch0 [xxx]
0f18 /2 prefetch1 [xxx]
0f18 /3 prefetch2 [xxx]
0fae /5 lfence [xxx]
0fae /6 mfence [xxx]
0fae /7 sfence [xxx]
0f18xx through 0f1exx This opcode rante is officially undefined but is probably reserved
for no-ops as well. Any instructions encountered in this range are
probably consequences of bad code and should be ingored.
JMP, Jcc, PUSH/RET, etc. Branches are considered no-ops if they can be proven to always branch
to the fall-through address.
virtual bool SgAsmInstruction::hasEffect ( const std::vector< SgAsmInstruction * > &  ,
bool  allow_branch = false,
bool  relax_stack_semantics = false 
)
virtual

Determine if an instruction sequence has an effect.

A sequence of instructions has an effect if it does something other than setting the instruction pointer to a concrete value.

This is mostly a wrapper around the NoOperation analysis. The allow_branch and relax_stack_semantics are no longer supported but perhaps will be added eventually to the NoOperation analysis.

virtual std::vector<std::pair<size_t,size_t> > SgAsmInstruction::findNoopSubsequences ( const std::vector< SgAsmInstruction * > &  insns,
bool  allow_branch = false,
bool  relax_stack_semantics = false 
)
virtual

Determines what subsequences of an instruction sequence have no cumulative effect.

The return value is a vector of pairs where each pair is the starting index and length of subsequence. The algorithm we use is to compute the machine state after each instruction and then look for pairs of states that are identical except for the instruction pointer.

This is mostly a wrapper around the NoOperation analysis. The allow_branch and relax_stack_semantics are no longer supported but perhaps will be added eventually to the NoOperation analysis.

virtual Rose::BinaryAnalysis::AddressSet SgAsmInstruction::getSuccessors ( bool &  complete)
virtual

Control flow successors for a single instruction.

The return value does not consider neighboring instructions, and therefore is quite naive. It returns only the information it can glean from this single instruction. If the returned set of virtual instructions is fully known then the complete argument will be set to true, otherwise false. The base class implementation always aborts()–it must be defined in an architecture-specific subclass (pure virtual is not possible due to ROSETTA).

Reimplemented in SgAsmCilInstruction, SgAsmJvmInstruction, SgAsmM68kInstruction, SgAsmMipsInstruction, SgAsmNullInstruction, SgAsmPowerpcInstruction, and SgAsmX86Instruction.

virtual Rose::BinaryAnalysis::AddressSet SgAsmInstruction::getSuccessors ( const std::vector< SgAsmInstruction * > &  basicBlock,
bool &  complete,
const Rose::BinaryAnalysis::MemoryMap::Ptr initial_memory = Rose::BinaryAnalysis::MemoryMap::Ptr() 
)
virtual

Control flow successors for a basic block.

The basicBlock argument is a vector of instructions that is assumed to be a basic block that is entered only at the first instruction and exits only at the last instruction. A memory map can supply initial values for the analysis' memory state. The return value is a set of control flow successor virtual addresses, and the complete argument return value indicates whether the returned set is known to be complete (aside from interrupts, faults, etc). The base class implementation just calls the single-instruction version, so architecture-specific subclasses might want to override this to do something more sophisticated.

Reimplemented in SgAsmCilInstruction, SgAsmM68kInstruction, SgAsmNullInstruction, and SgAsmX86Instruction.

virtual size_t SgAsmInstruction::get_size ( ) const
virtual

Returns the size of an instruction in bytes.

This is only a convenience function that returns the size of the instruction's raw byte vector. If an instruction or its arguments are modified, then the size returned by this function might not reflect the true size of the modified instruction if it were to be reassembled.

virtual bool SgAsmInstruction::isUnknown ( ) const
virtual

Returns true if this instruction is the special "unknown" instruction.

Each instruction architecture in ROSE defines an "unknown" instruction to be used when the disassembler is unable to create a real instruction. This can happen, for instance, if the bit pattern does not represent a valid instruction for the architecture.

Reimplemented in SgAsmCilInstruction, SgAsmJvmInstruction, SgAsmM68kInstruction, SgAsmMipsInstruction, SgAsmNullInstruction, SgAsmPowerpcInstruction, and SgAsmX86Instruction.

virtual unsigned SgAsmInstruction::get_anyKind ( ) const
virtual

Returns instruction kind for any architecture.

Instruction kinds are specific to the architecture so it doesn't make sense to compare an instruction kind from x86 with an instruction kind from m68k. However, this virtual function exists so that we don't need to implement switch statements every time we want to compare two instructions from the same architecture. For instance, instead of code like this:

bool areSame(SgAsmInstruction *a, SgAsmInstruction *b) {
if (a->variantT() != b->variantT())
return false;
if (SgAsmM68kInstruction *aa = isSgAsmM68kInstruction(a)) {
SgAsmM68kInstruction *bb = isSgAsmM68kInstruction(b);
return aa->get_kind() == bb->get_kind();
}
if (SgAsmMipsInstruction *aa = isSgAsmMipsInstruction(a)) {
SgAsmMipsInstruction *bb = isSgAsmMipsInstruction(b);
return aa->get_kind() == bb->get_kind();
}
...
... // and many others
...
ASSERT_not_reachable("architecture is not implemented yet");
}

we can write future-proof code:

bool areSame(SgAsmInstruction *a, SgAsmInstruction *b) {
return a->variantT()==b->variantT() && a->get_anyKind()==b->get_anyKind();
}

Reimplemented in SgAsmCilInstruction, SgAsmJvmInstruction, SgAsmM68kInstruction, SgAsmMipsInstruction, SgAsmNullInstruction, SgAsmPowerpcInstruction, and SgAsmX86Instruction.

virtual std::string SgAsmInstruction::toString ( ) const
virtual

Converts the instruction to a string.

The return value is an address, colon, mnemonic, and arguments. Only one space is used between the parts.

virtual std::set<rose_addr_t> SgAsmInstruction::explicitConstants ( ) const
virtual

Explicit constants.

Return the set of integer constants that appear explicitly in the instruction's operands. These are called "immediates" for some architectures such as X86.

size_t SgAsmInstruction::semanticFailure ( ) const

Property: Whether instruction semantics failed at this location.

This property is incremented by various analyses that evaluate instructions semantically when semantics fails in a way that is not recoverable. Some analyses can work around failed semantics by operating in a degraded mode, and it is up to the analysis whether to increment this property.

Thread safety: This method is thread safe.

void SgAsmInstruction::semanticFailure ( size_t  )

Property: Whether instruction semantics failed at this location.

This property is incremented by various analyses that evaluate instructions semantically when semantics fails in a way that is not recoverable. Some analyses can work around failed semantics by operating in a degraded mode, and it is up to the analysis whether to increment this property.

Thread safety: This method is thread safe.

void SgAsmInstruction::incrementSemanticFailure ( )

Property: Whether instruction semantics failed at this location.

This property is incremented by various analyses that evaluate instructions semantically when semantics fails in a way that is not recoverable. Some analyses can work around failed semantics by operating in a degraded mode, and it is up to the analysis whether to increment this property.

Thread safety: This method is thread safe.

bool SgAsmInstruction::normalizeOperands ( )

Rewrite certain addressing modes for operands.

The addressing mode: REG1 + REG2 * SIZE + OFFSET is changed from (+ (+ REG1 (* REG2 SIZE)) OFFSET) to (+ (+ REG1 OFFSET) (* REG2 SIZE)), which during instruction semantic executions causes the base register and offset to be added first to obtain the starting address of an array, and then an additional offset added to obtain the address of the desired element of that array.

Returns true if anything changed, false otherwise.

void SgAsmInstruction::initializeProperties ( )
protected

Initialize all properties that have explicit initial values.

This function is mostly for use in user-defined constructors where the user desires to initialize all the properties but does not know the names of the data members that store the property values. This function initializes the properties that have explicit initializations within this class, but does not recursively initialize base classes.

Member Data Documentation

const int64_t SgAsmInstruction::INVALID_STACK_DELTA
static

Represents an invalid stack delta.

This value is used for the result of a stack delta analysis stored in the instruction AST if the stack delta analysis was not run or did not produce a numeric result.

Definition at line 39568 of file binaryInstruction.C.


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