本文整理汇总了C++中BasicBlock::getInstruction方法的典型用法代码示例。如果您正苦于以下问题:C++ BasicBlock::getInstruction方法的具体用法?C++ BasicBlock::getInstruction怎么用?C++ BasicBlock::getInstruction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BasicBlock
的用法示例。
在下文中一共展示了BasicBlock::getInstruction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: instrument
//.........这里部分代码省略.........
PRINT_ERROR("Cannot find an instrumentation point at the entry block");
}
uint64_t noDataAddr = getInstDataAddress() + reserveDataOffset(strlen(NOSTRING) + 1);
char* nostring = new char[strlen(NOSTRING) + 1];
sprintf(nostring, "%s\0", NOSTRING);
initializeReservedData(noDataAddr, strlen(NOSTRING) + 1, nostring);
PRINT_DEBUG_MEMTRACK("There are %d instrumentation points", getNumberOfExposedBasicBlocks());
Vector<BasicBlock*>* allBlocks = new Vector<BasicBlock*>();
Vector<LineInfo*>* allLineInfos = new Vector<LineInfo*>();
uint32_t noProtPoints = 0;
uint32_t complexSelection = 0;
for (uint32_t i = 0; i < getNumberOfExposedBasicBlocks(); i++){
BasicBlock* bb = getExposedBasicBlock(i);
LineInfo* li = NULL;
if (lineInfoFinder){
li = lineInfoFinder->lookupLineInfo(bb);
}
Function* f = bb->getFunction();
(*allBlocks).append(bb);
(*allLineInfos).append(li);
if (i % 1000 == 0){
PRINT_DEBUG_MEMTRACK("inst point %d", i);
PRINT_MEMTRACK_STATS(__LINE__, __FILE__, __FUNCTION__);
}
if (li){
uint32_t line = li->GET(lr_line);
initializeReservedData(getInstDataAddress() + lineArray + sizeof(uint32_t)*i, sizeof(uint32_t), &line);
uint64_t filename = reserveDataOffset(strlen(li->getFileName()) + 1);
uint64_t filenameAddr = getInstDataAddress() + filename;
initializeReservedData(getInstDataAddress() + fileNameArray + i*sizeof(char*), sizeof(char*), &filenameAddr);
initializeReservedData(getInstDataAddress() + filename, strlen(li->getFileName()) + 1, (void*)li->getFileName());
} else {
temp32 = 0;
initializeReservedData(getInstDataAddress() + lineArray + sizeof(uint32_t)*i, sizeof(uint32_t), &temp32);
initializeReservedData(getInstDataAddress() + fileNameArray + i*sizeof(char*), sizeof(char*), &noDataAddr);
}
uint64_t funcname = reserveDataOffset(strlen(f->getName()) + 1);
uint64_t funcnameAddr = getInstDataAddress() + funcname;
initializeReservedData(getInstDataAddress() + funcNameArray + i*sizeof(char*), sizeof(char*), &funcnameAddr);
initializeReservedData(getInstDataAddress() + funcname, strlen(f->getName()) + 1, (void*)f->getName());
uint64_t hashValue = bb->getHashCode().getValue();
initializeReservedData(getInstDataAddress() + hashCodeArray + i*sizeof(uint64_t), sizeof(uint64_t), &hashValue);
InstrumentationSnippet* snip = new InstrumentationSnippet();
uint64_t counterOffset = counterArray + (i * sizeof(uint32_t));
// snippet contents, in this case just increment a counter
if (is64Bit()){
snip->addSnippetInstruction(X86InstructionFactory64::emitAddImmByteToMem(1, getInstDataAddress() + counterOffset));
} else {
snip->addSnippetInstruction(X86InstructionFactory32::emitAddImmByteToMem(1, getInstDataAddress() + counterOffset));
}
// do not generate control instructions to get back to the application, this is done for
// the snippet automatically during code generation
// register the snippet we just created
addInstrumentationSnippet(snip);
// register an instrumentation point at the function that uses this snippet
FlagsProtectionMethods prot = FlagsProtectionMethod_light;
#ifndef NO_REG_ANALYSIS
if (bb->getLeader()->allFlagsDeadIn()){
prot = FlagsProtectionMethod_none;
noProtPoints++;
}
for (uint32_t j = 0; j < bb->getNumberOfInstructions(); j++){
if (bb->getInstruction(j)->allFlagsDeadIn() || bb->getInstruction(j)->allFlagsDeadOut()){
complexSelection++;
break;
}
}
#endif
InstrumentationPoint* p = addInstrumentationPoint(bb, snip, InstrumentationMode_inline, prot);
}
PRINT_MEMTRACK_STATS(__LINE__, __FILE__, __FUNCTION__);
#ifdef NO_REG_ANALYSIS
PRINT_WARN(10, "Warning: register analysis disabled");
#endif
PRINT_INFOR("Excluding flags protection for %d/%d instrumentation points", noProtPoints, getNumberOfExposedBasicBlocks());
//PRINT_INFOR("complex inst point selection: %d/%d instrumentation points", complexSelection, getNumberOfExposedBasicBlocks());
printStaticFile(allBlocks, allLineInfos);
delete[] nostring;
delete allBlocks;
delete allLineInfos;
ASSERT(currentPhase == ElfInstPhase_user_reserve && "Instrumentation phase order must be observed");
}
示例2: computeDefUseDist
void FlowGraph::computeDefUseDist(){
uint32_t fcnt = function->getNumberOfInstructions();
std::pebil_map_type<uint64_t, X86Instruction*> imap;
std::pebil_map_type<uint64_t, BasicBlock*> bmap;
std::pebil_map_type<uint64_t, LinkedList<X86Instruction::ReachingDefinition*>*> alliuses;
std::pebil_map_type<uint64_t, LinkedList<X86Instruction::ReachingDefinition*>*> allidefs;
for (uint32_t i = 0; i < basicBlocks.size(); i++){
BasicBlock* bb = basicBlocks[i];
for (uint32_t j = 0; j < bb->getNumberOfInstructions(); j++){
X86Instruction* x = bb->getInstruction(j);
for (uint32_t k = 0; k < x->getSizeInBytes(); k++){
ASSERT(imap.count(x->getBaseAddress() + k) == 0);
ASSERT(bmap.count(x->getBaseAddress() + k) == 0);
imap[x->getBaseAddress() + k] = x;
bmap[x->getBaseAddress() + k] = bb;
}
ASSERT(alliuses.count(x->getBaseAddress()) == 0);
ASSERT(allidefs.count(x->getBaseAddress()) == 0);
alliuses[x->getBaseAddress()] = x->getUses();
allidefs[x->getBaseAddress()] = x->getDefs();
}
}
// For each loop
for (uint32_t i = 0; i < loops.size(); ++i) {
BasicBlock** allLoopBlocks = new BasicBlock*[loops[i]->getNumberOfBlocks()];
loops[i]->getAllBlocks(allLoopBlocks);
uint64_t loopLeader = loops[i]->getHead()->getBaseAddress();
// For each block
for (uint32_t j = 0; j < loops[i]->getNumberOfBlocks(); ++j){
BasicBlock* bb = allLoopBlocks[j];
// For each instruction
for (uint32_t k = 0; k < bb->getNumberOfInstructions(); ++k){
X86Instruction* ins = bb->getInstruction(k);
// Skip the instruction if it can't define anything
if (!ins->isIntegerOperation() && !ins->isFloatPOperation() && !ins->isMoveOperation()) {
continue;
}
ASSERT(!ins->usesControlTarget());
singleDefUse(this, ins, bb, loops[i], imap, bmap, alliuses, allidefs, k, loopLeader, fcnt);
}
}
delete[] allLoopBlocks;
}
// handle all non-loop blocks
for (uint32_t i = 0; i < getNumberOfBasicBlocks(); i++){
BasicBlock* bb = basicBlocks[i];
if (!isBlockInLoop(bb->getIndex())){
for (uint32_t k = 0; k < bb->getNumberOfInstructions(); ++k){
X86Instruction* ins = bb->getInstruction(k);
if (!ins->isIntegerOperation() && !ins->isFloatPOperation() && !ins->isMoveOperation()) {
continue;
}
ASSERT(!ins->usesControlTarget());
singleDefUse(this, ins, bb, NULL, imap, bmap, alliuses, allidefs, k, 0, fcnt);
}
}
}
for (uint32_t i = 0; i < basicBlocks.size(); i++){
BasicBlock* bb = basicBlocks[i];
for (uint32_t j = 0; j < bb->getNumberOfInstructions(); j++){
X86Instruction* x = bb->getInstruction(j);
uint64_t addr = x->getBaseAddress();
ASSERT(alliuses.count(addr) == 1);
LinkedList<X86Instruction::ReachingDefinition*>* l = alliuses[addr];
alliuses.erase(addr);
while (!l->empty()){
delete l->shift();
}
delete l;
ASSERT(allidefs.count(addr) == 1);
l = allidefs[addr];
allidefs.erase(addr);
while (!l->empty()){
delete l->shift();
}
delete l;
}
}
ASSERT(alliuses.size() == 0);
ASSERT(allidefs.size() == 0);
}