0

I am writing a Frama-C Plugin.

I want to develop a plugin, that sets the value of a local variable. By this idea I try to do the value-analysis afterwards, and then I can analyze the reachablility, path analysis and other things by my second plugin.

Is it possible to set the value of a local variable within a plugin (at the start of a function where I know the name)?

EDIT

I now found out how to make new local variables, how to get the Varinfo of variables and how to create new varinfos. The only missing thing is setting the variable's value.

I started with a code like this:

match kf_cil_fun with
| Cil_types.Definition(a,b) -> 
    let val_visitor = new value_set_visitor kf in
        Visitor.visitFramacFileSameGlobals (val_visitor :> Visitor.frama_c_visitor) (Ast.get());
    let old_varinfo = Cil.makeLocalVar a "x" Cil.intType in
    let new_varinfo = Cil.makeVarinfo false false "x" Cil.intType in
    val_visitor#doStuff old_varinfo new_varinfo;
    ()
| _ -> ()

where the visitor is a simple visitor with a method doStuff, and the builtin-methods vfile, vglob_aux and vstmt_aux that simply call Cil.DoChildren

method doStuff old_varinfo new_varinfo =
            Cil.set_varinfo self#behavior old_varinfo new_varinfo;

Does anyone have an idea of how to set the value of x to 1 (or a fixed other value)? Am I doing the things right?

Thomas Böhm
  • 1,456
  • 1
  • 15
  • 27
  • I don't know why you want to do this, but it is generally a bad idea to change the internal representation of the program. I would rather use a parameter than a local variable and give a constrain on it with a precondition. – Anne Apr 04 '16 at 14:26
  • I want to do this, because the program I want to analyse reads in a configuration file at startup, and sets some variables based on this. To do the analysis, I would have liked to set these variables according to the possible input combinations. The file may not contain all the combinations, but I can call the plugin several times with different predefined values. – Thomas Böhm Apr 05 '16 at 08:49
  • Is there another way to solve this? How should I handle such programs with external input? – Thomas Böhm Apr 05 '16 at 08:51
  • Maybe you could write (or generate before calling frama-c) a dummy C function that returns what you want, and use it instead of the function that reads the real configuration file. – Anne Apr 05 '16 at 11:28

0 Answers0