簡體   English   中英

frama-c是否可以在特定程序代碼之前獲取變量范圍

[英]Whether frama-c can get the range of variables before a particular program code

int main()
{
    int B = 1;
    int x = rand()%10+1;
    int x1 = rand()%10+1;
    int A = 1;
    while((B <= 5))
    {
            B++;
            A++;  
            if(B == x)
            {
                return 0;
            }
    }
    task(A) //The variable A passes in the range of values before the task function
    A = -2;
    return 0;
}
/*How can I use frama-c to get the range of A at task code if I want to get the range of A at task statement position instead of the range of A at the end of the program execution*/

如果要在任務語句位置獲取A的范圍而不是在程序執行結束時獲取A的范圍,如何使用frama-c在任務代碼處獲取A的范圍

如果我很好地理解了您的問題,那么您想知道特定語句中A的變化間隔。 我假設您依賴Eva插件,因為它是Eva通常提供的那種信息(至少如果我很好地理解“而不是在程序執行結束時使用A的范圍”) )。

有兩種可能性。 第一個是使用Eva的編程API,即Db.Value模塊。 這需要具備OCaml知識並閱讀Frama-C開發人員手冊 ,但這是訪問信息的最靈活,最穩定的方法。 簡而言之, Db.Value.get_state會返回Eva分析器運行后針對參數給出的語句所計算的抽象狀態,而Db.Value.eval_expr會給出抽象狀態並給出一個表達式,計算相應狀態下表達式的抽象值。

第二種可能性是使用內置函數的Frama_C_show_each_*系列:每當Eva遇到名稱以Frama_C_show_each_開頭的函數時,它將在標准輸出上打印當前抽象狀態下賦予該函數的參數的抽象值。 因此,添加Frama_C_show_each_A(A); 在調用task(A)之前,您會獲得frama-c -eva test.i等信息

[eva] test.i:19: Frama_C_show_each_A: [1..2147483647]

請注意,我已經修改了您的代碼,以使其可以在Frama-C中正常運行:

  • 添加了原型extern int rand(void); extern void task(int);
  • 添加了“;” task(A)

請確保您提供了一個最小,完整和可驗證的問題示例 ,這使它們非常容易回答。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM