我对 LLVM 和 KLEE 很陌生,我试图了解是否可以访问指针引用的结构的内容。我正在处理的代码很长而且很复杂,但问题如下:
在其中一门课中,我有以下陈述:
static my_struct * pointer2Structure;
typedef struct {
<primitive data types variables>
<other structures>
<pointers to other structures>
} my_struct;
到目前为止,我可以使用以下代码访问其他简单全局变量的内容:
...
ExecutionState state = ...;
const Module *m = ...;
for (const GlobalVariable &v : m->globals()) {
std::string name = v.getName().data();
if(!v.isConstant()) {
globalVariableCounter++;
Type *type = v.getValueType();
std::string strType;
llvm::raw_string_ostream typeInfo(strType);
type->print(typeInfo);
strType = typeInfo.str();
MemoryObject *mo = globalObjects.find(&v)->second;
const ObjectState *os = state.addressSpace.findObject(mo);
strValue = os->getValue(strType);
std::string info = "\nGlobal variable info:\n\t name = \t" + name
+ "\n\t typeID = \t" + getTypeName(type->getTypeID())
+ "\n\t type = \t" + strType
+ "\n\t value = \t" + strValue;
}
}
...
ExecutionState
、MemoryObject
和ObjectState
是 KLEE 中定义的类。该函数os->getValue(strType)
是用户定义的函数,用于获取 ObjectState 的内容。
我可以pointer2Structure
根据变量名看到,但由于它是一个指针(PointerType)我不知道如何访问它的内容。
有没有办法在知道指向结构的指针的名称的情况下迭代结构的元素?如果是这样,是否可以递归检查嵌套结构的内容?
我正在使用 LLVM 9.0,并且正在使用 -O0 -d 编译代码以启用调试信息。
非常感谢您的帮助。