ROSE  0.9.9.139
Public Types | Public Member Functions | Protected Member Functions | List of all members
Rose::BinaryAnalysis::Partitioner2::Function Class Reference

Description

Describes one function.

A function consists of one or more basic blocks. Exactly one block is special in that it serves as the entry point when this function is invoked from elsewhere; the only incoming inter-function edges are to this entry block. This function may have outgoing inter-function edges that represent invocations of other functions, and the targets of all such edges will be the entry block of another function. A function may also own zero or more data blocks consisting of a base address and size (type).

A function may exist as part of the partitioner's control flow graph, or in a detached state. When a function is represented by the control flow graph then it is in a frozen state, meaning that its basic blocks and data blocks cannot be adjusted adjusted; one must use the partitioner interface to do so.

Definition at line 39 of file Function.h.

#include <Function.h>

Inheritance diagram for Rose::BinaryAnalysis::Partitioner2::Function:
Inheritance graph
[legend]
Collaboration diagram for Rose::BinaryAnalysis::Partitioner2::Function:
Collaboration graph
[legend]

Public Types

enum  Ownership {
  OWN_UNOWNED =0,
  OWN_EXPLICIT,
  OWN_PROVISIONAL
}
 Manner in which a function owns a block. More...
 
typedef FunctionPtr Ptr
 Shared-ownership pointer for function. More...
 
- Public Types inherited from Sawyer::Attribute::Storage<>
typedef SynchronizationTraits< Sawyer::SingleThreadedTagSync
 

Public Member Functions

rose_addr_t address () const
 Return the entry address. More...
 
const std::set< rose_addr_t > & basicBlockAddresses () const
 Returns basic block addresses. More...
 
bool ownsBasicBlock (rose_addr_t bblockVa) const
 Predicate to test whether a function owns a basic block address. More...
 
bool insertBasicBlock (rose_addr_t bblockVa)
 Add a basic block to this function. More...
 
void eraseBasicBlock (rose_addr_t bblockVa)
 Remove a basic block from this function. More...
 
const std::vector< DataBlock::Ptr > & dataBlocks () const
 Returns data blocks owned by this function. More...
 
bool insertDataBlock (const DataBlock::Ptr &)
 Add a data block to this function. More...
 
void eraseDataBlock (const DataBlock::Ptr &)
 Remove a data block from this function. More...
 
bool isFrozen () const
 Determines whether a function is frozen. More...
 
bool isThunk () const
 True if function is a thunk. More...
 
size_t nBasicBlocks () const
 Number of basic blocks in the function. More...
 
std::string printableName () const
 A printable name for the function. More...
 
const Sawyer::Cached< bool > & isNoop () const
 Cached results of function no-op analysis. More...
 
const std::string & name () const
 Optional function name. More...
 
void name (const std::string &name)
 Optional function name. More...
 
const std::string & demangledName () const
 Optional demangled name. More...
 
void demangledName (const std::string &name)
 Optional demangled name. More...
 
const std::string & comment () const
 Optional function comment. More...
 
void comment (const std::string &s)
 Optional function comment. More...
 
unsigned reasons () const
 Function reasons. More...
 
void reasons (unsigned reasons)
 Function reasons. More...
 
void insertReasons (unsigned reasons)
 Function reasons. More...
 
void eraseReasons (unsigned reasons)
 Function reasons. More...
 
InstructionSemantics2::BaseSemantics::SValuePtr stackDelta () const
 Property: Stack delta. More...
 
int64_t stackDeltaConcrete () const
 Property: Stack delta. More...
 
InstructionSemantics2::BaseSemantics::SValuePtr stackDeltaOverride () const
 Property: Stack delta override. More...
 
void stackDeltaOverride (const InstructionSemantics2::BaseSemantics::SValuePtr &delta)
 Property: Stack delta override. More...
 
const StackDelta::AnalysisstackDeltaAnalysis () const
 Property: Stack delta analysis results. More...
 
StackDelta::AnalysisstackDeltaAnalysis ()
 Property: Stack delta analysis results. More...
 
const CallingConvention::AnalysiscallingConventionAnalysis () const
 Property: Calling convention analysis results. More...
 
CallingConvention::AnalysiscallingConventionAnalysis ()
 Property: Calling convention analysis results. More...
 
CallingConvention::Definition::Ptr callingConventionDefinition ()
 Property: Best calling convention definition. More...
 
void callingConventionDefinition (const CallingConvention::Definition::Ptr &ccdef)
 Property: Best calling convention definition. More...
 
- Public Member Functions inherited from Sawyer::SharedObject
 SharedObject ()
 Default constructor. More...
 
 SharedObject (const SharedObject &)
 Copy constructor. More...
 
virtual ~SharedObject ()
 Virtual destructor. More...
 
SharedObjectoperator= (const SharedObject &)
 Assignment. More...
 
- Public Member Functions inherited from Sawyer::Attribute::Storage<>
 Storage ()
 Default constructor. More...
 
 Storage (const Storage &other)
 Copy constructor. More...
 
Storageoperator= (const Storage &other)
 Assignment operator. More...
 
bool attributeExists (Id id) const
 Check attribute existence. More...
 
void eraseAttribute (Id id)
 Erase an attribute. More...
 
void clearAttributes ()
 Erase all attributes. More...
 
void setAttribute (Id id, const T &value)
 Store an attribute. More...
 
bool setAttributeMaybe (Id id, const T &value)
 Store an attribute if not already present. More...
 
getAttribute (Id id) const
 Get an attribute that is known to exist. More...
 
attributeOrElse (Id id, const T &dflt) const
 Return an attribute or a specified value. More...
 
attributeOrDefault (Id id) const
 Return an attribute or a default-constructed value. More...
 
Sawyer::Optional< T > optionalAttribute (Id id) const
 Return the attribute as an optional value. More...
 
size_t nAttributes () const
 Number of attributes stored. More...
 
std::vector< IdattributeIds () const
 Returns ID numbers for all IDs stored in this container. More...
 

Static Public Member Functions

static Ptr instance (rose_addr_t entryVa, const std::string &name="", unsigned reasons=0)
 Static allocating constructor. More...
 
static Ptr instance (rose_addr_t entryVa, unsigned reasons)
 Static allocating constructor. More...
 

Protected Member Functions

 Function (rose_addr_t entryVa, const std::string &name, unsigned reasons)
 

Member Typedef Documentation

Shared-ownership pointer for function.

Definition at line 48 of file Function.h.

Member Enumeration Documentation

Manner in which a function owns a block.

Enumerator
OWN_UNOWNED 

Function does not own the block.

OWN_EXPLICIT 

Function owns the block explicitly, the normal ownership.

OWN_PROVISIONAL 

Function might own the block in the future.

Definition at line 42 of file Function.h.

Member Function Documentation

static Ptr Rose::BinaryAnalysis::Partitioner2::Function::instance ( rose_addr_t  entryVa,
const std::string &  name = "",
unsigned  reasons = 0 
)
inlinestatic

Static allocating constructor.

Creates a new function having the specified characteristics.

Definition at line 110 of file Function.h.

static Ptr Rose::BinaryAnalysis::Partitioner2::Function::instance ( rose_addr_t  entryVa,
unsigned  reasons 
)
inlinestatic

Static allocating constructor.

Creates a new function having the specified characteristics.

Definition at line 113 of file Function.h.

rose_addr_t Rose::BinaryAnalysis::Partitioner2::Function::address ( ) const
inline

Return the entry address.

The entry address also serves as an identifier for the function since the CFG can only hold one function per entry address. Detached functions need not have unique entry addresses.

Definition at line 120 of file Function.h.

const std::string& Rose::BinaryAnalysis::Partitioner2::Function::name ( ) const
inline

Optional function name.

This is the official name. See also demangledName, which can also return the value of this Naming tips property.

Definition at line 127 of file Function.h.

Referenced by demangledName().

void Rose::BinaryAnalysis::Partitioner2::Function::name ( const std::string &  name)
inline

Optional function name.

This is the official name. See also demangledName, which can also return the value of this Naming tips property.

Definition at line 128 of file Function.h.

References name().

Referenced by name().

const std::string& Rose::BinaryAnalysis::Partitioner2::Function::demangledName ( ) const

Optional demangled name.

This property holds the override string to use as the demangled name. If set to the empty string, then reading this property returns the true Naming tips instead.

void Rose::BinaryAnalysis::Partitioner2::Function::demangledName ( const std::string &  name)
inline

Optional demangled name.

This property holds the override string to use as the demangled name. If set to the empty string, then reading this property returns the true Naming tips instead.

Definition at line 138 of file Function.h.

References name().

const std::string& Rose::BinaryAnalysis::Partitioner2::Function::comment ( ) const
inline

Optional function comment.

Comments are multi-line, plain-text (not HTML), ASCII.

Definition at line 146 of file Function.h.

void Rose::BinaryAnalysis::Partitioner2::Function::comment ( const std::string &  s)
inline

Optional function comment.

Comments are multi-line, plain-text (not HTML), ASCII.

Definition at line 147 of file Function.h.

unsigned Rose::BinaryAnalysis::Partitioner2::Function::reasons ( ) const
inline

Function reasons.

These are SgAsmFunction::FunctionReason bits.

Definition at line 153 of file Function.h.

Referenced by insertReasons().

void Rose::BinaryAnalysis::Partitioner2::Function::reasons ( unsigned  reasons)
inline

Function reasons.

These are SgAsmFunction::FunctionReason bits.

Definition at line 154 of file Function.h.

References reasons().

Referenced by reasons().

void Rose::BinaryAnalysis::Partitioner2::Function::insertReasons ( unsigned  reasons)
inline

Function reasons.

These are SgAsmFunction::FunctionReason bits.

Definition at line 155 of file Function.h.

References reasons().

void Rose::BinaryAnalysis::Partitioner2::Function::eraseReasons ( unsigned  reasons)
inline

Function reasons.

These are SgAsmFunction::FunctionReason bits.

Definition at line 156 of file Function.h.

const std::set<rose_addr_t>& Rose::BinaryAnalysis::Partitioner2::Function::basicBlockAddresses ( ) const
inline

Returns basic block addresses.

Because functions can exist in a detatched state, a function stores basic block addresses rather than basic blocks. This allows a function to indicate which blocks will be ultimately part of its definition without requiring that the blocks actually exist. When a detached function is inserted into the CFG then basic block placeholders will be created for any basic blocks that don't exist in the CFG (see Partitioner::insertFunction).

Definition at line 164 of file Function.h.

bool Rose::BinaryAnalysis::Partitioner2::Function::ownsBasicBlock ( rose_addr_t  bblockVa) const
inline

Predicate to test whether a function owns a basic block address.

Definition at line 167 of file Function.h.

bool Rose::BinaryAnalysis::Partitioner2::Function::insertBasicBlock ( rose_addr_t  bblockVa)
inline

Add a basic block to this function.

This method does not adjust the partitioner CFG. Basic blocks cannot be added by this method when this function is attached to the CFG since it would cause the CFG to become outdated with respect to this function, but as long as the function is detached blocks can be inserted and removed arbitrarily. If the specified address is already part of the function then it is not added a second time.

Returns true if the block is inserted, false if the block was already part of this function.

Definition at line 179 of file Function.h.

void Rose::BinaryAnalysis::Partitioner2::Function::eraseBasicBlock ( rose_addr_t  bblockVa)
inline

Remove a basic block from this function.

This method does not adjust the partitioner CFG. Basic blocks cannot be removed by this method when this function is attached to the CFG since it would cause the CFG to become outdated with respect to this function, but as long as the function is detached blocks can be inserted and removed arbitrarily. If the specified address is not a basic block address for this function then this is a no-op. Removing the function's entry address is never permitted.

Definition at line 192 of file Function.h.

const std::vector<DataBlock::Ptr>& Rose::BinaryAnalysis::Partitioner2::Function::dataBlocks ( ) const
inline

Returns data blocks owned by this function.

Returns the data blocks that are owned by this function in order of their starting address.

Definition at line 201 of file Function.h.

bool Rose::BinaryAnalysis::Partitioner2::Function::insertDataBlock ( const DataBlock::Ptr )

Add a data block to this function.

This method does not adjust the partitioner CFG. Data blocks cannot be added by this method when this function is attached to the CFG since it would cause the CFG to become outdated with respect to this function, but as long as the function is detached blocks can be inserted and removed arbitrarily. The specified data block cannot be a null pointer. If the data block is already owned by this function then nothing happens and this method returns false; otherwise the data block is inserted and the method returns true.

void Rose::BinaryAnalysis::Partitioner2::Function::eraseDataBlock ( const DataBlock::Ptr )

Remove a data block from this function.

This method does not adjust the partitioner CFG. Data blocks cannot be removed by this method when this function is attached to the CFG since it would cause the CFG to become outdated with respect to this function, but as long as the function is detached blocks can be inserted and removed arbitrarily. If the specified pointer is null or the data block does not exist in this function then this method is a no-op.

bool Rose::BinaryAnalysis::Partitioner2::Function::isFrozen ( ) const
inline

Determines whether a function is frozen.

The ownership relations (instructions, basic blocks, and data blocks) cannot be adjusted while a function is in a frozen state. All functions that are represented in the control flow graph are in a frozen state; detaching a function from the CFG thaws it.

Definition at line 221 of file Function.h.

bool Rose::BinaryAnalysis::Partitioner2::Function::isThunk ( ) const

True if function is a thunk.

This function is a thunk if it is marked as such in its reason codes via SgAsmFunction::FUNC_THUNK and it has exactly one basic block.

See also, Partitioner::functionThunkTarget that is a stronger predicate and also returns the address of the thunk target.

size_t Rose::BinaryAnalysis::Partitioner2::Function::nBasicBlocks ( ) const
inline

Number of basic blocks in the function.

Definition at line 233 of file Function.h.

InstructionSemantics2::BaseSemantics::SValuePtr Rose::BinaryAnalysis::Partitioner2::Function::stackDelta ( ) const

Property: Stack delta.

The set or computed stack delta. If a stack delta override has been set (stackDeltaOverride) then that value is returned. Otherwise, if the stack delta analysis has been run and a stack delta is known, it is returned. Otherwise a null pointer is returned. Calling this method returns previously computed values rather than running a potentially expensive analysis.

int64_t Rose::BinaryAnalysis::Partitioner2::Function::stackDeltaConcrete ( ) const

Property: Stack delta.

The set or computed stack delta. If a stack delta override has been set (stackDeltaOverride) then that value is returned. Otherwise, if the stack delta analysis has been run and a stack delta is known, it is returned. Otherwise a null pointer is returned. Calling this method returns previously computed values rather than running a potentially expensive analysis.

InstructionSemantics2::BaseSemantics::SValuePtr Rose::BinaryAnalysis::Partitioner2::Function::stackDeltaOverride ( ) const

Property: Stack delta override.

This is the value returned by stackDelta in preference to using the stack delta analysis results. It allows a user to override the stack delta analysis. The partitioner will not run stack delta analysis if an override value is set.

void Rose::BinaryAnalysis::Partitioner2::Function::stackDeltaOverride ( const InstructionSemantics2::BaseSemantics::SValuePtr delta)

Property: Stack delta override.

This is the value returned by stackDelta in preference to using the stack delta analysis results. It allows a user to override the stack delta analysis. The partitioner will not run stack delta analysis if an override value is set.

const StackDelta::Analysis& Rose::BinaryAnalysis::Partitioner2::Function::stackDeltaAnalysis ( ) const
inline

Property: Stack delta analysis results.

This property holds the results from stack delta analysis. It contains the stack entry and exit values for each basic block computed from data flow, and the overall stack delta for the function. The analysis is not updated by this class; objects of this class only store the results provided by something else.

The hasResults and didConverge methods invoked on the return value will tell you whether an analysis has run and whether the results are valid, respectively.

Definition at line 267 of file Function.h.

StackDelta::Analysis& Rose::BinaryAnalysis::Partitioner2::Function::stackDeltaAnalysis ( )
inline

Property: Stack delta analysis results.

This property holds the results from stack delta analysis. It contains the stack entry and exit values for each basic block computed from data flow, and the overall stack delta for the function. The analysis is not updated by this class; objects of this class only store the results provided by something else.

The hasResults and didConverge methods invoked on the return value will tell you whether an analysis has run and whether the results are valid, respectively.

Definition at line 268 of file Function.h.

const CallingConvention::Analysis& Rose::BinaryAnalysis::Partitioner2::Function::callingConventionAnalysis ( ) const
inline

Property: Calling convention analysis results.

This property holds the results from calling convention analysis. It contains information about what registers and stack locations are accessed and whether they serve as inputs or outputs and which registers are used but restored before returning (callee-saved). It also stores a concrete stack delta. The analysis is not updated by this class; objects of this class only store the results provided by something else.

The analysis itself does not fully describe a calling convention since a function might not use all features of the calling convention. For instance, a no-op function could match any number of calling convention definitions.

The hasResults and didConverge methods invoked on the return value will tell you whether an analysis has run and whether the results are valid, respectively.

Definition at line 285 of file Function.h.

CallingConvention::Analysis& Rose::BinaryAnalysis::Partitioner2::Function::callingConventionAnalysis ( )
inline

Property: Calling convention analysis results.

This property holds the results from calling convention analysis. It contains information about what registers and stack locations are accessed and whether they serve as inputs or outputs and which registers are used but restored before returning (callee-saved). It also stores a concrete stack delta. The analysis is not updated by this class; objects of this class only store the results provided by something else.

The analysis itself does not fully describe a calling convention since a function might not use all features of the calling convention. For instance, a no-op function could match any number of calling convention definitions.

The hasResults and didConverge methods invoked on the return value will tell you whether an analysis has run and whether the results are valid, respectively.

Definition at line 286 of file Function.h.

CallingConvention::Definition::Ptr Rose::BinaryAnalysis::Partitioner2::Function::callingConventionDefinition ( )
inline

Property: Best calling convention definition.

This is the best calling convention definition for this function. Calling conventions have two parts: (1) the behavior of the function such as which locations serve as inputs (read-before-write) and outputs (write-last), and callee-saved locations (read-before-write and write-last and same initial and final value), and (2) a list of well-known calling convention definitions that match the function's behavior. More than one definition can match. This property holds one defintion which is usually the "best" one.

Definition at line 298 of file Function.h.

void Rose::BinaryAnalysis::Partitioner2::Function::callingConventionDefinition ( const CallingConvention::Definition::Ptr ccdef)
inline

Property: Best calling convention definition.

This is the best calling convention definition for this function. Calling conventions have two parts: (1) the behavior of the function such as which locations serve as inputs (read-before-write) and outputs (write-last), and callee-saved locations (read-before-write and write-last and same initial and final value), and (2) a list of well-known calling convention definitions that match the function's behavior. More than one definition can match. This property holds one defintion which is usually the "best" one.

Definition at line 299 of file Function.h.

std::string Rose::BinaryAnalysis::Partitioner2::Function::printableName ( ) const

A printable name for the function.

Returns a string like 'function 0x10001234 "main"'. The function name is not included if this function has neither a demangled name nor a true name. The demangledName overrides the true Naming tips.

const Sawyer::Cached<bool>& Rose::BinaryAnalysis::Partitioner2::Function::isNoop ( ) const
inline

Cached results of function no-op analysis.

If a value is cached, then the analysis has run and the cached value is true if the analysis proved that the function is a no-op.

Definition at line 312 of file Function.h.


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