(* attach to a process, stop it, print maps, restart it, detach *) let dotest (pid:int64) = let sctl = Sctl.create_local () in (* let sctl = Sctl.create_remote "127.0.0.1" 30000 in *) let procs = Sctl.ps sctl in Array.iter (fun x -> Printf.printf "%Ld: %s\n" x.Sctl.pid x.Sctl.cmd) procs; let (prog,ctx) = Sctl.attach sctl pid in Sctl.cont prog; Unix.sleep 3; let ctx = Sctl.stop prog in let buf = Sctl.readmem prog ctx.Sctl.rip 16L in Printf.printf "at stop, eip is %Lx. Data:\n" ctx.Sctl.rip; Msg.debug_buf buf; Unix.sleep 3; let (pid,regs,bins) = Sctl.stat prog in begin Array.iter (fun x -> Printf.printf "%s %Lx %Ld\n" x.Sctl.r_file x.Sctl.r_addr x.Sctl.r_len) regs; flush stdout; Array.iter (fun x -> Printf.printf "%Ld %Lx %s %s\n" x.Sctl.b_nsid x.Sctl.b_base (match x.Sctl.b_isexe with true -> "exe" | false -> "nex") x.Sctl.b_path) bins; flush stdout end; Sctl.cont prog; Sctl.detach prog; Sctl.close sctl ;; if (Array.length Sys.argv) <> 2 then Printf.printf "usage: attach \n" else dotest(Int64.of_string Sys.argv.(1))