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?
Asked
Active
Viewed 87 times
2

Thuy Nguyen
- 353
- 2
- 10
-
1What problem are you trying to solve? You should be able to copy the text from the "Information" tab to the clipboard and save it in a file. – the busybee Feb 09 '20 at 16:38
-
I want to get the types of all variables in C program and save it to a file, then use this information to analyze the source code later. Hence, I expect an automated way to perform this task. – Thuy Nguyen Feb 09 '20 at 16:48
-
Then I'm out, I don't know Frama-C. – the busybee Feb 09 '20 at 17:00
-
thank you for trying to help. – Thuy Nguyen Feb 09 '20 at 17:26
1 Answers
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
-
1Sure, 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