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>
I figured that my opt command is wrong!  How to specify the output file anyway??
if I want hello.bc to be input file and newhello.bc to be output file, is the
opt command go like this?
opt -load ../../../Debug+Asserts/lib/Hello.so -hello  <hello.bc> -o
newhello.bc  ??
--
            祝好!
 
  甄凯
------------------------------------------------------------------------------------------------------
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.
At 2012-04-10 19:34:51,15102925731 <zhenkaixd at 126.com> wrote:
 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/70728456/attachment.html>
I 've checked the introduction of the opt-tool on"
http://llvm.org/releases/1.0/docs/CommandGuide/opt.html "
And it says
-o <filename>
Specify the output filename.
but I tried "opt -load ../../../Debug+Asserts/lib/Hello.so -hello 
<hello.bc> -o newhello.bc" and get
"opt: newhello.bc: error: Could not openinput file: No such file or
directory"
It's not output file!
Any help?
--
            祝好!
 
  甄凯
------------------------------------------------------------------------------------------------------
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.
At 2012-04-10 19:38:36,15102925731 <zhenkaixd at 126.com> wrote:
I figured that my opt command is wrong!  How to specify the output file anyway??
if I want hello.bc to be input file and newhello.bc to be output file, is the
opt command go like this?
opt -load ../../../Debug+Asserts/lib/Hello.so -hello  <hello.bc> -o
newhello.bc  ??
--
            祝好!
 
  甄凯
------------------------------------------------------------------------------------------------------
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.
At 2012-04-10 19:34:51,15102925731 <zhenkaixd at 126.com> wrote:
 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/5080e293/attachment.html>
Hi,> BTW the opt command I use is *"opt -load ../../../Debug+Asserts/lib/Hello.so > -hello <hello.bc> -o hello.bc"*just use hello.bc not <hello.bc> otherwise the shell will redirect input and output. Ciao, Duncan.
I did it !!!!
YOU MADE MY DAY  !!!!!!!!!!!!!!!
--
            祝好!
 
  甄凯
------------------------------------------------------------------------------------------------------
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.
At 2012-04-10 19:55:04,"Duncan Sands" <baldrick at free.fr>
wrote:>Hi,
>
>> BTW the opt command I use is *"opt -load
../../../Debug+Asserts/lib/Hello.so
>> -hello <hello.bc> -o hello.bc"*
>
>just use hello.bc not <hello.bc> otherwise the shell will redirect
input and
>output.
>
>Ciao, Duncan.
>_______________________________________________
>LLVM Developers mailing list
>LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20120410/83ad69da/attachment.html>
Maybe Matching Threads
- [LLVMdev] How to explain this weird phenomenon????????
- [LLVMdev] How to explain this weird phenomenon????????
- [LLVMdev] How to explain this weird phenomenon????????
- [LLVMdev] How to explain this weird phenomenon????????
- [LLVMdev] How to compile a linux module into .bc file using clang or llvm command?