(* test throughput of network connection to sctl *) module HT = Hashtbl open Sctl let printlocals (pc:int64) (lt:loctab) : unit = try let (_, locres) = Hashtbl.find lt pc in let printloc (l:sctlloc) = let kn = (match l.sl_kind with L_param -> "param" | L_var -> "local var") in ignore (Printf.fprintf stderr "%s %s %s %s\n" kn (formattype l.sl_type) l.sl_id (format_lexpr l.sl_lexpr)) in List.iter printloc locres with Not_found -> ignore (Printf.fprintf stderr "No locals information for 0x%Lx\n" pc) let nstest () = let sns = ns "/home/jdraper/projects/sctl/ocaml/test/ns2" in ignore (Printf.fprintf stderr "sns.ns_id = %Ld\n" sns.ns_id); let foosym = looksym sns "foo" in ignore (Printf.fprintf stderr "%s\n" (formatsym foosym)); let barsym = looksym sns "bar" in ignore (Printf.fprintf stderr "%s\n" (formatsym barsym)); let mainsym = looksym sns "main" in ignore (Printf.fprintf stderr "%s\n" (formatsym mainsym)); let ftype = looktype sns (Ttypedef ("FILE")) in ignore (Printf.fprintf stderr "Found it\n"); ignore (Printf.fprintf stderr "%s\n" (formattype ftype.st_tname)); let st = enumsym sns in let tt = enumtype sns in HT.iter (fun k v -> ignore (Printf.fprintf stderr "%s\n" (formatsym v))) st; HT.iter (fun k v -> Printf.fprintf stderr "%s\n" (formattype v.st_tname)) tt; (* let symarray = enumsym sns in *) (* Array.iter formatsym symarray; *) (* let tdefarray = enumtype sns in *) (* Array.iter (fun td -> Printf.fprintf stderr "%s\n" (formattype td.st_tname)) *) (* tdefarray; *) let addr = Int64.sub mainsym.s_val 4L in let arv = lookaddr sns addr in ignore (Printf.fprintf stderr "0x%Lx is in " addr); ignore (Printf.fprintf stderr "%s\n" (formatsym arv)); flush stderr; let addr = Int64.add mainsym.s_val 4L in let arv = lookaddr sns addr in ignore (Printf.fprintf stderr "0x%Lx is in " addr); ignore (Printf.fprintf stderr "%s\n" (formatsym arv)); flush stderr; let mainctx = { empty_ctx with rip=mainsym.s_val; } in ignore (Printf.fprintf stderr "0x%Lx:\n" mainctx.rip); flush stderr; let lt = enumloc sns mainctx in printlocals mainctx.rip lt; let mainctx1 = { empty_ctx with rip=Int64.add mainsym.s_val 1L; } in ignore (Printf.fprintf stderr "0x%Lx:\n" mainctx1.rip); flush stderr; let lt1 = enumloc sns mainctx1 in printlocals mainctx1.rip lt1; let mainctx2 = { empty_ctx with rip=Int64.add mainsym.s_val 2L; } in ignore (Printf.fprintf stderr "0x%Lx:\n" mainctx2.rip); flush stderr; let lt2 = enumloc sns mainctx2 in printlocals mainctx2.rip lt2; let mainctx3 = { empty_ctx with rip=Int64.add mainsym.s_val 4L; } in ignore (Printf.fprintf stderr "0x%Lx:\n" mainctx3.rip); flush stderr; let lt3 = enumloc sns mainctx3 in printlocals mainctx3.rip lt3; let segsymarray = enumseg sns in Array.iter (fun v -> ignore (Printf.fprintf stderr "%s\n" (formatsymsize v))) segsymarray; let mainsrcloc = looksrc sns mainsym.s_val in ignore (Printf.fprintf stderr "0x%Lx %s: %s %d %d\n" mainsym.s_val mainsym.s_name mainsrcloc.src_file (Int32.to_int mainsrcloc.src_line) (Int32.to_int mainsrcloc.src_col)); flush stderr; let gtcallsrcloc = looksrc sns 0x400634L in ignore (Printf.fprintf stderr "0x400634 %s: %s %d %d\n" mainsym.s_name gtcallsrcloc.src_file (Int32.to_int gtcallsrcloc.src_line) (Int32.to_int gtcallsrcloc.src_col)); flush stderr; let line = lookline sns "ns2.c" 12 in ignore (Printf.fprintf stderr "ns2.c 12: 0x%Lx\n" line); flush_all (); close sns.ns_sctl; ;; nstest ()