[DynInst_API:] Patching every basic block of a given elf binary


Date: Sat, 22 Aug 2015 22:06:47 -0400
From: Shuai Wang <wangshuai901@xxxxxxxxx>
Subject: [DynInst_API:] Patching every basic block of a given elf binary
Dear list,


I am a newbie to DynInst, and I am trying to instrument every basic blocks of a given elf binary. For example, to insert a basic block counter at the beginning of each basic block.

I installed DynInst 8.2.1, and modified the example in DynInstAPI's appendix A, some code snippet like this:


Â.....

BPatch_point *entryPointBB(BPatch_basicBlock *bb) {
  BPatch_point *points;
  points = bb->findPoint(BPatch_entry);

  return points;
}

void binaryAnalysis(BPatch_addressSpace *app) {
  BPatch_image *appImage = app->getImage();
  int insns_access_memory = 0;
  std::vector<BPatch_function *> funcs;
  appImage->findFunction("main", funcs);

  BPatch_flowGraph *fg = funcs[0]->getCFG();
  std::set<BPatch_basicBlock *> blocks;
  fg->getAllBasicBlocks(blocks);

  std::set<BPatch_basicBlock *>::iterator block_iter;
  for (block_iter = blocks.begin(); block_iter != blocks.end(); ++block_iter)
  {
    BPatch_basicBlock *block = *block_iter;

    BPatch_point * ps = ÂentryPointBB(block);

    //patchBB(app, ps);
    printf("%p\n", ps);  Â<------------------- (nil)
  }
}
....

However, after the compilation, when I tried to execute the code, I find that BPatch_point ps does not get any value. As a result, the last printf statement print out a nil for this empty pointer..


Here is my question: Am I missed anything? What should I do if I want to instrument every basic block at its front?

I really appreciate if anyone can give me some help. Thank you a lot!

Sincerely,
Shuai



[← Prev in Thread] Current Thread [Next in Thread→]