[LLVMdev] [LLVMDEV]How could I get function name in this situation?

songlh at cs.wisc.edu songlh at cs.wisc.edu
Wed Jan 26 12:40:15 PST 2011


thanks!

After I check the ll file, I find this:

%1 = load %struct.nsAString** %aBuf_addr, align 4, !dbg !2048
%2 = getelementptr inbounds %struct.nsAString* %1, i32 0, i32 0, !dbg !2048
%3 = getelementptr inbounds %struct.nsISupports* %2, i32 0, i32 0, !dbg !2048
%4 = load i32 (...)*** %3, align 4, !dbg !2048
%5 = getelementptr inbounds i32 (...)** %4, i32 10, !dbg !2048
%6 = load i32 (...)** %5, align 1, !dbg !2048
%7 = bitcast i32 (...)* %6 to void (%struct.nsAString*, i32)*, !dbg !2048
%8 = load %struct.nsAString** %aBuf_addr, align 4, !dbg !2048
call void %7(%struct.nsAString* %8, i32 0) nounwind, !dbg !2048

The last line is the CallInst I find.

I feel it is using memory address to get the function. Is there someway I
can do this in my c++ code??

thanks a lot!

> On 1/26/11 2:07 PM, songlh at cs.wisc.edu wrote:
>> Hi:
>>
>>    My llvm code is:
>>
>>    for( BasicBlock::iterator i = b->begin() , ie = b->end();
>>         b != be ; b ++ ){
>>         if( CallInst * pCall = dyn_cast<CallInst>(i)){
>>
>>            pCall->dump(); //
>>            Function * pFunction = pCall->getCalledFunction();
>>            if( !pFunction ){
>>
>>            }
>>            std::string fname = pFunction->getName();
>>         }
>>    }
>>
>>    The dump result of the function call I want to find is :
>>
>>    call void %7(%struct.nsAString* %8, i32 0) nounwind, !dbg !1565
>
> This is a call using a function pointer.  There is no function name to
> retrieve.  You can check the called value (pcall->getCalledValue()) and
> see if it's something like a cast instruction that casts a constant
> function value, but that case is probably unlikely.
>
> -- John T.
>
>>    it returns null from pCall->getCalledFunction(), and I cannot get the
>> function name.
>>
>>    How could I get the function name in this situation?
>>
>>    thanks a lot!
>>
>>                                          Linhai
>>
>> _______________________________________________
>> 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