GTIRB-PPRINTER  v0.1.1
GrammaTech Intermediate Representation for Binaries: Pretty Printer
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
gtirb_pprint::PrettyPrinterBase Class Referenceabstract

#include <PrettyPrinter.h>

Inheritance diagram for gtirb_pprint::PrettyPrinterBase:
Inheritance graph
[legend]

Public Member Functions

 PrettyPrinterBase (gtirb::Context &context, gtirb::IR &ir, const string_range &skip_funcs, DebugStyle dbg)
 
virtual ~PrettyPrinterBase ()
 
virtual std::ostream & print (std::ostream &out)
 

Protected Member Functions

std::string avoidRegNameConflicts (const std::string &x)
 
std::vector< std::string > * getAmbiguousSymbol ()
 
std::optional< std::string > getContainerFunctionName (const gtirb::Addr x) const
 
const std::optional< const gtirb::Section * > getContainerSection (const gtirb::Addr addr) const
 
std::optional< std::string > getForwardedSymbolName (const gtirb::Symbol *symbol, bool isAbsolute) const
 
std::string getFunctionName (gtirb::Addr x) const
 
virtual int getGtirbOpIndex (int index, int opCount) const =0
 
virtual std::string getRegisterName (unsigned int reg) const
 
virtual const gtirb::SymAddrConst * getSymbolicImmediate (const gtirb::SymbolicExpression *symex)
 
bool isAmbiguousSymbol (const std::string &ea) const
 
bool isInSkippedFunction (const gtirb::Addr x) const
 
bool isInSkippedSection (const gtirb::Addr x) const
 
bool isSectionSkipped (const std::string &name)
 
virtual void printAddend (std::ostream &os, int64_t number, bool first=false)
 
virtual void printAlignment (std::ostream &os, const gtirb::Addr addr)
 
virtual void printBar (std::ostream &os, bool heavy=true)
 
virtual void printBlock (std::ostream &os, const gtirb::Block &x)
 
virtual gtirb::Addr printBlockOrWarning (std::ostream &os, const gtirb::Block &x, gtirb::Addr last)
 
virtual void printComment (std::ostream &os, const gtirb::Addr ea)
 
virtual void printDataObject (std::ostream &os, const gtirb::DataObject &dataObject)
 
virtual gtirb::Addr printDataObjectOrWarning (std::ostream &os, const gtirb::DataObject &x, gtirb::Addr last)
 
virtual void printEA (std::ostream &os, gtirb::Addr ea)
 
virtual void printFunctionHeader (std::ostream &os, gtirb::Addr ea)
 
virtual void printHeader (std::ostream &os)=0
 
virtual void printInstruction (std::ostream &os, const cs_insn &inst)
 
virtual void printNonZeroDataObject (std::ostream &os, const gtirb::DataObject &dataObject)
 
virtual void printOperand (std::ostream &os, const gtirb::SymbolicExpression *symbolic, const cs_insn &inst, uint64_t index)
 
virtual void printOperandList (std::ostream &os, const gtirb::Addr ea, const cs_insn &inst)
 
virtual void printOpImmediate (std::ostream &os, const gtirb::SymbolicExpression *symbolic, const cs_insn &inst, uint64_t index)=0
 
virtual void printOpIndirect (std::ostream &os, const gtirb::SymbolicExpression *symbolic, const cs_insn &inst, uint64_t index)=0
 
virtual void printOpRegdirect (std::ostream &os, const cs_insn &inst, const cs_x86_op &op)=0
 
virtual void printOverlapWarning (std::ostream &os, gtirb::Addr ea)
 
virtual void printSectionHeader (std::ostream &os, const gtirb::Addr addr)
 
virtual void printString (std::ostream &os, const gtirb::DataObject &x)
 
virtual void printSymbolDefinitionsAtAddress (std::ostream &os, gtirb::Addr ea)
 
virtual void printSymbolicData (std::ostream &os, const gtirb::SymbolicExpression *symbolic)
 
virtual void printSymbolicExpression (std::ostream &os, const gtirb::SymAddrConst *sexpr, bool inData=false)
 
virtual void printSymbolicExpression (std::ostream &os, const gtirb::SymAddrAddr *sexpr, bool inData=false)
 
virtual void printSymbolReference (std::ostream &os, const gtirb::Symbol *symbol, bool inData) const
 
virtual void printZeroDataObject (std::ostream &os, const gtirb::DataObject &dataObject)
 
bool shouldExcludeDataElement (const gtirb::Section &section, const gtirb::DataObject &dataObject) const
 
bool skipEA (const gtirb::Addr x) const
 

Static Protected Member Functions

static std::string AdaptRegister (const std::string &x)
 
static std::string AvoidRegNameConflicts (const std::string &x)
 
static std::string GetSizeName (uint64_t x)
 
static std::string GetSizeName (const std::string &x)
 
static std::string GetSizeSuffix (uint64_t x)
 
static std::string GetSizeSuffix (const std::string &x)
 
static std::string GetSymbolToPrint (gtirb::Addr x)
 

Protected Attributes

const std::unordered_set< std::string > AsmArraySection
 
std::unordered_set< std::string > AsmSkipFunction
 Functions to avoid printing. More...
 
std::unordered_set< std::string > AsmSkipSection
 Sections to avoid printing. More...
 
gtirb::Context & context
 
csh csHandle
 
bool debug
 
gtirb::IR & ir
 
const std::string StrNOP {"nop"}
 
const std::string StrSection {".section"}
 
const std::string StrSectionBSS {".bss"}
 
const std::string StrSectionGlobal {".globl"}
 
const std::string StrSectionText {".text"}
 
const std::string StrSectionType {".type"}
 
const std::string StrTab {" "}
 
const std::string StrZeroByte {".byte 0x00"}
 Constants to reduce (eliminate) magical strings inside the printer. More...
 

Detailed Description

The pretty-printer interface. There is only one exposed function, print().

Constructor & Destructor Documentation

◆ PrettyPrinterBase()

gtirb_pprint::PrettyPrinterBase::PrettyPrinterBase ( gtirb::Context &  context,
gtirb::IR &  ir,
const string_range skip_funcs,
DebugStyle  dbg 
)

◆ ~PrettyPrinterBase()

gtirb_pprint::PrettyPrinterBase::~PrettyPrinterBase ( )
virtual

Member Function Documentation

◆ AdaptRegister()

static std::string gtirb_pprint::PrettyPrinterBase::AdaptRegister ( const std::string &  x)
staticprotected

◆ avoidRegNameConflicts()

std::string gtirb_pprint::PrettyPrinterBase::avoidRegNameConflicts ( const std::string &  x)
protected

◆ AvoidRegNameConflicts()

std::string gtirb_pprint::PrettyPrinterBase::AvoidRegNameConflicts ( const std::string &  x)
staticprotected

◆ getAmbiguousSymbol()

std::vector<std::string>* gtirb_pprint::PrettyPrinterBase::getAmbiguousSymbol ( )
protected

◆ getContainerFunctionName()

std::optional< std::string > gtirb_pprint::PrettyPrinterBase::getContainerFunctionName ( const gtirb::Addr  x) const
protected

Get the name of the function containing an effective address. This implementation assumes that functions are tightly packed within a module; that is, it assumes that all addresses from the start of one function to the next is part of the first. It also assumes that the body of the last function in a module extends to the end of the module.

The locations of the functions are found in the "functionEntry" AuxData table.

Parameters
xthe address to check
Returns
the name of the containing function if one is found.

◆ getContainerSection()

const std::optional< const gtirb::Section * > gtirb_pprint::PrettyPrinterBase::getContainerSection ( const gtirb::Addr  addr) const
protected

◆ getForwardedSymbolName()

std::optional< std::string > gtirb_pprint::PrettyPrinterBase::getForwardedSymbolName ( const gtirb::Symbol *  symbol,
bool  isAbsolute 
) const
protected

◆ getFunctionName()

std::string gtirb_pprint::PrettyPrinterBase::getFunctionName ( gtirb::Addr  x) const
protected

◆ getGtirbOpIndex()

virtual int gtirb_pprint::PrettyPrinterBase::getGtirbOpIndex ( int  index,
int  opCount 
) const
protectedpure virtual

Get the index of an operand in the GTIRB, given the index of the operand in the Capstone instruction.

NOTE: The GTIRB operands are indexed as if they were in an array: auto operands[] = {<unused>, src1, src2, ..., dst}

Parameters
indexthe Capstone index of the operand
opCountthe total number of operands in the instruction

Implemented in gtirb_pprint::AttPrettyPrinter, and gtirb_pprint::IntelPrettyPrinter.

◆ getRegisterName()

std::string gtirb_pprint::PrettyPrinterBase::getRegisterName ( unsigned int  reg) const
protectedvirtual

Reimplemented in gtirb_pprint::AttPrettyPrinter.

◆ GetSizeName() [1/2]

std::string gtirb_pprint::PrettyPrinterBase::GetSizeName ( uint64_t  x)
staticprotected

◆ GetSizeName() [2/2]

std::string gtirb_pprint::PrettyPrinterBase::GetSizeName ( const std::string &  x)
staticprotected

◆ GetSizeSuffix() [1/2]

std::string gtirb_pprint::PrettyPrinterBase::GetSizeSuffix ( uint64_t  x)
staticprotected

◆ GetSizeSuffix() [2/2]

std::string gtirb_pprint::PrettyPrinterBase::GetSizeSuffix ( const std::string &  x)
staticprotected

◆ getSymbolicImmediate()

const gtirb::SymAddrConst * gtirb_pprint::PrettyPrinterBase::getSymbolicImmediate ( const gtirb::SymbolicExpression *  symex)
protectedvirtual

Return the SymAddrConst expression if it refers to a printed symbol.

Parameters
symexthe SymbolicExpression to check

◆ GetSymbolToPrint()

std::string gtirb_pprint::PrettyPrinterBase::GetSymbolToPrint ( gtirb::Addr  x)
staticprotected

◆ isAmbiguousSymbol()

bool gtirb_pprint::PrettyPrinterBase::isAmbiguousSymbol ( const std::string &  ea) const
protected

◆ isInSkippedFunction()

bool gtirb_pprint::PrettyPrinterBase::isInSkippedFunction ( const gtirb::Addr  x) const
protected

◆ isInSkippedSection()

bool gtirb_pprint::PrettyPrinterBase::isInSkippedSection ( const gtirb::Addr  x) const
protected

◆ isSectionSkipped()

bool gtirb_pprint::PrettyPrinterBase::isSectionSkipped ( const std::string &  name)
protected

◆ print()

std::ostream & gtirb_pprint::PrettyPrinterBase::print ( std::ostream &  out)
virtual

◆ printAddend()

void gtirb_pprint::PrettyPrinterBase::printAddend ( std::ostream &  os,
int64_t  number,
bool  first = false 
)
protectedvirtual

◆ printAlignment()

void gtirb_pprint::PrettyPrinterBase::printAlignment ( std::ostream &  os,
const gtirb::Addr  addr 
)
protectedvirtual

◆ printBar()

void gtirb_pprint::PrettyPrinterBase::printBar ( std::ostream &  os,
bool  heavy = true 
)
protectedvirtual

◆ printBlock()

void gtirb_pprint::PrettyPrinterBase::printBlock ( std::ostream &  os,
const gtirb::Block &  x 
)
protectedvirtual

◆ printBlockOrWarning()

gtirb::Addr gtirb_pprint::PrettyPrinterBase::printBlockOrWarning ( std::ostream &  os,
const gtirb::Block &  x,
gtirb::Addr  last 
)
protectedvirtual

Print the block as long as it does not overlap with the address last. If it overlaps, print a warning instead. Return the ending address of the block if this was printed. Otherwise return last.

◆ printComment()

void gtirb_pprint::PrettyPrinterBase::printComment ( std::ostream &  os,
const gtirb::Addr  ea 
)
protectedvirtual

◆ printDataObject()

void gtirb_pprint::PrettyPrinterBase::printDataObject ( std::ostream &  os,
const gtirb::DataObject &  dataObject 
)
protectedvirtual

◆ printDataObjectOrWarning()

gtirb::Addr gtirb_pprint::PrettyPrinterBase::printDataObjectOrWarning ( std::ostream &  os,
const gtirb::DataObject &  x,
gtirb::Addr  last 
)
protectedvirtual

Print the dataObject as long as it does not overlap with the address last. If it overlaps, print a warning instead. Return the ending address of the block if this was printed. Otherwise return last.

◆ printEA()

void gtirb_pprint::PrettyPrinterBase::printEA ( std::ostream &  os,
gtirb::Addr  ea 
)
protectedvirtual

◆ printFunctionHeader()

void gtirb_pprint::PrettyPrinterBase::printFunctionHeader ( std::ostream &  os,
gtirb::Addr  ea 
)
protectedvirtual

◆ printHeader()

virtual void gtirb_pprint::PrettyPrinterBase::printHeader ( std::ostream &  os)
protectedpure virtual

◆ printInstruction()

void gtirb_pprint::PrettyPrinterBase::printInstruction ( std::ostream &  os,
const cs_insn &  inst 
)
protectedvirtual

Print a single instruction to the stream. This implementation prints the mnemonic provided by Capstone, then calls printOperandList(). Thus, it is probably sufficient for most subclasses to configure Capstone to produce the correct mnemonics (e.g., to include an operand size suffix) and not modify this method.

Parameters
osthe output stream to print to
instthe instruction to print

◆ printNonZeroDataObject()

void gtirb_pprint::PrettyPrinterBase::printNonZeroDataObject ( std::ostream &  os,
const gtirb::DataObject &  dataObject 
)
protectedvirtual

◆ printOperand()

void gtirb_pprint::PrettyPrinterBase::printOperand ( std::ostream &  os,
const gtirb::SymbolicExpression *  symbolic,
const cs_insn &  inst,
uint64_t  index 
)
protectedvirtual

◆ printOperandList()

void gtirb_pprint::PrettyPrinterBase::printOperandList ( std::ostream &  os,
const gtirb::Addr  ea,
const cs_insn &  inst 
)
protectedvirtual

◆ printOpImmediate()

virtual void gtirb_pprint::PrettyPrinterBase::printOpImmediate ( std::ostream &  os,
const gtirb::SymbolicExpression *  symbolic,
const cs_insn &  inst,
uint64_t  index 
)
protectedpure virtual

◆ printOpIndirect()

virtual void gtirb_pprint::PrettyPrinterBase::printOpIndirect ( std::ostream &  os,
const gtirb::SymbolicExpression *  symbolic,
const cs_insn &  inst,
uint64_t  index 
)
protectedpure virtual

◆ printOpRegdirect()

virtual void gtirb_pprint::PrettyPrinterBase::printOpRegdirect ( std::ostream &  os,
const cs_insn &  inst,
const cs_x86_op &  op 
)
protectedpure virtual

◆ printOverlapWarning()

void gtirb_pprint::PrettyPrinterBase::printOverlapWarning ( std::ostream &  os,
gtirb::Addr  ea 
)
protectedvirtual

◆ printSectionHeader()

void gtirb_pprint::PrettyPrinterBase::printSectionHeader ( std::ostream &  os,
const gtirb::Addr  addr 
)
protectedvirtual

◆ printString()

void gtirb_pprint::PrettyPrinterBase::printString ( std::ostream &  os,
const gtirb::DataObject &  x 
)
protectedvirtual

◆ printSymbolDefinitionsAtAddress()

void gtirb_pprint::PrettyPrinterBase::printSymbolDefinitionsAtAddress ( std::ostream &  os,
gtirb::Addr  ea 
)
protectedvirtual

◆ printSymbolicData()

void gtirb_pprint::PrettyPrinterBase::printSymbolicData ( std::ostream &  os,
const gtirb::SymbolicExpression *  symbolic 
)
protectedvirtual

◆ printSymbolicExpression() [1/2]

void gtirb_pprint::PrettyPrinterBase::printSymbolicExpression ( std::ostream &  os,
const gtirb::SymAddrConst *  sexpr,
bool  inData = false 
)
protectedvirtual

◆ printSymbolicExpression() [2/2]

void gtirb_pprint::PrettyPrinterBase::printSymbolicExpression ( std::ostream &  os,
const gtirb::SymAddrAddr *  sexpr,
bool  inData = false 
)
protectedvirtual

◆ printSymbolReference()

void gtirb_pprint::PrettyPrinterBase::printSymbolReference ( std::ostream &  os,
const gtirb::Symbol *  symbol,
bool  inData 
) const
protectedvirtual

◆ printZeroDataObject()

void gtirb_pprint::PrettyPrinterBase::printZeroDataObject ( std::ostream &  os,
const gtirb::DataObject &  dataObject 
)
protectedvirtual

◆ shouldExcludeDataElement()

bool gtirb_pprint::PrettyPrinterBase::shouldExcludeDataElement ( const gtirb::Section &  section,
const gtirb::DataObject &  dataObject 
) const
protected

◆ skipEA()

bool gtirb_pprint::PrettyPrinterBase::skipEA ( const gtirb::Addr  x) const
protected

Member Data Documentation

◆ AsmArraySection

const std::unordered_set<std::string> gtirb_pprint::PrettyPrinterBase::AsmArraySection
protected
Initial value:
{".init_array",
".fini_array"}

◆ AsmSkipFunction

std::unordered_set<std::string> gtirb_pprint::PrettyPrinterBase::AsmSkipFunction
protected

Functions to avoid printing.

◆ AsmSkipSection

std::unordered_set<std::string> gtirb_pprint::PrettyPrinterBase::AsmSkipSection
protected
Initial value:
{
".comment", ".plt", ".init", ".fini", ".got", ".plt.got", ".got.plt"}

Sections to avoid printing.

◆ context

gtirb::Context& gtirb_pprint::PrettyPrinterBase::context
protected

◆ csHandle

csh gtirb_pprint::PrettyPrinterBase::csHandle
protected

◆ debug

bool gtirb_pprint::PrettyPrinterBase::debug
protected

◆ ir

gtirb::IR& gtirb_pprint::PrettyPrinterBase::ir
protected

◆ StrNOP

const std::string gtirb_pprint::PrettyPrinterBase::StrNOP {"nop"}
protected

◆ StrSection

const std::string gtirb_pprint::PrettyPrinterBase::StrSection {".section"}
protected

◆ StrSectionBSS

const std::string gtirb_pprint::PrettyPrinterBase::StrSectionBSS {".bss"}
protected

◆ StrSectionGlobal

const std::string gtirb_pprint::PrettyPrinterBase::StrSectionGlobal {".globl"}
protected

◆ StrSectionText

const std::string gtirb_pprint::PrettyPrinterBase::StrSectionText {".text"}
protected

◆ StrSectionType

const std::string gtirb_pprint::PrettyPrinterBase::StrSectionType {".type"}
protected

◆ StrTab

const std::string gtirb_pprint::PrettyPrinterBase::StrTab {" "}
protected

◆ StrZeroByte

const std::string gtirb_pprint::PrettyPrinterBase::StrZeroByte {".byte 0x00"}
protected

Constants to reduce (eliminate) magical strings inside the printer.


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