ROSE  0.11.145.0
Classes | Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
Rose::BinaryAnalysis::AsmFunctionIndex Class Reference

Description

Functions indexed by entry address.

This class is designed to be a highly-configurable way to print a table describing known functions. The way it works is the user adds functions to the AsmFunctionIndex object (explicitly, or by having this object traverse an AST), and then prints the object to an std::ostream. The index contains a list of functions to be included in the index, but it also contains a list of callbacks responsible for printing the table column headers and data.

For instance, to print an index of all functions sorted by function name and using the default table style, simply invoke this code:

#include <Rose/BinaryAnalysis/AsmFunctionIndex.h>
SgProject *project = ...;
std::cout <<AsmFunctionIndex(project).sort_by_name();

If you want a list of functions sorted by decreasing size in bytes, you could do this:

std::cout <<AsmFunctionIndex(project).sort_by_byte_size().reverse();

Here's an example of augmenting the function index so that it always sorts the functions by entry address and it prints an extra column named "Hash" that consists of the first 16 characters of some computed function hash.

class MyFunctionIndex: public AsmFunctionIndex {
public:
struct HashCallback: public OutputCallback {
HashCallback(): OutputCallback("Hash", 16) {}
virtual bool operator()(bool enabled, const DataArgs &args) {
if (enabled)
args.output <<data_prefix <<std::setw(width) <<function_hash(args.func).substr(0,16);
return enabled;
}
} hashCallback;
MyFunctionIndex(SgNode *ast): AsmFunctionIndex(ast) {
output_callbacks.before(&nameCallback, &hashCallback);
}
};
std::cout <<MyFuncitonIndex(project);

The output might look something like this:

  Num Entry-Addr Begin-Addr  End-Addr  Insns/ Bytes      Reason        Kind         Hash                     Name              
 ---- ---------- ---------- ---------- ------------ ---------------- -------- ---------------- --------------------------------
    0 0x08048278 0x0804828e 0x0804828f     8/23     .C..S...........  unknown                  _init                           
    1 0x080482a0 0x080482a0 0x080482a6     1/6      .C.I............  unknown                  malloc@@plt                      
    2 0x080482b0 0x080482b0 0x080482b6     1/6      .C.I............  unknown                  __libc_start_main@@plt           
    3 0x080482c0 0x080482e1 0x080482e2    14/34     E...S...........  unknown                  _start                          
    4 0x080482e4 0x08048304 0x08048305    15/33     .C..S...........  unknown                  call_gmon_start                 
    5 0x08048310 0x0804833e 0x0804833f    16/47     .C..S...........  unknown                  __do_global_dtors_aux           
    6 0x08048340 0x08048362 0x08048363    13/35     .C..S...........  unknown                  frame_dummy                     
    7 0x08048364 0x080483bf 0x080483c0    29/92     ....S...........  unknown 91badca44c59fae6 main                            
    8 0x080483c0 0x08048411 0x08048412    34/82     ....S...........  unknown                  __libc_csu_init                 
    9 0x08048414 0x08048455 0x08048456    27/66     ....S...........  unknown                  __libc_csu_fini                 
   10 0x08048460 0x08048490 0x08048491    20/49     .C..S...........  unknown                  __do_global_ctors_aux           
   11 0x08048494 0x080484ad 0x080484ae    12/26     .C..S...........  unknown                  _fini                           
 ---- ---------- ---------- ---------- ------------ ---------------- -------- ---------------- --------------------------------

Definition at line 79 of file AsmFunctionIndex.h.

#include <Rose/BinaryAnalysis/AsmFunctionIndex.h>

Collaboration diagram for Rose::BinaryAnalysis::AsmFunctionIndex:
Collaboration graph
[legend]

Classes

class  BeginAddrCallback
 Print function minimum address. More...
 
class  CallingConventionCallback
 Print calling convention. More...
 
class  EndAddrCallback
 Print function ending address. More...
 
class  EntryAddrCallback
 Print function entry address. More...
 
class  Footnotes
 
class  FootnotesCallback
 Footnotes at the end of the table. More...
 
class  MayReturnCallback
 Print whether function can return. More...
 
class  NameCallback
 Function name. More...
 
class  OutputCallback
 Base class for printing table cells. More...
 
class  ReasonCallback
 Print function reason bits. More...
 
class  RowIdCallback
 Print index row numbers. More...
 
class  SizeBytesCallback
 Print function size in bytes. More...
 
class  SizeInsnsCallback
 Print number of instructions in function. More...
 
struct  SortByBeginAddr
 Functor for sorting by function beginning address. More...
 
struct  SortByBytesSize
 Functor for sorting by number of bytes in function. More...
 
struct  SortByEntryAddr
 Functor for sorting by function entry virtual address. More...
 
struct  SortByInsnsSize
 Functor for sorting by number of instructions in function. More...
 
struct  SortByName
 Functor to sort functions by name. More...
 
class  StackDeltaCallback
 Print stack delta. More...
 

Public Member Functions

 AsmFunctionIndex ()
 Constructs an empty index. More...
 
 AsmFunctionIndex (SgNode *ast)
 Constructs an index from an AST. More...
 
virtual void add_function (SgAsmFunction *)
 Adds a function to the end of this index. More...
 
virtual void add_functions (SgNode *ast)
 Adds functions to this index. More...
 
virtual void clear ()
 Clears the index. More...
 
virtual bool empty () const
 Determines if an index is empty. More...
 
virtual size_t size () const
 Returns the number of functions in the index. More...
 
template<class Comparator >
AsmFunctionIndexsort (Comparator comp, bool unique=false)
 Sort the functions in the index. More...
 
AsmFunctionIndexreverse ()
 Reverse the order of the functions. More...
 
virtual void print (std::ostream &) const
 Prints a function index to an output stream. More...
 
AsmFunctionIndexsort_by_entry_addr (bool unique=false)
 Specific sorting method. More...
 
AsmFunctionIndexsort_by_begin_addr (bool unique=false)
 Specific sorting method. More...
 
AsmFunctionIndexsort_by_ninsns (bool unique=false)
 Specific sorting method. More...
 
AsmFunctionIndexsort_by_nbytes (bool unique=false)
 Specific sorting method. More...
 
AsmFunctionIndexsort_by_name (bool unique=false)
 Specific sorting method. More...
 

Public Attributes

Rose::BinaryAnalysis::AsmFunctionIndex::RowIdCallback rowIdCallback
 
Rose::BinaryAnalysis::AsmFunctionIndex::EntryAddrCallback entryAddrCallback
 
Rose::BinaryAnalysis::AsmFunctionIndex::BeginAddrCallback beginAddrCallback
 
Rose::BinaryAnalysis::AsmFunctionIndex::EndAddrCallback endAddrCallback
 
Rose::BinaryAnalysis::AsmFunctionIndex::SizeInsnsCallback sizeInsnsCallback
 
Rose::BinaryAnalysis::AsmFunctionIndex::SizeBytesCallback sizeBytesCallback
 
Rose::BinaryAnalysis::AsmFunctionIndex::ReasonCallback reasonCallback
 
Rose::BinaryAnalysis::AsmFunctionIndex::CallingConventionCallback callingConventionCallback
 
Rose::BinaryAnalysis::AsmFunctionIndex::MayReturnCallback mayReturnCallback
 
Rose::BinaryAnalysis::AsmFunctionIndex::StackDeltaCallback stackDeltaCallback
 
Rose::BinaryAnalysis::AsmFunctionIndex::NameCallback nameCallback
 
Rose::BinaryAnalysis::AsmFunctionIndex::FootnotesCallback footnotesCallback
 

Protected Types

typedef std::vector< SgAsmFunction * > Functions
 

Protected Member Functions

virtual void init ()
 Initializes the callback lists. More...
 

Protected Attributes

Functions functions
 Functions in index order. More...
 
Callbacks::List< OutputCallbackoutput_callbacks
 List of callbacks to be invoked when printing columns. More...
 

Friends

std::ostream & operator<< (std::ostream &, const AsmFunctionIndex &)
 

Constructor & Destructor Documentation

Rose::BinaryAnalysis::AsmFunctionIndex::AsmFunctionIndex ( )
inline

Constructs an empty index.

Definition at line 86 of file AsmFunctionIndex.h.

References init().

Rose::BinaryAnalysis::AsmFunctionIndex::AsmFunctionIndex ( SgNode ast)
inline

Constructs an index from an AST.

Definition at line 91 of file AsmFunctionIndex.h.

References add_functions(), and init().

Member Function Documentation

virtual void Rose::BinaryAnalysis::AsmFunctionIndex::add_function ( SgAsmFunction )
virtual

Adds a function to the end of this index.

The function is added regardless of whether it already exists.

virtual void Rose::BinaryAnalysis::AsmFunctionIndex::add_functions ( SgNode ast)
virtual

Adds functions to this index.

The specified AST is traversed and all SgAsmFunction nodes are added to this index. All encountered functions are added to the index in the order they are encountered regardless of whether they already exist.

Referenced by AsmFunctionIndex().

virtual void Rose::BinaryAnalysis::AsmFunctionIndex::clear ( )
inlinevirtual

Clears the index.

Removes all functions from the index, but does not change any callback lists.

Definition at line 107 of file AsmFunctionIndex.h.

References functions.

virtual bool Rose::BinaryAnalysis::AsmFunctionIndex::empty ( ) const
inlinevirtual

Determines if an index is empty.

Returns true if the index contains no functions, false otherwise.

Definition at line 112 of file AsmFunctionIndex.h.

References functions.

virtual size_t Rose::BinaryAnalysis::AsmFunctionIndex::size ( ) const
inlinevirtual

Returns the number of functions in the index.

Definition at line 117 of file AsmFunctionIndex.h.

References functions.

template<class Comparator >
AsmFunctionIndex& Rose::BinaryAnalysis::AsmFunctionIndex::sort ( Comparator  comp,
bool  unique = false 
)
inline

Sort the functions in the index.

The supplied functor takes two SgAsmFunction pointers as arguments and returns true if the first argument goes before the second argument in the specific strict weak ordering it defines, and false otherwise. If unique is defined, then a final pass is made over the functions and any adjacent functions for which the Comparator::unique() method, which takes two SgAsmFunction pointer arguments, returns false will cause the second argument to be removed from the index.

Definition at line 204 of file AsmFunctionIndex.h.

References functions.

Referenced by sort_by_begin_addr(), sort_by_entry_addr(), sort_by_name(), sort_by_nbytes(), and sort_by_ninsns().

AsmFunctionIndex& Rose::BinaryAnalysis::AsmFunctionIndex::sort_by_entry_addr ( bool  unique = false)
inline

Specific sorting method.

This method is expected to be commonly used, so we define it here for convenience. If some other sorting method is needed, see the generic sort() method.

Definition at line 221 of file AsmFunctionIndex.h.

References sort().

AsmFunctionIndex& Rose::BinaryAnalysis::AsmFunctionIndex::sort_by_begin_addr ( bool  unique = false)
inline

Specific sorting method.

This method is expected to be commonly used, so we define it here for convenience. If some other sorting method is needed, see the generic sort() method.

Definition at line 222 of file AsmFunctionIndex.h.

References sort().

AsmFunctionIndex& Rose::BinaryAnalysis::AsmFunctionIndex::sort_by_ninsns ( bool  unique = false)
inline

Specific sorting method.

This method is expected to be commonly used, so we define it here for convenience. If some other sorting method is needed, see the generic sort() method.

Definition at line 223 of file AsmFunctionIndex.h.

References sort().

AsmFunctionIndex& Rose::BinaryAnalysis::AsmFunctionIndex::sort_by_nbytes ( bool  unique = false)
inline

Specific sorting method.

This method is expected to be commonly used, so we define it here for convenience. If some other sorting method is needed, see the generic sort() method.

Definition at line 224 of file AsmFunctionIndex.h.

References sort().

AsmFunctionIndex& Rose::BinaryAnalysis::AsmFunctionIndex::sort_by_name ( bool  unique = false)
inline

Specific sorting method.

This method is expected to be commonly used, so we define it here for convenience. If some other sorting method is needed, see the generic sort() method.

Definition at line 225 of file AsmFunctionIndex.h.

References sort().

AsmFunctionIndex& Rose::BinaryAnalysis::AsmFunctionIndex::reverse ( )
inline

Reverse the order of the functions.

This is typically called after sorting.

Definition at line 229 of file AsmFunctionIndex.h.

References functions.

virtual void Rose::BinaryAnalysis::AsmFunctionIndex::print ( std::ostream &  ) const
virtual

Prints a function index to an output stream.

virtual void Rose::BinaryAnalysis::AsmFunctionIndex::init ( )
protectedvirtual

Initializes the callback lists.

This is invoked by the default constructor.

Referenced by AsmFunctionIndex().

Member Data Documentation

Functions Rose::BinaryAnalysis::AsmFunctionIndex::functions
protected

Functions in index order.

Definition at line 500 of file AsmFunctionIndex.h.

Referenced by clear(), empty(), reverse(), size(), and sort().

Callbacks::List<OutputCallback> Rose::BinaryAnalysis::AsmFunctionIndex::output_callbacks
protected

List of callbacks to be invoked when printing columns.

Definition at line 506 of file AsmFunctionIndex.h.


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