diff options
author | Damien Doligez <damien.doligez-inria.fr> | 2012-03-08 19:52:03 +0000 |
---|---|---|
committer | Damien Doligez <damien.doligez-inria.fr> | 2012-03-08 19:52:03 +0000 |
commit | 6c24f4f90b23e8c4536281d31461adfe5a15b739 (patch) | |
tree | 29f6c4af8052800cc7d0eafb9650c6be8e90a2e5 /debugger/program_loading.ml | |
parent | 1fb4007ece64b1d59e16d7a84639fce1dd69ed45 (diff) |
merge version 3.12 from 3.12.1 to r12205
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12210 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'debugger/program_loading.ml')
-rw-r--r-- | debugger/program_loading.ml | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/debugger/program_loading.ml b/debugger/program_loading.ml index 3f32cb245..6ef9d03e7 100644 --- a/debugger/program_loading.ml +++ b/debugger/program_loading.ml @@ -35,6 +35,39 @@ let load_program () = (*** Launching functions. ***) +(* Returns the environment to be passed to debugee *) +let get_environment () = + let env = Unix.environment () in + let have_same_name x y = + let split = Primitives.split_string '=' in + match split x, split y with + (hd1 :: _), (hd2 :: _) -> hd1 = hd2 + | _ -> false in + let have_name_in_config_env x = + List.exists + (have_same_name x) + !Debugger_config.environment in + let env = + Array.fold_right + (fun elem acc -> + if have_name_in_config_env elem then + acc + else + elem :: acc) + env + [] in + Array.of_list (env @ !Debugger_config.environment) + +(* Returns the environment to be passed to debugee *) +let get_win32_environment () = + let res = Buffer.create 256 in + let env = get_environment () in + let len = Array.length env in + for i = 0 to pred len do + Buffer.add_string res (Printf.sprintf "set %s && " env.(i)) + done; + Buffer.contents res + (* A generic function for launching the program *) let generic_exec_unix cmdline = function () -> if !debug_loading then @@ -52,7 +85,7 @@ let generic_exec_unix cmdline = function () -> 0 -> (* Try to detach the process from the controlling terminal, so that it does not receive SIGINT on ctrl-C. *) begin try ignore(setsid()) with Invalid_argument _ -> () end; - execv shell [| shell; "-c"; cmdline() |] + execve shell [| shell; "-c"; cmdline() |] (get_environment ()) | _ -> exit 0 with x -> Unix_tools.report_error x; @@ -86,7 +119,8 @@ let exec_with_runtime = but quoting is even worse because Unix.create_process thinks each command line parameter is a file. So no good solution so far *) - Printf.sprintf "set CAML_DEBUG_SOCKET=%s && %s %s %s" + Printf.sprintf "%sset CAML_DEBUG_SOCKET=%s && %s %s %s" + (get_win32_environment ()) !socket_name runtime_program !program_name @@ -105,7 +139,8 @@ let exec_direct = match Sys.os_type with "Win32" -> (* See the comment above *) - Printf.sprintf "set CAML_DEBUG_SOCKET=%s && %s %s" + Printf.sprintf "%sset CAML_DEBUG_SOCKET=%s && %s %s" + (get_win32_environment ()) !socket_name !program_name !arguments |