[LLVMdev] How to explain this weird phenomenon????????

15102925731 zhenkaixd at 126.com
Tue Apr 10 04:34:51 PDT 2012


 My friends,

I ran a function pass on a .bc file, intending to insert a CallInst to my self-made check function.

The compilation is successful. BUT after I ran that pass on the .bc file, the size of the file didn't get any bigger!!
Does this mean my instrumentation work failed??

BTW  the opt command I use is "opt -load ../../../Debug+Asserts/lib/Hello.so -hello  <hello.bc> -o hello.bc"
Does this command mean to run hello pass on hello.bc and send the result to hello.bc???

The source code of the function pass is as follow.
// for each function traverse the instruction in it
                            for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI)
                             {
                                for(BasicBlock::iterator II = BI->begin(),IE = BI->end();II != IE; ++II)
                                 {
                                      // we only care the instruction that call for functions and it can be cast to CallInst
                                        if(CallInst * III = dyn_cast<CallInst>(II))
                                         {
                                      // if the callInst is calling for puts function
                                             if(III->getCalledFunction()!=NULL&&III->getCalledFunction()->getName()=="puts")
                                             {
                                                     errs() <<III->getCalledFunction()->getName()<<" function found!\n";
                                                  // declare the extern function(int check()) that I want to instrument in the .bc file
                                                     Function *check =  cast<Function>(III->getCalledFunction()->getParent()->getOrInsertFunction("check",
                                          Type::getInt32Ty(III->getCalledFunction()->getParent()->getContext()),
                                          (Type *)0));
                                           // Create the CallInst to call for the check function!
CallInst *callcheck = CallInst::Create(check,"CallCheck");
                                          // insert the CallInst right before II
                                                callcheck->insertBefore(II);

                                                      errs() <<"INSERT SUCCEEDED!!!!!!!!\n";
                                              }
                                              else
                                             {
                                                  errs() <<"it's not main function!\n"<<"it is:"<<III->getCalledFunction()->getName()<<'\n';
                                              }
                                        }
                                }

     


--

            祝好!
 
  甄凯
------------------------------------------------------------------------------------------------------
2012-04-10
------------------------------------------------------------------------------------------------------
Name: 甄凯(ZhenKai)
Homepage:http://www.renren.com/262729393
Email: zhenkaixd at 126.com or 846227103 at qq.com
TEL: 15810729006(Beijing)
Address: Room I-406, Central Building, Tsinghua University, Beijing, China. 100084.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120410/30529ce2/attachment.html>


More information about the llvm-dev mailing list