Advertisement
Guest User

Init progress

a guest
Oct 7th, 2015
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 1.52 KB | None | 0 0
  1. (* init_info.ml
  2.  * ./ocamlopt ... dynlink.cmxa init_info.ml ...
  3.  *  Uncaught exception during initialization:
  4.  *    CamlinternalFormatBasics
  5.  *    Pervasives
  6.  *    ...
  7.  *    Dynlink
  8.  *    Init_info
  9.  *    A
  10.  * => B
  11.  *    Std_exit
  12.  * Exception: Failure("Argh")
  13.  *)
  14. external ndl_getmap: unit -> bytes = "caml_natdynlink_getmap"
  15. external ndl_globals_inited: unit -> int = "caml_natdynlink_globals_inited"
  16. external reraise: exn -> 'a = "%reraise"
  17.  
  18. let init_list : string list lazy_t =
  19.   lazy begin
  20.     let map : (string*Digest.t*Digest.t*string list) list =
  21.       Marshal.from_bytes (ndl_getmap ()) 0 in
  22.     List.concat (List.map (fun (_,_,_,syms) -> syms) map)
  23.   end
  24.  
  25. let get_init_progress () : string list * string list =
  26.   let lazy all = init_list and current = ndl_globals_inited () in
  27.   let rec aux acc n = function
  28.    | x :: xs when n > 0 -> aux (x :: acc) (n - 1) xs
  29.    | xs -> List.rev acc, xs
  30.   in
  31.   aux [] current all
  32.  
  33. let prerr_init_progress () =
  34.   let finished, todo = get_init_progress () in
  35.   let prerr_item sym = prerr_string "   "; prerr_endline sym in
  36.   List.iter prerr_item finished;
  37.   match todo with
  38.   | [] -> ()
  39.   | x :: xs ->
  40.       prerr_string "=> ";
  41.       prerr_endline x;
  42.       List.iter prerr_item xs
  43.  
  44. let init_handler exn backtrace =
  45.   prerr_endline "Uncaught exception during initialization:";
  46.   prerr_init_progress ();
  47.   prerr_endline ("Exception: " ^ Printexc.to_string exn);
  48.   Printexc.print_raw_backtrace stderr backtrace
  49.  
  50. let () = Printexc.set_uncaught_exception_handler init_handler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement