decompiler  1.0.0
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ghidra::Cover Class Reference

A description of the topological scope of a single variable object. More...

#include <cover.hh>

Public Member Functions

void clear (void)
 Clear this to an empty Cover.
 
int4 compareTo (const Cover &op2) const
 Give ordering of this and another Cover. More...
 
const CoverBlockgetCoverBlock (int4 i) const
 Get the CoverBlock corresponding to the i-th block. More...
 
int4 intersect (const Cover &op2) const
 Characterize the intersection between this and another Cover. More...
 
int4 intersectByBlock (int4 blk, const Cover &op2) const
 Characterize the intersection on a specific block. More...
 
void intersectList (vector< int4 > &listout, const Cover &op2, int4 level) const
 Generate a list of blocks that intersect. More...
 
bool contain (const PcodeOp *op, int4 max) const
 Does this contain the given PcodeOp. More...
 
int4 containVarnodeDef (const Varnode *vn) const
 Check the definition of a Varnode for containment. More...
 
void merge (const Cover &op2)
 Merge this with another Cover block by block. More...
 
void rebuild (const Varnode *vn)
 Reset this based on def-use of a single Varnode. More...
 
void addDefPoint (const Varnode *vn)
 Reset to the single point where the given Varnode is defined. More...
 
void addRefPoint (const PcodeOp *ref, const Varnode *vn)
 Add a variable read to this Cover. More...
 
void print (ostream &s) const
 Dump a description of this cover to stream. More...
 
map< int4, CoverBlock >::const_iterator begin (void) const
 Get beginning of CoverBlocks.
 
map< int4, CoverBlock >::const_iterator end (void) const
 Get end of CoverBlocks.
 

Private Member Functions

void addRefRecurse (const FlowBlock *bl)
 Fill-in this recursively from the given block. More...
 

Private Attributes

map< int4, CoverBlockcover
 block index -> CoverBlock
 

Static Private Attributes

static const CoverBlock emptyBlock
 Global empty CoverBlock for blocks not covered by this.
 

Detailed Description

A description of the topological scope of a single variable object.

The topological scope of a variable within a function is the set of locations within the code of the function where that variable holds a variable. For the decompiler, a high-level variable in this sense, HighVariable, is a collection of Varnode objects. In order to merge Varnodes into a HighVariable, the topological scope of each Varnode must not intersect because that would mean the high-level variable holds different values at the same point in the function.

Internally this is implemented as a map from basic block to their non-empty CoverBlock

Member Function Documentation

◆ addDefPoint()

void ghidra::Cover::addDefPoint ( const Varnode vn)

Reset to the single point where the given Varnode is defined.

Any previous cover is removed. Calling this with an input Varnode still produces a valid Cover.

Parameters
vnis the Varnode

References ghidra::Varnode::getDef(), ghidra::FlowBlock::getIndex(), ghidra::PcodeOp::getParent(), ghidra::Varnode::isInput(), ghidra::CoverBlock::setBegin(), and ghidra::CoverBlock::setEnd().

Referenced by ghidra::Merge::buildDominantCopy(), ghidra::Merge::checkCopyPair(), and ghidra::Merge::eliminateIntersect().

◆ addRefPoint()

void ghidra::Cover::addRefPoint ( const PcodeOp ref,
const Varnode vn 
)

Add a variable read to this Cover.

Given a Varnode being read and the PcodeOp which reads it, add the point of the read to this and recursively fill in backwards until we run into existing cover.

Parameters
refis the reading PcodeOp
vnis the Varnode being read

References ghidra::PcodeOp::code(), ghidra::CPUI_MULTIEQUAL, ghidra::PcodeOp::getIn(), ghidra::FlowBlock::getIn(), ghidra::FlowBlock::getIndex(), ghidra::PcodeOp::getParent(), ghidra::CoverBlock::getUIndex(), ghidra::PcodeOp::numInput(), ghidra::CoverBlock::setEnd(), and ghidra::FlowBlock::sizeIn().

Referenced by ghidra::Merge::buildDominantCopy(), ghidra::Merge::checkCopyPair(), and ghidra::Merge::eliminateIntersect().

◆ addRefRecurse()

void ghidra::Cover::addRefRecurse ( const FlowBlock bl)
private

Fill-in this recursively from the given block.

Add to this Cover recursively, starting at bottom of the given block and filling in backward until we run into existing cover.

Parameters
blis the starting block to add

References ghidra::PcodeOp::code(), ghidra::CPUI_MULTIEQUAL, ghidra::FlowBlock::getIn(), ghidra::FlowBlock::getIndex(), ghidra::CoverBlock::getUIndex(), ghidra::CoverBlock::setAll(), and ghidra::FlowBlock::sizeIn().

◆ compareTo()

int4 ghidra::Cover::compareTo ( const Cover op2) const

Give ordering of this and another Cover.

Compare this with another Cover by comparing just the indices of the first blocks respectively that are partly covered. Return -1, 0, or 1 if this Cover's first block has a smaller, equal, or bigger index than the other Cover's first block.

Parameters
op2is the other Cover
Returns
the comparison value

References cover.

Referenced by ghidra::Merge::compareHighByBlock().

◆ contain()

bool ghidra::Cover::contain ( const PcodeOp op,
int4  max 
) const

Does this contain the given PcodeOp.

Parameters
opis the given PcodeOp
maxis 1 to test for any containment, 2 to force interior containment
Returns
true if there is containment

References ghidra::FlowBlock::getIndex(), and ghidra::PcodeOp::getParent().

Referenced by ghidra::Merge::checkCopyPair(), and ghidra::ActionMarkImplied::checkImpliedCover().

◆ containVarnodeDef()

int4 ghidra::Cover::containVarnodeDef ( const Varnode vn) const

Check the definition of a Varnode for containment.

If the given Varnode has a defining PcodeOp this is checked for containment. If the Varnode is an input, check if this covers the start of the function.

Return:

  • 0 if cover does not contain varnode definition
  • 1 if there if it is contained in interior
  • 2 if the defining points intersect
  • 3 if Cover's tail is the varnode definition
Parameters
vnis the given Varnode
Returns
the containment characterization

References ghidra::Varnode::getDef(), ghidra::FlowBlock::getIndex(), and ghidra::PcodeOp::getParent().

Referenced by ghidra::Merge::eliminateIntersect(), and ghidra::Merge::hideShadows().

◆ getCoverBlock()

const CoverBlock & ghidra::Cover::getCoverBlock ( int4  i) const

Get the CoverBlock corresponding to the i-th block.

Return a representative CoverBlock describing how much of the given block is covered by this

Parameters
iis the index of the given block
Returns
a reference to the corresponding CoverBlock

Referenced by ghidra::Merge::collectCorrectable(), and ghidra::Merge::collectCovering().

◆ intersect()

int4 ghidra::Cover::intersect ( const Cover op2) const

Characterize the intersection between this and another Cover.

Return

  • 0 if there is no intersection
  • 1 if the only intersection is on a boundary point
  • 2 if the intersection contains a range of p-code ops
Parameters
op2is the other Cover
Returns
the intersection characterization

References cover.

Referenced by ghidra::Merge::buildDominantCopy(), ghidra::Merge::inflateTest(), ghidra::HighVariable::markExpression(), and ghidra::Merge::shadowedVarnode().

◆ intersectByBlock()

int4 ghidra::Cover::intersectByBlock ( int4  blk,
const Cover op2 
) const

Characterize the intersection on a specific block.

Looking only at the given block, Return

  • 0 if there is no intersection
  • 1 if the only intersection is on a boundary point
  • 2 if the intersection contains a range of p-code ops
Parameters
blkis the index of the given block
op2is the other Cover
Returns
the characterization

References cover.

Referenced by ghidra::HighIntersectTest::gatherBlockVarnodes(), and ghidra::HighIntersectTest::testBlockIntersection().

◆ intersectList()

void ghidra::Cover::intersectList ( vector< int4 > &  listout,
const Cover op2,
int4  level 
) const

Generate a list of blocks that intersect.

For each block for which this and another Cover intersect, and the block's index to a result list if the type of intersection exceeds a characterization level.

Parameters
listoutwill hold the list of intersecting block indices
op2is the other Cover
levelis the characterization threshold which must be exceeded

References cover.

Referenced by ghidra::HighIntersectTest::intersection().

◆ merge()

void ghidra::Cover::merge ( const Cover op2)

Merge this with another Cover block by block.

Parameters
op2is the other Cover

References cover.

Referenced by ghidra::Merge::buildDominantCopy(), ghidra::Merge::inflate(), and ghidra::HighVariable::markExpression().

◆ print()

void ghidra::Cover::print ( ostream &  s) const

Dump a description of this cover to stream.

Parameters
sis the output stream

Referenced by ghidra::HighVariable::printCover().

◆ rebuild()

void ghidra::Cover::rebuild ( const Varnode vn)

Reset this based on def-use of a single Varnode.

The cover is set to all p-code ops between the point where the Varnode is defined and all the points where it is read

Parameters
vnis the single Varnode

References ghidra::Varnode::beginDescend(), and ghidra::Varnode::endDescend().


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