使用LLVM / Clang在Xcode项目中查找fclose()调用(Use LLVM/Clang to find fclose() calls in an Xcode project)

编程入门 行业动态 更新时间:2024-10-22 11:00:08
使用LLVM / Clang在Xcode项目中查找fclose()调用(Use LLVM/Clang to find fclose() calls in an Xcode project)

我想学习如何以编程方式与LLVM / Clang集成以查找我的Xcode项目中的所有fclose()调用。 我意识到我可以通过正常的文本搜索来实现这一点,但这只是更详细问题的第一步。

I would like to learn how I might programmatically integrate with LLVM/Clang to find all of the fclose() calls in my Xcode project. I realize I can accomplish this via normal text searching but this is just the first step in a more detailed problem.

最满意答案

您可以编写函数pass并查找函数名称,如下所示:

#include "llvm/Pass.h" #include "llvm/IR/Function.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; namespace { struct Hello : public FunctionPass { static char ID; Hello() : FunctionPass(ID) {} virtual bool runOnFunction(Function &F) { errs() << "Hello: "; errs().write_escaped(F.getName()) << '\n'; return false; } }; } char Hello::ID = 0; static RegisterPass<Hello> X("hello", "Hello World Pass", false, false);

使用opt -hello input.ll从opt调用此传递,您将获得所有打印函数的名称。 更改上述代码中的逻辑以查找所需的功能。 有关写通行证的更多详细信息,请参阅以下链接:

http://llvm.org/docs/WritingAnLLVMPass.html

You can write function pass and find the name of the function as below:

#include "llvm/Pass.h" #include "llvm/IR/Function.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; namespace { struct Hello : public FunctionPass { static char ID; Hello() : FunctionPass(ID) {} virtual bool runOnFunction(Function &F) { errs() << "Hello: "; errs().write_escaped(F.getName()) << '\n'; return false; } }; } char Hello::ID = 0; static RegisterPass<Hello> X("hello", "Hello World Pass", false, false);

Call this pass from opt using opt -hello input.ll and you will get the names of all functions printed. Change the logic in the above code to find your required function. See the following link for more details on writing passes:

http://llvm.org/docs/WritingAnLLVMPass.html

更多推荐

本文发布于:2023-07-26 15:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1277519.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   Xcode   Clang   LLVM   project

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!