I want to query the value analysis plugin in Frama-C for instructions to get their value. For each array, it returns the value range of the whole array. For example, if the instruction is array[i] = 1;
, I got result = {1}
for array[i]
from value analysis plugin. Now, for e.g. array[i]
, I would like to get the variable name i
and its value from value analysis.
Below is a sample of my code
class print_VA_result out = object
inherit Visitor.frama_c_inplace
(**..*)
method vstmt_aux s =
if Db.Value.is_computed () then
match s.skind with
| Instr i ->
begin
match i with
| Set(lval,_,_) ->
print_value lval s
|_ -> "<>"
...
Can anybody help me for this? Thanks a lot in advance.
I assume that you know how to write a function print_val
of type Db.Value.t -> unit
The following code, to be placed before your matching on a Set
instruction, will catch an access to an array at index e
match i with
(* Access to an array *)
| Set ((_, Index (e, _)), _, _) ->
let v = !Db.Value.access_expr (Kstmt s) e in
print_val v
(* End special case *)
| Set(lval,_,_) ->
print_value lval s
Alternatively, if you know the name of your variable, you can use the function Globals.Vars.find_from_astinfo
to find the corresponding varinfo vi
, and this code to query the contents of the varinfo.
open Cil_types
let vi_content stmt vi =
let lv = (Var vi, NoOffset) in
!Db.Value.access (Kstmt stmt) lv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With