[英]Get the array index variable and its value in value analysis (Frama-C)
I want to query the value analysis plugin in Frama-C for instructions to get their value. 我想查询Frama-C中的值分析插件以获取其值的说明。 For each array, it returns the value range of the whole array. 对于每个数组,它返回整个数组的值范围。 For example, if the instruction is array[i] = 1;
例如,如果指令是array[i] = 1;
, I got result = {1}
for array[i]
from value analysis plugin. ,我从值分析插件得到了array[i]
result = {1}
。 Now, for eg array[i]
, I would like to get the variable name i
and its value from value analysis. 现在,对于例如array[i]
,我想从值分析中获取变量名称i
及其值。
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
我假设您知道如何编写类型为Db.Value.t -> unit
的函数print_val
Db.Value.t -> unit
下面的代码,在您在Set
指令上匹配之前放置,将捕获对索引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. 或者,如果您知道变量的名称,则可以使用Globals.Vars.find_from_astinfo
函数查找相应的varinfo vi
,并使用此代码查询varinfo的内容。
open Cil_types
let vi_content stmt vi =
let lv = (Var vi, NoOffset) in
!Db.Value.access (Kstmt stmt) lv
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.