I am quite new to LLVM and KLEE and I am trying to understand whether it is possible to access the content of a structure that is referred to by a pointer. The code I am working on is quite long and complicated, but the problem is the following:
In one of the classes I have the statementes below:
static my_struct * pointer2Structure;
typedef struct {
<primitive data types variables>
<other structures>
<pointers to other structures>
} my_struct;
So far I can access the content of other simple global variables with the following code:
...
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
, and ObjectState
are classes defined in KLEE.
The function os->getValue(strType)
is a user defined function to get the content of the ObjectState.
I can see pointer2Structure
based on the variable name, but since it is a pointer (PointerType) I don't know how to access its content.
Is there any way to iterate over the elements of the structure knowing the name of the pointer to the structure? If so, is it possible to recursively examine the content of nested structures?
I am using LLVM 9.0 and I am compiling the code with -O0 -d to enable debug information.
Thank you very much for your help.