Problem on instrumentation

Hi,


I am instrumenting a piece of code. I want to insert a function call at the interested area, and do something in the called function which is written by myself.


I have succeed on implementing the pass, and getting the instrmented code. However, I am not sure where to put this function, and what kind of linkage I should use for this function.


Currently I use External linkage which is implemented as following:


LLVMContext& context=M.getContext();
FunctionType* FT=FunctionType::get(Type::getInt32Ty(context),false);
Function* F=Function::Create(FT,Function::ExternalLinkage,“myFunctionCall”,&M);


Is it OK? And also, where should I put the function “int myFunctionCall()”?


Thank you very much. I am expecting for your reply.


Regards
Andy
|

Hi,
I also want to insert a function call at the interested area, and do something in the called function which is written by myself.

First you need to determine the INSTRUCTION where you want to insert your function to. you can do this by writing some code like,
for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI)
for(BasicBlock::iterator II = BI->begin(),IE = BI->end();II != IE; ++II)

then use the insertBefore or insertAfter function.

I wonder how is your “instrumented code” like. Because I can insert a function that is wrapped in the module, but
the function may be wrapped so poorly that when I run the pass, the programme broke down.

Hi,
I 've already added you in my QQ list.

I’m wondering how you wrapped your self-written function in llvm-like language so it can be recognized when
you call it in the pass?

Best regards!