[LLVMdev] How to get the name and argument of a function

songlh at cs.wisc.edu songlh at cs.wisc.edu
Mon Jan 17 18:53:46 PST 2011


Thanks a lot!

I can get the call place now. But still have problems in getting the
argument.

CallInst * pCall;

......

pCall->getArgOperand(0)->dump();

I can get "i8* getelementptr inbounds ([5 x i8]* @.str, i32 0, i32 0)"

I think this means that the variable is a global constant string. Do you
know how to get the name of this global string, and how to use the name to
get the string value?

Btw: when I use pCall->getArgOperand(0)->getName(), I can only get "".

thanks a lot!

Linhai

> songlh at cs.wisc.edu wrote:
>> Hi everyone:
>>
>>     The code I am analyzing is :
>>
>>     int main()
>>     {
>>         int i = 0;
>>         printf("hello world!");
>>         printf( "%d" , i );
>>     }
>>
>>
>>
>>     I want to get each place where printf is called, and the argument
>> used
>> during that call.
>>
>>     so I write llvm pass code like:
>>
>>     void Myfunction( Function&  F){
>>         for( Function::iterator b = F.begin() , be = F.end() ;
>>          b != be; ++b){
>>             for(BasicBlock::iterator i = b.begin() , ie = b.end();
>>              i != ie; i ++){
>>                 if( isa<CallInst>(&(*i)) || isa<InvokeInst>(&(*i))){
>>                     //how could I get the function name and argument
>>                     //used here
>>                 }
>>             }
>>
>>         }
>>     }
>>
>>
>>     How could I get the function name and the arguments when I know an
>> Instruction is a function call?
>
> There's a worked example at
> http://wiki.llvm.org/HowTo:_Find_all_call_sites_of_a_function .
>
> With the CallInst/InvokeInst you can query getArgOperand() to get the
> arguments or getCallee() which return a Function -- or it might not. If
> the call is an indirect call (ie., function pointer) then you don't know
> what it's calling. Ignoring indirect calls, you can call getName() on a
> function to get its name.
>
> Personally, I rely heavily on the doxygen to find my way around the API:
> http://llvm.org/doxygen/hierarchy.html . Look up "CallInst" for example.
> The getName() method isn't on Function, but all the way on the base
> class Value.
>
> Nick
>
>>
>>     thanks a lot!
>>
>>     Best wishes!
>>
>>                                                   Linhai Song
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>
>





More information about the llvm-dev mailing list