ROSE  0.11.145.0
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 41 of file Function.h.

#include <Rose/BinaryAnalysis/Partitioner2/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
 Read-only property: Entry address. More...
 
void insertReasons (unsigned reasons)
 Insert additional function reason bits. More...
 
void eraseReasons (unsigned reasons)
 Remove function reason bits. 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< DataBlockPtr > & dataBlocks () const
 Returns data blocks owned by this function. More...
 
bool insertDataBlock (const DataBlockPtr &)
 Add a data block to this function. More...
 
DataBlockPtr eraseDataBlock (const DataBlockPtr &)
 Remove specified or equivalent data block from this function. More...
 
DataBlockPtr dataBlockExists (const DataBlockPtr &) const
 Determine if this function contains the specified data block, or equivalent. More...
 
AddressIntervalSet dataAddresses () const
 Addresses that are part of static data. 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...
 
size_t nDataBlocks () const
 Number of data 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
 Property: Optional function name. More...
 
void name (const std::string &)
 Property: Optional function name. More...
 
const std::string & demangledName () const
 Property: Optional demangled name. More...
 
void demangledName (const std::string &)
 Property: Optional demangled name. More...
 
const std::string & comment () const
 Property: Optional function comment. More...
 
void comment (const std::string &)
 Property: Optional function comment. More...
 
const SourceLocationsourceLocation () const
 Property: Location of function definition in source code, if known.
 
void sourceLocation (const SourceLocation &)
 Property: Location of function definition in source code, if known.
 
unsigned reasons () const
 Property: Bit vector of function reasons. More...
 
void reasons (unsigned)
 Property: Bit vector of function reasons. More...
 
const std::string & reasonComment () const
 Property: Additional comment for why function was detected.
 
void reasonComment (const std::string &)
 Property: Additional comment for why function was detected.
 
InstructionSemantics::BaseSemantics::SValuePtr stackDelta () const
 Property: Stack delta. More...
 
int64_t stackDeltaConcrete () const
 Property: Stack delta. More...
 
InstructionSemantics::BaseSemantics::SValuePtr stackDeltaOverride () const
 Property: Stack delta override. More...
 
void stackDeltaOverride (const InstructionSemantics::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::DefinitionPtr callingConventionDefinition ()
 Property: Best calling convention definition. More...
 
void callingConventionDefinition (const CallingConvention::DefinitionPtr &)
 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 50 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 44 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 
)
static

Static allocating constructor.

Creates a new function having the specified characteristics.

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

Static allocating constructor.

Creates a new function having the specified characteristics.

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

Read-only property: 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.

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

Property: Optional function name.

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

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

Property: Optional function name.

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

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

Property: 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 &  )

Property: 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.

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

Property: Optional function comment.

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

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

Property: Optional function comment.

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

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

Property: Bit vector of function reasons.

These are SgAsmFunction::FunctionReason bits.

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

Property: Bit vector of function reasons.

These are SgAsmFunction::FunctionReason bits.

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

Insert additional function reason bits.

The high-order bits 16 bits are OR'd into the reasons property, while the low-order 16 bits given in the argument replace the low-order 16 bits stored in the reasons property.

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

Remove function reason bits.

Removes the high-order 16 bits that appear in the argument from the reasons property. The low-order 16 bits are all cleared if any of the low-order 16 bits of the argument are set.

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

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::attachFunction).

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

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

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

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.

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

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.

const std::vector<DataBlockPtr>& Rose::BinaryAnalysis::Partitioner2::Function::dataBlocks ( ) const

Returns data blocks owned by this function.

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

bool Rose::BinaryAnalysis::Partitioner2::Function::insertDataBlock ( const DataBlockPtr )

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.

DataBlockPtr Rose::BinaryAnalysis::Partitioner2::Function::eraseDataBlock ( const DataBlockPtr )

Remove specified or equivalent data block from this function.

If this function is in a detached state (i.e., not part of the CFG/AUM) then the specified data block or equivalent data block is removed from this function. Returns the data block that was erased, or null if none was erased.

It is an error to invoke this method on function that is attached to the CFG/AUM, for which isFrozen returns true. This method is a no-op if the specified data block is a null pointer.

DataBlockPtr Rose::BinaryAnalysis::Partitioner2::Function::dataBlockExists ( const DataBlockPtr ) const

Determine if this function contains the specified data block, or equivalent.

If this function owns the specified data block or an equivalent data block then this method returns a pointer to the existing data block, otherwise it returns the null pointer.

Thread safety: This method is not thread safe.

AddressIntervalSet Rose::BinaryAnalysis::Partitioner2::Function::dataAddresses ( ) const

Addresses that are part of static data.

Returns all addresses that are part of static data.

Thread safety: This method is not thread safe.

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

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.

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::functionIsThunk that is a stronger predicate and also returns the address of the thunk target.

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

Number of basic blocks in the function.

size_t Rose::BinaryAnalysis::Partitioner2::Function::nDataBlocks ( ) const

Number of data blocks in the function.

InstructionSemantics::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.

InstructionSemantics::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 InstructionSemantics::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

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.

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

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.

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

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.

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

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.

CallingConvention::DefinitionPtr Rose::BinaryAnalysis::Partitioner2::Function::callingConventionDefinition ( )

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.

void Rose::BinaryAnalysis::Partitioner2::Function::callingConventionDefinition ( const CallingConvention::DefinitionPtr )

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.

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

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.


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