Skip to content

Commit

Permalink
Get rid of block_instance::srcs_ and block_instance:trgs_ .
Browse files Browse the repository at this point in the history
  • Loading branch information
wenbinf committed Jun 24, 2011
1 parent fde2c8e commit f531f72
Show file tree
Hide file tree
Showing 8 changed files with 1,147 additions and 1,151 deletions.
682 changes: 341 additions & 341 deletions dyninstAPI/src/BPatch_basicBlock.C

Large diffs are not rendered by default.

1,406 changes: 705 additions & 701 deletions dyninstAPI/src/BPatch_flowGraph.C

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions dyninstAPI/src/Relocation/CFG/RelocBlock.C
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,18 @@ void RelocBlock::getSuccessors(RelocGraph *cfg) {
// Edges to a block that does not correspond to a RelocBlock (BlockEdges)
// Edges to a raw address, caused by representing inter-CodeObject edges
// -- this last is a Defensive mode special.
const block_instance::edgelist &targets = block_->targets();
for (block_instance::edgelist::const_iterator iter = targets.begin(); iter != targets.end(); ++iter) {
processEdge(OutEdge, *iter, cfg);
/* const block_instance::edgelist &targets = block_->targets();
for (block_instance::edgelist::const_iterator iter = targets.begin(); iter != targets.end(); ++iter) {*/
const PatchBlock::edgelist &targets = block_->getTargets();
for (PatchBlock::edgelist::const_iterator iter = targets.begin(); iter != targets.end(); ++iter) {
processEdge(OutEdge, SCAST_EI(*iter), cfg);
}
}

void RelocBlock::getPredecessors(RelocGraph *cfg) {
const block_instance::edgelist &edges = block_->sources();
for (block_instance::edgelist::const_iterator iter = edges.begin(); iter != edges.end(); ++iter) {
processEdge(InEdge, *iter, cfg);
const PatchBlock::edgelist &edges = block_->getSources();
for (PatchBlock::edgelist::const_iterator iter = edges.begin(); iter != edges.end(); ++iter) {
processEdge(InEdge, SCAST_EI(*iter), cfg);
}

}
Expand Down Expand Up @@ -316,14 +318,16 @@ void RelocBlock::createCFWidget() {
#endif

void RelocBlock::preserveBlockGap() {
const block_instance::edgelist &targets = block_->targets();
for (block_instance::edgelist::const_iterator iter = targets.begin(); iter != targets.end(); ++iter) {
/* const block_instance::edgelist &targets = block_->targets();
for (block_instance::edgelist::const_iterator iter = targets.begin(); iter != targets.end(); ++iter) {*/
const PatchBlock::edgelist &targets = block_->getTargets();
for (PatchBlock::edgelist::const_iterator iter = targets.begin(); iter != targets.end(); ++iter) {
if ((*iter)->type() == ParseAPI::CALL_FT ||
(*iter)->type() == ParseAPI::FALLTHROUGH ||
(*iter)->type() == ParseAPI::COND_NOT_TAKEN) {
// Okay, I admit - I want to see this code trigger in the
// fallthrough or cond_not_taken cases...
block_instance *target = (*iter)->trg();
block_instance *target = SCAST_EI(*iter)->trg();
if (target) {
cfWidget()->setGap(target->start() - block_->end());
return;
Expand Down
11 changes: 6 additions & 5 deletions dyninstAPI/src/Relocation/Transformers/Instrumenter.C
Original file line number Diff line number Diff line change
Expand Up @@ -289,20 +289,21 @@ bool Instrumenter::edgeInstrumentation(RelocBlock *trace, RelocGraph *cfg) {
assert(trace->type() == RelocBlock::Relocated);
block_instance *block = trace->block();
assert(block);
const block_instance::edgelist &targets = block->targets();
for (block_instance::edgelist::const_iterator iter = targets.begin();
const PatchBlock::edgelist &targets = block->getTargets();
for (PatchBlock::edgelist::const_iterator iter = targets.begin();
iter != targets.end(); ++iter) {
instPoint *point = NULL;
edge_instance* iedge = SCAST_EI(*iter);
if (trace->func()) {
// point = trace->func()->findPoint(instPoint::EdgeDuring, *iter, false);
point = trace->func()->edgePoint(*iter, false);
point = trace->func()->edgePoint(iedge, false);
}
if (!point || point->empty()) continue;

RelocBlock *instRelocBlock = RelocBlock::createInst(point, (*iter)->trg()->start(), (*iter)->trg(), trace->func());
RelocBlock *instRelocBlock = RelocBlock::createInst(point, iedge->trg()->start(), iedge->trg(), trace->func());
cfg->addRelocBlockAfter(trace, instRelocBlock);

Predicates::Edge pred(*iter);
Predicates::Edge pred(iedge);
if (!cfg->interpose(pred, trace->outs(), instRelocBlock)) return false;
}
return true;
Expand Down
150 changes: 66 additions & 84 deletions dyninstAPI/src/block.C
Original file line number Diff line number Diff line change
Expand Up @@ -45,141 +45,123 @@ using namespace Dyninst::ParseAPI;

block_instance::block_instance(ParseAPI::Block *ib,
mapped_object *obj)
: PatchBlock(ib, obj) {
// We create edges lazily
: PatchBlock(ib, obj) {
// We create edges lazily
};

// Fork constructor
block_instance::block_instance(const block_instance *parent,
mapped_object *childObj)
mapped_object *childObj)
: PatchBlock(parent, childObj) {
// We also need to copy edges.
// Thing is, those blocks may not exist yet...
// So we wait, and do edges after all blocks have
// been created
// We also need to copy edges.
// Thing is, those blocks may not exist yet...
// So we wait, and do edges after all blocks have
// been created
}

block_instance::~block_instance() {}

AddressSpace *block_instance::addrSpace() const {
return obj()->proc();
return obj()->proc();
}


edge_instance *block_instance::getFallthrough() {
for (edgelist::const_iterator iter = targets().begin(); iter != targets().end(); ++iter) {
if ((*iter)->type() == FALLTHROUGH ||
(*iter)->type() == CALL_FT ||
(*iter)->type() == COND_NOT_TAKEN) {
return *iter;
}
}
return NULL;
for (edgelist::const_iterator iter = getTargets().begin(); iter != getTargets().end(); ++iter) {
if ((*iter)->type() == FALLTHROUGH ||
(*iter)->type() == CALL_FT ||
(*iter)->type() == COND_NOT_TAKEN) {
return SCAST_EI(*iter);
}
}
return NULL;
}

block_instance *block_instance::getFallthroughBlock() {
edge_instance *ft = getFallthrough();
if (ft &&
!ft->sinkEdge())
return ft->trg();
else
return NULL;
edge_instance *ft = getFallthrough();
if (ft &&
!ft->sinkEdge())
return ft->trg();
else
return NULL;
}

edge_instance *block_instance::getTarget() {
for (edgelist::const_iterator iter = targets().begin(); iter != targets().end(); ++iter) {
if ((*iter)->type() == CALL ||
(*iter)->type() == DIRECT ||
(*iter)->type() == COND_TAKEN) {
return *iter;
}
}
return NULL;
for (edgelist::const_iterator iter = getTargets().begin(); iter != getTargets().end(); ++iter) {
if ((*iter)->type() == CALL ||
(*iter)->type() == DIRECT ||
(*iter)->type() == COND_TAKEN) {
return SCAST_EI(*iter);
}
}
return NULL;
}

block_instance *block_instance::getTargetBlock() {
edge_instance *t = getFallthrough();
if (t &&
!t->sinkEdge())
return t->trg();
else
return NULL;
edge_instance *t = getFallthrough();
if (t &&
!t->sinkEdge())
return t->trg();
else
return NULL;
}

int block_instance::id() const {
return llb()->id();
return llb()->id();
}

using namespace Dyninst::Relocation;
void block_instance::triggerModified() {
// Relocation info caching...
//PCSensitiveTransformer::invalidateCache(this);
}

const block_instance::edgelist &block_instance::sources() {
if (srcs_.empty()) {
PatchBlock::edgelist& s = getSources();
for (PatchBlock::edgelist::iterator i = s.begin(); i != s.end(); i++)
srcs_.push_back(SCAST_EI(*i));
};
return srcs_;
}

const block_instance::edgelist &block_instance::targets() {
if (trgs_.empty()) {
PatchBlock::edgelist& s = getTargets();
for (PatchBlock::edgelist::iterator i = s.begin(); i != s.end(); i++)
trgs_.push_back(SCAST_EI(*i));
};
return trgs_;
// Relocation info caching...
//PCSensitiveTransformer::invalidateCache(this);
}

std::string block_instance::calleeName() {
// How the heck do we do this again?
return obj()->getCalleeName(this);
// How the heck do we do this again?
return obj()->getCalleeName(this);
}

void block_instance::updateCallTarget(func_instance *func) {
// Update a sink-typed call edge to
// have an inter-module target
edge_instance *e = getTarget();
assert(e->sinkEdge());
e->trg_ = func->entryBlock();
// Update a sink-typed call edge to
// have an inter-module target
edge_instance *e = getTarget();
assert(e->sinkEdge());
e->trg_ = func->entryBlock();
}


func_instance *block_instance::entryOfFunc() const {
parse_block *b = SCAST_PB(llb());
parse_func *e = b->getEntryFunc();
if (!e) return NULL;
return obj()->findFunction(e);
parse_block *b = SCAST_PB(llb());
parse_func *e = b->getEntryFunc();
if (!e) return NULL;
return obj()->findFunction(e);
}

bool block_instance::isFuncExit() const {
parse_block *b = SCAST_PB(llb());
return b->isExitBlock();
parse_block *b = SCAST_PB(llb());
return b->isExitBlock();
}

func_instance *block_instance::findFunction(ParseAPI::Function *p) {
return obj()->findFunction(p);
return obj()->findFunction(p);
}


void *block_instance::getPtrToInstruction(Address addr) const {
if (addr < start()) return NULL;
if (addr > end()) return NULL;
return obj()->getPtrToInstruction(addr);
if (addr < start()) return NULL;
if (addr > end()) return NULL;
return obj()->getPtrToInstruction(addr);
}

void block_instance::destroy(block_instance *b) {
// Put things here that should go away when we destroy a block.
// Iterate through functions...

std::vector<ParseAPI::Function *> pFuncs;
b->llb()->getFuncs(pFuncs);
for (unsigned i = 0; i < pFuncs.size(); ++i) {
func_instance *func = b->findFunction(pFuncs[i]);
func->destroyBlock(b);
}
delete b;
// Put things here that should go away when we destroy a block.
// Iterate through functions...

std::vector<ParseAPI::Function *> pFuncs;
b->llb()->getFuncs(pFuncs);
for (unsigned i = 0; i < pFuncs.size(); ++i) {
func_instance *func = b->findFunction(pFuncs[i]);
func->destroyBlock(b);
}
delete b;
}
12 changes: 6 additions & 6 deletions dyninstAPI/src/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class block_instance : public Dyninst::PatchAPI::PatchBlock {
friend class mapped_object;

public:
typedef std::vector<edge_instance *> edges;
typedef std::vector<edge_instance *> edgelist;
//typedef std::vector<edge_instance *> edges;
//typedef std::vector<edge_instance *> edgelist;

block_instance(ParseAPI::Block *ib, mapped_object *obj);
block_instance(const block_instance *parent, mapped_object *child);
Expand All @@ -74,8 +74,8 @@ class block_instance : public Dyninst::PatchAPI::PatchBlock {
parse_block * llb() const { return SCAST_PB(block_); }
void *getPtrToInstruction(Address addr) const;

const edgelist &sources();
const edgelist &targets();
//const edgelist &sources();
//const edgelist &targets();

// Shortcuts
edge_instance *getTarget();
Expand All @@ -100,8 +100,8 @@ class block_instance : public Dyninst::PatchAPI::PatchBlock {
void updateCallTarget(func_instance *func);
func_instance *findFunction(ParseAPI::Function *);

edges srcs_;
edges trgs_;
// edges srcs_;
// edges trgs_;

BlockInstpoints points_;
};
Expand Down
8 changes: 6 additions & 2 deletions dyninstAPI/src/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,15 @@ void func_instance::getCallerBlocks(OutputIterator result)
{
if(!ifunc() || !ifunc()->entryBlock())
return;

/*
const block_instance::edgelist &ins = entryBlock()->sources();
for (block_instance::edgelist::const_iterator iter = ins.begin();
iter != ins.end(); ++iter) {
*result = (*iter)->src();
*/
const PatchBlock::edgelist &ins = entryBlock()->getSources();
for (PatchBlock::edgelist::const_iterator iter = ins.begin();
iter != ins.end(); ++iter) {
*result = SCAST_EI(*iter)->src();
++result;
}
}
Expand Down
7 changes: 4 additions & 3 deletions dyninstAPI/src/hybridInstrumentation.C
Original file line number Diff line number Diff line change
Expand Up @@ -1110,9 +1110,10 @@ bool HybridAnalysis::hasEdge(BPatch_function *func, Address source, Address targ
// 0. first see if the edge needs to be parsed

block_instance *block = func->lowlevel_func()->obj()->findBlockByEntry(source);
const block_instance::edgelist &targets = block->targets();
for (block_instance::edgelist::const_iterator iter = targets.begin(); iter != targets.end(); ++iter) {
if ((*iter)->trg()->start() == target)
const PatchBlock::edgelist &targets = block->getTargets();
for (PatchBlock::edgelist::const_iterator iter = targets.begin(); iter != targets.end(); ++iter) {

if (SCAST_EI(*iter)->trg()->start() == target)
return true;
}
return false;
Expand Down

0 comments on commit f531f72

Please sign in to comment.