最近我正在尝试使用LLVM监控结构访问。
我可以使用SI.dump((作为打印StoreInst
i32* getelementptr inbounds (%struct._Datatype, %struct._Datatype* @monitor_memory, i32 0, i32 0)
但在传递代码中,我找不到StoreInst只获取Struct名称的方法,我想稍后使用它进行比较。
if (type->getStructName() == "struct._Datatype") {
....
}
有人能帮我吗?谢谢代码片段在这里:
for(BasicBlock &B : F) {
for(Instruction &I : B) {
StoreInst * store = nullptr;
builder->SetInsertPoint(&I);
if((store = dyn_cast<StoreInst>(&I)) != nullptr) {
Value * value = store->getValueOperand(); // Getting the value to be stored at given address
Value * address = store->getPointerOperand(); // Getting source address
Type * type = store->getPointerOperandType(); // the type that I get is i32*, but I expect it to be struct._Datatype.
}
}
}
定义为的数据类型
typedef struct _Datatype {
int a;
int b;
} Datatype;
对于可能有名称的对象类型,通常使用LLVM中的getName((获取名称。StructType类有一个getName((,所以您只需要
cast<StructType>(type)->getName()