如何从LLVM中的CallInst获取间接调用的函数名称 [英] How can I get Function Name of indirect call from CallInst in LLVM
本文介绍了如何从LLVM中的CallInst获取间接调用的函数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Function *fun = call->getCalledFunction();
如果
getCalledFunction();
是间接调用,则返回null.如何获得函数名称或指针名称?
getCalledFunction();
returns null if it's indirect call. How can I get the name of the function or the name of the pointer?
我发现Stack Overflow中与此问题有关的所有问题都涉及直接调用的函数名或指针类型.
I found all questions in Stack Overflow related to this issue talked about function name of direct call, or type of pointer.
我只想跟踪这种情况:
void foo(){}
void goo(){}
void main(){
int x = 1;
void (*p)();
if(x)
p = &foo;
else
p = &goo;
p(); // print the called function name
}
推荐答案
我遇到了同样的问题.阅读llvm源代码后,这是我的解决方案:
I get the same problem. Here is my solution after reading the llvm source code:
Function* fp = CI->getCalledFunction();
if (fp==NULL) {
Value* v=CI->getCalledValue();
Value* sv = v->stripPointerCasts();
StringRef fname = sv->getName();
errs()<<fname<<"\n";
}
这篇关于如何从LLVM中的CallInst获取间接调用的函数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文