0

*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;
byako
  • 3,372
  • 2
  • 21
  • 36
  • i did a mistake on this line let var=Globals.Vars.find_from_astinfo "val" z in. It is localisation instead of z but it does not still work... – Kune Rasamizanany Apr 23 '15 at 10:45

1 Answers1

4

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
Anne
  • 1,270
  • 6
  • 15
  • Thank you! It works! But if "val" was a global variable outside of main. How could i get it? And also for this example below, why it does not work if i initialize val with a value != 0 or if i initialize b with 0? – Kune Rasamizanany Apr 23 '15 at 12:28
  • You can get the variable with ``Cil_types.VGlobal``, but not the PDG node since a PDG is for a function, so there is no node for global declarations. – Anne Apr 23 '15 at 12:32
  • Ah ok! In this case instead of "let kf = Globals.Functions.find_def_by_name "main" in" , what should i write to have a PDG which could contain all – Kune Rasamizanany Apr 23 '15 at 12:40
  • There is no global PDG. – Anne Apr 23 '15 at 12:58