0

I am currently struggling with creating a Frama-C-plugin that gets all int-values of structs in a hierarchy (structs in structs).

For example: I have a C-Program with the following types:

struct a{
    int a;
    int b;
}
struct b{
    int c;
    int d;
    struct a a1;
    struct a a2;
}

(And even deepter hierarchie)

In the program, there is only one struct of type b created in the main method. Furthermore, I have several local pointers and ints (so a solution only for a struct-hierarchy doesn't help).

Now I want to get the "bottom-values" of the struct of type b at some specific positions.

I've started with code like this:

let lval =  
    if (Cil.isPointerType vi.vtype) then (
        (Mem (Cil.evar vi), NoOffset)
    ) else if (Cil.isStructOrUnionType vi.vtype)(
        (*TODO Section*)    
    ) else (
        (Var vi, NoOffset)
    )

int* and int's are already working fine, I use the lval-variable to get the value.

To get the struct's values, I think I have to go down vi recursivly, until I get to the point where it is a "normal" variable or a pointer, but how do I do this?

I've already looked at varinfo in cil_types.mli, but I have no idea how to get the data in the struct.

Is it even possible to get the result of the value-analysis for these values, and if yes, how?

Thomas Böhm
  • 1,456
  • 1
  • 15
  • 27
  • 1
    You'll have to extract the fields information from the type (`vi.vtype`), and then build a new `lval` with a field offset (see `Cil.addOffsetLval`). – Anne Apr 12 '16 at 13:00
  • Thanks, I was able to print the values with your help :) – Thomas Böhm Apr 14 '16 at 08:48

0 Answers0