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

Description

Unparses binary AST into text.

This class operates on part of an AST corresponding to a binary file (executable, library, etc) and generates output. It is intended to be highly customizable and has been used to generate both assembly listings and Graphviz files.

To generate an assembly listing, use the unparse() method, like this:

SgProject *project = ...;
AsmUnparser().unparse(std::cout, project);

The unparser can organize the output either by address (like traditional assembly listings) or by the organization found in the AST (by interpretation, then function, then basic block). The AST organization is often more useful and is therefore the default. Some of the callbacks mentioned below apply only to one organizational style or the other.

Instead of passing a SgProject node to the unparse() method, one may also pass lower-level nodes, such as SgAsmInterpretation, SgAsmFunction, SgAsmBlock, or even a single SgAsmInstruction. The unparser operates finding the list of top-level, unparsable nodes (see find_unparsable_nodes()) reachable from the specified node and then unparsing each one. For each node, an appropriate unparse_TYPE() is called, where TYPE is "insn", "basicblock", "staticdata", "datablock", "function", or "interpretation". Each of these unparse functions invokes three lists of callbacks:

The callback lists are initialized to contain the following functor types. Some callbacks are no-ops for certain organizations of the output, and these are noted.

Additional functors are defined within the AsmUnparser class but are not installed into the callback lists by default. They're only provided because they might be useful to end users.

Static Data Disassembly

Sometimes ROSE mistakenly assumes that certain parts of the address space are static data. This can happen, for example, when code is unreachable. One common place this happens is when a call is made to a function that never returns, but the compiler thought it might return. It's often useful to be able to disassemble these static data areas and present them as instructions (in addition to the usual data presentation). Originally, this had to be done by hand using a derived AsmUnparser class and registering a static data unparser that did the disassembly, but now the AsmUnparser class defines a staticDataDisassembler callback (of type StaticDataDisassembler) for this purpose. In order to disassemble static data, one needs to provide the staticDataDisassembler with a disassembler. One way to do that is to use the default disassembler for the interpretation that's being unparsed. One could also use the same disassembler that was originally used to disassemble the entire specimen. In either case, setting the disassembler's recursion properties is probably wise since static data is often meaningless as instructions.

SgAsmInterpretation *interp = ...;
disassembler->set_search(Disassembler::SEARCH_DEFAULT | Disassembler::SEARCH_DEADEND |
Disassembler::SEARCH_UNKNOWN | Disassembler::SEARCH_UNUSED);
AsmUnparser unparser;
unparser.staticDataDisassembler.init(disassembler);
unparser.unparse(std::cout, interp);
delete disassembler; // ok to delete since we won't be using unparser anymore

The output will look something like this:

0x0804828f: 00 ff 35 a0 95 04 08 ff |..5.....|
0x08048297: 25 a4 95 04 08 00 00 00 |%.......|
0x0804829f: 00                      |.       | 17 bytes untyped data beginning at 0x0804828f
0x0804828f: 00 ff                   |..      | (data)   add    bh, bh
0x08048291: 35 a0 95 04 08          |5....   | (data)   xor    eax, 0x080495a0
0x08048296: ff 25 a4 95 04 08       |.%....  | (data)   jmp    DWORD PTR ds:[0x080495a4]
0x0804829c: 00 00                   |..      | (data)   add    BYTE PTR ds:[eax], al
0x0804829e: 00 00                   |..      | (data)   add    BYTE PTR ds:[eax], al 

Examples

Changing register names

This example shows how one can replace a register name with something else. Let's say that MIPS32 Release 1 instructions are being unparsed and you'd rather see "lr" (for "link register") rather than "r31" or "ra". This can be accomplished by creating a new register dictionary, adding the definition for "lr", and using that dictionary for unparsing:

RegisterDictionary::Ptr myRegisters = RegisterDictionary::instance("My Mips32 Release 1");
myRegisters->insert(RegisterDictionary::instanceMips32()); // incorporate MIPS32 defns
RegisterDescriptor *r31 = myRegisters->lookup("r31"); // definition for r31
myRegisters->insert("lr", *r31); // new name, same old definition
AsmUnparser unparser;
unparser.set_registers(myRegisters);
SgAsmInterpretation interp = ...; // the stuff to unparse
unparser.unparse(std::cout, interp);

Unparsing to HTML

This next example shows how to escape entire instructions for HTML output, and surround each instruction with an HTML table row. We could have just as easily combined all three parts into a single functor, but doing it this way makes the example a bit more interesting.

class UnparseForHTML: public AsmUnparser {
// Callback to emit the beginning of the table row.
class BB_Prologue: public UnparserCallback {
public:
virtual bool operator()(bool enabled, const BasicBlockArgs &args) {
if (enabled)
args.output <<"<tr><td>";
return enabled;
}
} bb_prologue;
// Callback to output the instructions into a string and then escape
// any characters that are special to HTML.
class BB_Body: public UnparserCallback {
public:
virtual bool operator()(bool enabled, const BasicBlockArgs &args) {
if (enabled) {
for (size_t i=0; i<args.insns.size(); i++) {
std::ostringstream ss;
args.unparser->unparse_insn(ss, args.insns[i], i);
args.output <<StringUtility::htmlEscape(ss.str());
}
}
return enabled;
}
} bb_body;
// Callback to emit the end of the table row.
class BB_Epilogue: public UnparserCallback {
public:
virtual bool operator()(bool enabled, const BasicBlockArgs &args) {
if (enabled)
args.output <<"</tr></td>";
return enabled;
}
} bb_epilogue;
// The constructor makes some adjustments to the callback lists. The
// basicBlockBody is the functor that would normally emit the instructions
// of the basic block.
UnparseForHTML() {
basicblock_callbacks.pre.prepend(&bb_prologue);
basicblock_callbacks.unparse.replace(&basicBlockBody, &bb_body);
basicblock_callbacks.post.append(&bb_epilogue);
}
};
void
unparse_binary(std::ostream &output, SgNode *ast)
{
output <<"<table>";
UnparseForHTML().unparse(output, ast);
output <<"</table>";
}

Definition at line 256 of file AsmUnparser.h.

#include <backend/asmUnparser/AsmUnparser.h>

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

Classes

class  BasicBlockBody
 Functor to emit the instructions that belong to a basic block. More...
 
class  BasicBlockCleanup
 Functor to clean up after basic block. More...
 
class  BasicBlockLineTermination
 Functor to emit a blank line after every basic block. More...
 
class  BasicBlockNoopUpdater
 Functor to update unparser's is_noop array. More...
 
class  BasicBlockNoopWarning
 Functor to emit a warning if the block contains any no-effect sequences. More...
 
class  BasicBlockOutgoingStackDelta
 Functor to emit basic block outgoing stack delta. More...
 
class  BasicBlockPredecessors
 Functor to emit control flow predecessor addresses. More...
 
class  BasicBlockReasons
 Functor to emit reasons this block is part of a function. More...
 
class  BasicBlockSuccessors
 Functor to emit block successor list. More...
 
struct  CallbackLists
 
class  DataBlockBody
 Functor to emit each data statement of the block. More...
 
class  DataBlockLineTermination
 Functor to emit a blank line after every data block. More...
 
class  DataBlockTitle
 Functor to print some information at the beginning of a data block. More...
 
class  FunctionAttributes
 Functor to emit function attributes. More...
 
class  FunctionBody
 Functor to unparse the function body. More...
 
class  FunctionComment
 Functor to print function comments followed by a linefeed if necessary. More...
 
class  FunctionEntryAddress
 Functor to emit function entry address. More...
 
class  FunctionLineTermination
 Functor to emit function line termination. More...
 
class  FunctionName
 Functor to emit function name. More...
 
class  FunctionPredecessors
 Functor to print caller addresses. More...
 
class  FunctionReasons
 Functor to emit function reasons. More...
 
class  FunctionSeparator
 Functor to emit function separator. More...
 
class  FunctionSuccessors
 Functor to print callee addresses. More...
 
class  InsnAddress
 Functor to emit instruction address. More...
 
class  InsnBlockEntry
 Functor to emit info about the first instruction of a block. More...
 
class  InsnBlockSeparation
 Functor to emit basic block separation in output organized by address. More...
 
class  InsnBody
 Functor to emit the entire instruction. More...
 
class  InsnComment
 Functor to emit instruction comment, if any. More...
 
class  InsnFuncEntry
 Functor to emit function information at entry points. More...
 
class  InsnLineTermination
 Functor to emit instruction line termination. More...
 
class  InsnNoEffect
 Functor to emit a note about instructions that have no effect. More...
 
class  InsnRawBytes
 Functor to emit instruction bytes. More...
 
class  InsnSkipBackBegin
 Functor to print skip/back information when an instruction is entered. More...
 
class  InsnSkipBackEnd
 Update instruction end address for skip/back reporting. More...
 
class  InsnStackDelta
 Functor to emit the numeric stack delta at each instruction. More...
 
class  InterpBody
 Functor to emit the functions in an interpretation. More...
 
class  InterpName
 Functor to emit interpretation name. More...
 
struct  LinePrefix
 Details for line prefixes. More...
 
struct  SkipBack
 Details for skip/back reporting. More...
 
class  StaticDataBlockEntry
 Functor to emit info about the first data node of a block. More...
 
class  StaticDataBlockSeparation
 Functor to emit data block separation in output organized by address. More...
 
class  StaticDataComment
 Functor to emit optional static data comment. More...
 
class  StaticDataDetails
 Functor to emit details about static data. More...
 
class  StaticDataDisassembler
 Disassembles static data as if it were code. More...
 
class  StaticDataLineTermination
 Functor to emit a blank line after every data block. More...
 
class  StaticDataRawBytes
 Functor to emit the bytes of the data block. More...
 
class  StaticDataSkipBackBegin
 Functor to print skip/back information when a static data block is entered. More...
 
class  StaticDataSkipBackEnd
 Update static data end address for skip/back reporting. More...
 
class  UnparserCallback
 

Public Types

enum  Organization {
  ORGANIZED_BY_AST,
  ORGANIZED_BY_ADDRESS
}
 
typedef Rose::BinaryAnalysis::ControlFlow::Graph CFG
 Control Flow Graph type. More...
 
typedef boost::graph_traits< CFG >::vertex_descriptor CFG_Vertex
 
typedef std::map< SgAsmBlock *, CFG_Vertex > CFG_BlockMap
 
typedef Rose::BinaryAnalysis::FunctionCall::Graph CG
 
typedef boost::graph_traits< CG >::vertex_descriptor CG_Vertex
 
typedef std::map< SgAsmFunction *, CG_Vertex > CG_FunctionMap
 
typedef std::map< uint64_t, std::string > LabelMap
 Maps integers to labels. More...
 

Public Member Functions

 AsmUnparser ()
 Constructor that intializes the "unparser" callback lists with some useful functors. More...
 
virtual bool is_unparsable_node (SgNode *node)
 Determines if a node can be unparsed. More...
 
virtual SgNodefind_unparsable_node (SgNode *ast)
 Finds first unparsable node. More...
 
virtual std::vector< SgNode * > find_unparsable_nodes (SgNode *ast)
 Finds top unparsable nodes. More...
 
virtual size_t unparse (std::ostream &, SgNode *ast)
 Unparse part of the AST. More...
 
std::string to_string (SgNode *ast)
 Unparse part of the AST into a string. More...
 
virtual bool unparse_one_node (std::ostream &, SgNode *)
 Unparse a single node if possible. More...
 
void add_function_labels (SgNode *ast)
 Adds function labels to the label map. More...
 
void add_control_flow_graph (const Rose::BinaryAnalysis::ControlFlow::Graph &cfg)
 Associates a control flow graph with this unparser. More...
 
virtual Organization get_organization () const
 Get/set how output is organized. More...
 
virtual void set_organization (Organization organization)
 Get/set how output is organized. More...
 
virtual RegisterDictionaryPtr get_registers () const
 Register dictionaries. More...
 
virtual void set_registers (const RegisterDictionaryPtr &registers)
 Register dictionaries. More...
 
virtual bool unparse_insn (bool enabled, std::ostream &, SgAsmInstruction *, size_t position_in_block=(size_t)-1)
 Unparse an object. More...
 
virtual bool unparse_basicblock (bool enabled, std::ostream &, SgAsmBlock *)
 Unparse an object. More...
 
virtual bool unparse_staticdata (bool enabled, std::ostream &, SgAsmStaticData *, size_t position_in_block=(size_t)-1)
 Unparse an object. More...
 
virtual bool unparse_datablock (bool enabled, std::ostream &, SgAsmBlock *)
 Unparse an object. More...
 
virtual bool unparse_function (bool enabled, std::ostream &, SgAsmFunction *)
 Unparse an object. More...
 
virtual bool unparse_interpretation (bool enabled, std::ostream &, SgAsmInterpretation *)
 Unparse an object. More...
 
void set_skipback_reporting (bool b=true)
 Controls printing of skip/back messages during linear output. More...
 
void clear_skipback_reporting ()
 Controls printing of skip/back messages during linear output. More...
 
bool get_skipback_reporting () const
 Controls printing of skip/back messages during linear output. More...
 
void reset_skipback ()
 Controls printing of skip/back messages during linear output. More...
 
void start_of_object (rose_addr_t, std::ostream &)
 Controls printing of skip/back messages during linear output. More...
 
void end_of_object (rose_addr_t)
 Controls printing of skip/back messages during linear output. More...
 
virtual void set_prefix_format (const std::string &format)
 Controls printing of line prefixes. More...
 
virtual const std::string & get_prefix_format () const
 Controls printing of line prefixes. More...
 
virtual void set_prefix_address (rose_addr_t va)
 Controls printing of line prefixes. More...
 
virtual rose_addr_t get_prefix_address () const
 Controls printing of line prefixes. More...
 
virtual std::string line_prefix () const
 Controls printing of line prefixes. More...
 
virtual std::string blank_prefix () const
 Controls printing of line prefixes. More...
 

Static Public Member Functions

static void initDiagnostics ()
 Initialize diagnostic messages subsystem. More...
 

Public Attributes

std::vector< bool > insn_is_noop
 Optional information about no-op sequences. More...
 
Functors

Functors used by the base class.

We declare these as public so users can have an address by which to search through the various callback lists. For instance, if the user doesn't want to see instruction raw bytes, they just remove the insnRawBytes callback from the appropriate list(s).

InsnSkipBackBegin insnSkipBackBegin
 
InsnBlockSeparation insnBlockSeparation
 
InsnFuncEntry insnFuncEntry
 
InsnAddress insnAddress
 
InsnRawBytes insnRawBytes
 
InsnBlockEntry insnBlockEntry
 
InsnStackDelta insnStackDelta
 
InsnBody insnBody
 
InsnNoEffect insnNoEffect
 
InsnComment insnComment
 
InsnLineTermination insnLineTermination
 
InsnSkipBackEnd insnSkipBackEnd
 
BasicBlockReasons basicBlockReasons
 
BasicBlockPredecessors basicBlockPredecessors
 
BasicBlockNoopUpdater basicBlockNoopUpdater
 
BasicBlockNoopWarning basicBlockNoopWarning
 
BasicBlockBody basicBlockBody
 
BasicBlockOutgoingStackDelta basicBlockOutgoingStackDelta
 
BasicBlockSuccessors basicBlockSuccessors
 
BasicBlockLineTermination basicBlockLineTermination
 
BasicBlockCleanup basicBlockCleanup
 
StaticDataSkipBackBegin staticDataSkipBackBegin
 
StaticDataBlockSeparation staticDataBlockSeparation
 
StaticDataRawBytes staticDataRawBytes
 
StaticDataBlockEntry staticDataBlockEntry
 
StaticDataDetails staticDataDetails
 
StaticDataComment staticDataComment
 
StaticDataLineTermination staticDataLineTermination
 
StaticDataDisassembler staticDataDisassembler
 
StaticDataSkipBackEnd staticDataSkipBackEnd
 
DataBlockBody dataBlockBody
 
DataBlockLineTermination dataBlockLineTermination
 
FunctionEntryAddress functionEntryAddress
 
FunctionSeparator functionSeparator
 
FunctionReasons functionReasons
 
FunctionName functionName
 
FunctionLineTermination functionLineTermination
 
FunctionComment functionComment
 
FunctionPredecessors functionPredecessors
 
FunctionSuccessors functionSuccessors
 
FunctionAttributes functionAttributes
 
FunctionBody functionBody
 
InterpName interpName
 
InterpBody interpBody
 

Static Public Attributes

static Sawyer::Message::Facility mlog
 Diagnostic messages. More...
 

Protected Member Functions

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

Protected Attributes

CallbackLists insn_callbacks
 Callbacks for instruction unparsing. More...
 
CallbackLists basicblock_callbacks
 Callbacks for basic block unparsing. More...
 
CallbackLists staticdata_callbacks
 Callbacks for static data unparsing. More...
 
CallbackLists datablock_callbacks
 Callbacks for data block unparsing. More...
 
CallbackLists function_callbacks
 Callbacks for function unparsing. More...
 
CallbackLists interp_callbacks
 Callbacks for interpretation unparsing. More...
 
LabelMap labels
 This map is consulted whenever a constant is encountered. More...
 
Organization organization
 How output will be organized. More...
 
RegisterDictionaryPtr user_registers
 Dictionaries used to convert register descriptors to register names. More...
 
RegisterDictionaryPtr interp_registers
 
CFG cfg
 Control flow graph. More...
 
CFG_BlockMap cfg_blockmap
 A mapping from SgAsmBlock to control flow graph vertex. More...
 
CG cg
 Function call graph. More...
 
CG_FunctionMap cg_functionmap
 A mapping from SgAsmFunction to call graph vertex. More...
 
struct Rose::BinaryAnalysis::AsmUnparser::SkipBack skipback
 
struct Rose::BinaryAnalysis::AsmUnparser::LinePrefix lineprefix
 

Member Typedef Documentation

Control Flow Graph type.

The unparser supports the standard binary control flow graph data type. This could be templatized, but we're planning to move to a non-template graph type in the near future [RPM 2012-04-18].

Definition at line 272 of file AsmUnparser.h.

typedef std::map<uint64_t, std::string> Rose::BinaryAnalysis::AsmUnparser::LabelMap

Maps integers to labels.

Definition at line 901 of file AsmUnparser.h.

Member Enumeration Documentation

Enumerator
ORGANIZED_BY_AST 

Output follows the AST organization.

In other words, the instructions and data for a block appear consecutively, the blocks of a function appear consecutively, and the functions of an interpretation appear consecutively. This is the default format since it provides the most information about the organization of the binary file.

ORGANIZED_BY_ADDRESS 

Output of instructions and data are organized by address.

Specifically, in the case of overlapping instructions and/or data, the starting address is used to sort the output. This organization is typical of more traditional disassemblers.

Definition at line 258 of file AsmUnparser.h.

Constructor & Destructor Documentation

Rose::BinaryAnalysis::AsmUnparser::AsmUnparser ( )

Constructor that intializes the "unparser" callback lists with some useful functors.

Member Function Documentation

virtual Organization Rose::BinaryAnalysis::AsmUnparser::get_organization ( ) const
inlinevirtual

Get/set how output is organized.

The unparse() method organizes output by one of the methods described for the Organization enum.

Definition at line 816 of file AsmUnparser.h.

virtual void Rose::BinaryAnalysis::AsmUnparser::set_organization ( Organization  organization)
inlinevirtual

Get/set how output is organized.

The unparse() method organizes output by one of the methods described for the Organization enum.

Definition at line 817 of file AsmUnparser.h.

virtual bool Rose::BinaryAnalysis::AsmUnparser::is_unparsable_node ( SgNode node)
virtual

Determines if a node can be unparsed.

The AsmUnparser only handles certain node types, namely those that correspond to binary functions, blocks, and instructions. This method should return true if the specified node is one that can be parsed. See also, find_unparsable_node().

virtual SgNode* Rose::BinaryAnalysis::AsmUnparser::find_unparsable_node ( SgNode ast)
virtual

Finds first unparsable node.

Traverses the specified AST to find a node that can be unparsed, and returns it. The traversal is a depth-first traversal with pre-order visiting. The traversal terminates as soon as a node is found. Returns false if no suitable node can be found.

virtual std::vector<SgNode*> Rose::BinaryAnalysis::AsmUnparser::find_unparsable_nodes ( SgNode ast)
virtual

Finds top unparsable nodes.

Traverses the specified AST to find nodes that can be unparsed, and returns a vector of such nodes. Once a node is discovered, the subtree rooted at that node is not searched.

virtual RegisterDictionaryPtr Rose::BinaryAnalysis::AsmUnparser::get_registers ( ) const
virtual

Register dictionaries.

A register dictionary is used to convert register descriptors stored within instructions (via RegisterDescriptor) into names. The unparser keeps two register dictionaries: the user-specified register dictionary, and a dictionary obtained from a SgAsmInterpretation. The user-specified dictionary is used in preference to the SgAsmInterpretation dictionary when both are specified. The SgAsmInterpretation dictionary is set (internally) whenever an SgAsmInterpretation node is encountered during unparsing, and reset after the entire node is unparsed. The user-specified dictionary is set via the set_registers() method. The get_registers() returns either the user-specified or SgAsmInterpretation dictionary.

virtual void Rose::BinaryAnalysis::AsmUnparser::set_registers ( const RegisterDictionaryPtr registers)
virtual

Register dictionaries.

A register dictionary is used to convert register descriptors stored within instructions (via RegisterDescriptor) into names. The unparser keeps two register dictionaries: the user-specified register dictionary, and a dictionary obtained from a SgAsmInterpretation. The user-specified dictionary is used in preference to the SgAsmInterpretation dictionary when both are specified. The SgAsmInterpretation dictionary is set (internally) whenever an SgAsmInterpretation node is encountered during unparsing, and reset after the entire node is unparsed. The user-specified dictionary is set via the set_registers() method. The get_registers() returns either the user-specified or SgAsmInterpretation dictionary.

virtual size_t Rose::BinaryAnalysis::AsmUnparser::unparse ( std::ostream &  ,
SgNode ast 
)
virtual

Unparse part of the AST.

This is the primary method for this class. It traverses the specified ast and prints some kind of assembly language output to the specified output stream. The specifics of what is produced depend on how the AsmUnparser is configured.

The return value is the number of unparsable nodes encountered and has various meanings depending on the output organization. For output organized by AST it is the number of "top-level unparsable nodes", the number of nodes, R, such that is_unparsable_node(R) is true, and there exists no node C such that C is a proper ancestor of R and contained in the specified AST. For output organized by address, it is the number of instructions and data objects unparsed. In any case, a return value of zero means that nothing was unparsed and no output was produced.

std::string Rose::BinaryAnalysis::AsmUnparser::to_string ( SgNode ast)

Unparse part of the AST into a string.

This is a wrapper around unparse() that returns a string rather than producing output on a stream.

virtual bool Rose::BinaryAnalysis::AsmUnparser::unparse_one_node ( std::ostream &  ,
SgNode  
)
virtual

Unparse a single node if possible.

Tries to unparse the given AST node directly, without traversing the AST to find a starting point. This is basically a big switch statement that calls one of the unparse_WHATEVER() methods.

Returns true if the node was unparsed, false otherwise.

virtual bool Rose::BinaryAnalysis::AsmUnparser::unparse_insn ( bool  enabled,
std::ostream &  ,
SgAsmInstruction ,
size_t  position_in_block = (size_t)-1 
)
virtual

Unparse an object.

These are called by unparse_one_node(), but might also be called by callbacks.

virtual bool Rose::BinaryAnalysis::AsmUnparser::unparse_basicblock ( bool  enabled,
std::ostream &  ,
SgAsmBlock  
)
virtual

Unparse an object.

These are called by unparse_one_node(), but might also be called by callbacks.

virtual bool Rose::BinaryAnalysis::AsmUnparser::unparse_staticdata ( bool  enabled,
std::ostream &  ,
SgAsmStaticData ,
size_t  position_in_block = (size_t)-1 
)
virtual

Unparse an object.

These are called by unparse_one_node(), but might also be called by callbacks.

virtual bool Rose::BinaryAnalysis::AsmUnparser::unparse_datablock ( bool  enabled,
std::ostream &  ,
SgAsmBlock  
)
virtual

Unparse an object.

These are called by unparse_one_node(), but might also be called by callbacks.

virtual bool Rose::BinaryAnalysis::AsmUnparser::unparse_function ( bool  enabled,
std::ostream &  ,
SgAsmFunction  
)
virtual

Unparse an object.

These are called by unparse_one_node(), but might also be called by callbacks.

virtual bool Rose::BinaryAnalysis::AsmUnparser::unparse_interpretation ( bool  enabled,
std::ostream &  ,
SgAsmInterpretation  
)
virtual

Unparse an object.

These are called by unparse_one_node(), but might also be called by callbacks.

void Rose::BinaryAnalysis::AsmUnparser::add_function_labels ( SgNode ast)

Adds function labels to the label map.

This method traverses the specified AST looking for function symbols, and adds their address and name to the label map for the unparser. The map is used by some callbacks to convert numeric values to more human friendly labels. If integer values are relative to other AST nodes, then one doesn't need to populate the LabelMap (see documentation for the AsmUnparser::labels data member.

void Rose::BinaryAnalysis::AsmUnparser::add_control_flow_graph ( const Rose::BinaryAnalysis::ControlFlow::Graph cfg)

Associates a control flow graph with this unparser.

If a control flow graph is present then certain output callbacks will be able to use that information. For instance, the basicBlockPredecessors will emit a list of all the predecessors of a block. Passing an empty graph will remove control flow information.

void Rose::BinaryAnalysis::AsmUnparser::set_skipback_reporting ( bool  b = true)
inline

Controls printing of skip/back messages during linear output.

Each callback that prints an object that occupies address space should call start_of_object() and end_of_object() before and after printing the object. If output is organized in the linear fashion and the start of an object does not coincide with the end of the previous object, and if skip/back reporting is enabled, then a message about skipping ahead or backward is inserted into the unparse output at that point.

Definition at line 920 of file AsmUnparser.h.

void Rose::BinaryAnalysis::AsmUnparser::clear_skipback_reporting ( )
inline

Controls printing of skip/back messages during linear output.

Each callback that prints an object that occupies address space should call start_of_object() and end_of_object() before and after printing the object. If output is organized in the linear fashion and the start of an object does not coincide with the end of the previous object, and if skip/back reporting is enabled, then a message about skipping ahead or backward is inserted into the unparse output at that point.

Definition at line 921 of file AsmUnparser.h.

bool Rose::BinaryAnalysis::AsmUnparser::get_skipback_reporting ( ) const
inline

Controls printing of skip/back messages during linear output.

Each callback that prints an object that occupies address space should call start_of_object() and end_of_object() before and after printing the object. If output is organized in the linear fashion and the start of an object does not coincide with the end of the previous object, and if skip/back reporting is enabled, then a message about skipping ahead or backward is inserted into the unparse output at that point.

Definition at line 922 of file AsmUnparser.h.

void Rose::BinaryAnalysis::AsmUnparser::reset_skipback ( )
inline

Controls printing of skip/back messages during linear output.

Each callback that prints an object that occupies address space should call start_of_object() and end_of_object() before and after printing the object. If output is organized in the linear fashion and the start of an object does not coincide with the end of the previous object, and if skip/back reporting is enabled, then a message about skipping ahead or backward is inserted into the unparse output at that point.

Definition at line 923 of file AsmUnparser.h.

void Rose::BinaryAnalysis::AsmUnparser::start_of_object ( rose_addr_t  ,
std::ostream &   
)

Controls printing of skip/back messages during linear output.

Each callback that prints an object that occupies address space should call start_of_object() and end_of_object() before and after printing the object. If output is organized in the linear fashion and the start of an object does not coincide with the end of the previous object, and if skip/back reporting is enabled, then a message about skipping ahead or backward is inserted into the unparse output at that point.

void Rose::BinaryAnalysis::AsmUnparser::end_of_object ( rose_addr_t  )

Controls printing of skip/back messages during linear output.

Each callback that prints an object that occupies address space should call start_of_object() and end_of_object() before and after printing the object. If output is organized in the linear fashion and the start of an object does not coincide with the end of the previous object, and if skip/back reporting is enabled, then a message about skipping ahead or backward is inserted into the unparse output at that point.

virtual void Rose::BinaryAnalysis::AsmUnparser::set_prefix_format ( const std::string &  format)
inlinevirtual

Controls printing of line prefixes.

Lines have an optional prefix area that tends to be the same regardless of the kind of object being printed. For instance, the default is for most lines to contain an address of some sort. Sometimes we want the prefix area to be the same size for all lines but have some lines with a blank prefix; and sometimes we want to omit the prefix and its indentation altogether.

The prefix format (set_prefix_format() and get_prefix_format()) is a printf-style format string with an optional format specifier for an unsigned 64-bit integer address. The address is set by the unparser when an unparsable object is encountered, but can be overridden by on of that object's callbacks (set_prefix_address() and get_prefix_address()). A prefix string is returned by by line_prefix() or blank_prefix() using the current format string and address (a blank prefix first calls line_prefix() and then changes all characters to ASCII SPC).

Definition at line 942 of file AsmUnparser.h.

virtual const std::string& Rose::BinaryAnalysis::AsmUnparser::get_prefix_format ( ) const
inlinevirtual

Controls printing of line prefixes.

Lines have an optional prefix area that tends to be the same regardless of the kind of object being printed. For instance, the default is for most lines to contain an address of some sort. Sometimes we want the prefix area to be the same size for all lines but have some lines with a blank prefix; and sometimes we want to omit the prefix and its indentation altogether.

The prefix format (set_prefix_format() and get_prefix_format()) is a printf-style format string with an optional format specifier for an unsigned 64-bit integer address. The address is set by the unparser when an unparsable object is encountered, but can be overridden by on of that object's callbacks (set_prefix_address() and get_prefix_address()). A prefix string is returned by by line_prefix() or blank_prefix() using the current format string and address (a blank prefix first calls line_prefix() and then changes all characters to ASCII SPC).

Definition at line 943 of file AsmUnparser.h.

virtual void Rose::BinaryAnalysis::AsmUnparser::set_prefix_address ( rose_addr_t  va)
inlinevirtual

Controls printing of line prefixes.

Lines have an optional prefix area that tends to be the same regardless of the kind of object being printed. For instance, the default is for most lines to contain an address of some sort. Sometimes we want the prefix area to be the same size for all lines but have some lines with a blank prefix; and sometimes we want to omit the prefix and its indentation altogether.

The prefix format (set_prefix_format() and get_prefix_format()) is a printf-style format string with an optional format specifier for an unsigned 64-bit integer address. The address is set by the unparser when an unparsable object is encountered, but can be overridden by on of that object's callbacks (set_prefix_address() and get_prefix_address()). A prefix string is returned by by line_prefix() or blank_prefix() using the current format string and address (a blank prefix first calls line_prefix() and then changes all characters to ASCII SPC).

Definition at line 944 of file AsmUnparser.h.

virtual rose_addr_t Rose::BinaryAnalysis::AsmUnparser::get_prefix_address ( ) const
inlinevirtual

Controls printing of line prefixes.

Lines have an optional prefix area that tends to be the same regardless of the kind of object being printed. For instance, the default is for most lines to contain an address of some sort. Sometimes we want the prefix area to be the same size for all lines but have some lines with a blank prefix; and sometimes we want to omit the prefix and its indentation altogether.

The prefix format (set_prefix_format() and get_prefix_format()) is a printf-style format string with an optional format specifier for an unsigned 64-bit integer address. The address is set by the unparser when an unparsable object is encountered, but can be overridden by on of that object's callbacks (set_prefix_address() and get_prefix_address()). A prefix string is returned by by line_prefix() or blank_prefix() using the current format string and address (a blank prefix first calls line_prefix() and then changes all characters to ASCII SPC).

Definition at line 945 of file AsmUnparser.h.

virtual std::string Rose::BinaryAnalysis::AsmUnparser::line_prefix ( ) const
virtual

Controls printing of line prefixes.

Lines have an optional prefix area that tends to be the same regardless of the kind of object being printed. For instance, the default is for most lines to contain an address of some sort. Sometimes we want the prefix area to be the same size for all lines but have some lines with a blank prefix; and sometimes we want to omit the prefix and its indentation altogether.

The prefix format (set_prefix_format() and get_prefix_format()) is a printf-style format string with an optional format specifier for an unsigned 64-bit integer address. The address is set by the unparser when an unparsable object is encountered, but can be overridden by on of that object's callbacks (set_prefix_address() and get_prefix_address()). A prefix string is returned by by line_prefix() or blank_prefix() using the current format string and address (a blank prefix first calls line_prefix() and then changes all characters to ASCII SPC).

virtual std::string Rose::BinaryAnalysis::AsmUnparser::blank_prefix ( ) const
inlinevirtual

Controls printing of line prefixes.

Lines have an optional prefix area that tends to be the same regardless of the kind of object being printed. For instance, the default is for most lines to contain an address of some sort. Sometimes we want the prefix area to be the same size for all lines but have some lines with a blank prefix; and sometimes we want to omit the prefix and its indentation altogether.

The prefix format (set_prefix_format() and get_prefix_format()) is a printf-style format string with an optional format specifier for an unsigned 64-bit integer address. The address is set by the unparser when an unparsable object is encountered, but can be overridden by on of that object's callbacks (set_prefix_address() and get_prefix_address()). A prefix string is returned by by line_prefix() or blank_prefix() using the current format string and address (a blank prefix first calls line_prefix() and then changes all characters to ASCII SPC).

Definition at line 947 of file AsmUnparser.h.

static void Rose::BinaryAnalysis::AsmUnparser::initDiagnostics ( )
static

Initialize diagnostic messages subsystem.

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

Initializes the callback lists.

This is invoked by the default constructor.

Member Data Documentation

std::vector<bool> Rose::BinaryAnalysis::AsmUnparser::insn_is_noop

Optional information about no-op sequences.

When a basic block is unparsed, the BasicBlockNoopUpdater callback (if present and enabled) will analyze its instructions and update the insn_is_noop vector. The vector is indexed by position of instruction within the block and indicates whehter that instruction is part of a no-op sequence. Note that if BasicBlockNoopUpdater is not called for a block, then the insn_is_noop vector will not be initialized. Even if it is initialized, the size of the vector may be less then the number of instructions because we don't store trailing false values. The vector is cleared by the BasicBlockCleanup callback.

Definition at line 862 of file AsmUnparser.h.

Sawyer::Message::Facility Rose::BinaryAnalysis::AsmUnparser::mlog
static

Diagnostic messages.

Definition at line 952 of file AsmUnparser.h.

CallbackLists Rose::BinaryAnalysis::AsmUnparser::insn_callbacks
protected

Callbacks for instruction unparsing.

Definition at line 968 of file AsmUnparser.h.

CallbackLists Rose::BinaryAnalysis::AsmUnparser::basicblock_callbacks
protected

Callbacks for basic block unparsing.

Definition at line 969 of file AsmUnparser.h.

CallbackLists Rose::BinaryAnalysis::AsmUnparser::staticdata_callbacks
protected

Callbacks for static data unparsing.

Definition at line 970 of file AsmUnparser.h.

CallbackLists Rose::BinaryAnalysis::AsmUnparser::datablock_callbacks
protected

Callbacks for data block unparsing.

Definition at line 971 of file AsmUnparser.h.

CallbackLists Rose::BinaryAnalysis::AsmUnparser::function_callbacks
protected

Callbacks for function unparsing.

Definition at line 972 of file AsmUnparser.h.

CallbackLists Rose::BinaryAnalysis::AsmUnparser::interp_callbacks
protected

Callbacks for interpretation unparsing.

Definition at line 973 of file AsmUnparser.h.

LabelMap Rose::BinaryAnalysis::AsmUnparser::labels
protected

This map is consulted whenever a constant is encountered.

If the constant is defined as a key of the map, then that element's string is used as a label. Populating this map is not as important as it once was, because now integers can be associated with other addressable AST nodes and labels are generated from them. For example, if 0x08042000 is the entry address of a function named "init", then it can be added to the LabelMap and the unparser will generate this assembly code:

call 0x08042000<init>

If the SgAsmIntegerValueExpression that represents the 0x08042000 is associated with the SgAsmFunction node for the "init" function, then the same output is generated when the LabelMap is not populated. In fact, the new method can also generate code like this, where the integer is an offset from the entry point:

je 0x08042080<init+0x80>

which isn't possible in general with the LabelMap mechanism.

Definition at line 994 of file AsmUnparser.h.

Organization Rose::BinaryAnalysis::AsmUnparser::organization
protected

How output will be organized.

Definition at line 997 of file AsmUnparser.h.

RegisterDictionaryPtr Rose::BinaryAnalysis::AsmUnparser::user_registers
protected

Dictionaries used to convert register descriptors to register names.

Definition at line 1000 of file AsmUnparser.h.

CFG Rose::BinaryAnalysis::AsmUnparser::cfg
protected

Control flow graph.

If non-empty, then it is used for things like listing CFG predecessors of each basic block.

Definition at line 1007 of file AsmUnparser.h.

CFG_BlockMap Rose::BinaryAnalysis::AsmUnparser::cfg_blockmap
protected

A mapping from SgAsmBlock to control flow graph vertex.

This map is updated when the control flow graph is modified by the add_control_flow_graph() method.

Definition at line 1011 of file AsmUnparser.h.

CG Rose::BinaryAnalysis::AsmUnparser::cg
protected

Function call graph.

This graph is built from the control flow graph whenever add_control_flow_graph() is called.

Definition at line 1014 of file AsmUnparser.h.

CG_FunctionMap Rose::BinaryAnalysis::AsmUnparser::cg_functionmap
protected

A mapping from SgAsmFunction to call graph vertex.

This map is updated when the control flow graph is modified by the add_control_flow_graph() method.

Definition at line 1018 of file AsmUnparser.h.


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