2

I am trying to print types of variables in C program using Frama-C. I found that this information is represented in the GUI as in the figure below. However, I cannot found a way to output this information to a file. Could you please suggest me the way to perform this task with Frama-c? enter image description here

Thuy Nguyen
  • 353
  • 2
  • 10

1 Answers1

2

There are no direct solutions from the command line. However, this can be very easily done with a simple script such as (not tested)

let print_type () =
  Ast.compute();
  Globals.Vars.iter
   (fun v _ ->
     Format.printf "Variable %a: %a@."
     Cil_datatype.Varinfo.pretty v
     Cil_datatype.Typ.pretty v.vtype)

let () = Db.Main.extend print_type

which can be launched with frama-c -load-script <my_script.ml> <other args including source files>

More information on scripting Frama-C (including an extensive tutorial) is available in the developer manual.

Virgile
  • 9,724
  • 18
  • 42
  • Thank you for your suggestion. As I understand, your script only handles global variables. Is it possible to handle other types of variables, including external, argument, and local variables? – Thuy Nguyen Feb 10 '20 at 18:13
  • 1
    Sure, you can basically inspect any node in Frama-C Abstract Syntax Tree (AST) by writing an appropriate visitor. Section 2.4.1 of the developer manual gives an example of a very simple visitor, and the mechanism is detailed in section 4.17. `Db.Main.extend (fun () -> Visitor.visitFramacFileSameGlobals (object method! vvdec v = Format.printf "Variable %a: %a@." Cil_datatype.Varinfo.pretty v Cil_datatype.Typ.pretty v.vtype; Cil.DoChildren end)` (again not tested) should do the trick, but comments are not well suited for writing code. Feel free to open a new question if you have troubles. – Virgile Feb 11 '20 at 10:15