Search code examples
frama-c

To get the node corresponding the declaration of a local variable with Db.Pdg.find_decl_var_node


*I wrote this script in order to get the node corresponding the declaration of a local variable, in my case "val" which is in a little program C but i get the error Unexpected error (Not_found). I think that i did not give the right arguments to my method especially localisation which is type Cil_types.localisation If anybody could help me... *

let main () =  
  let memo_debug = Kernel.Debug.get () in
  Kernel.Debug.set 1;
  File.pretty_ast ();
  Kernel.Debug.set memo_debug ;
  let kf =  Globals.Functions.find_def_by_name "main" in
  let pdg = !Db.Pdg.get kf in
  let localisation=Cil_types.VGlobal in
  let var=Globals.Vars.find_from_astinfo "val" z  in
  let node= !Db.Pdg.find_decl_var_node pdg var in  
  Format.printf "%a@." (!Db.Pdg.pretty_node false) node;

Solution

  • You say that val is a local variable in main, so you shouldn't look for it in the global scope. Instead, you should do :

    let scope = Cil_types.VLocal kf in
    let var=Globals.Vars.find_from_astinfo "val" scope in