123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051open!ImportmoduleSys=Sys0typet=Caml.Printexc.raw_backtraceletelide=refam_testingletelided_message="<backtrace elided in test>"letget?(at_most_num_frames=Int.max_value)()=Caml.Printexc.get_callstackat_most_num_frames;;letto_stringt=if!elidethenelided_messageelseCaml.Printexc.raw_backtrace_to_stringt;;letto_string_listt=String.split_lines(to_stringt)letsexp_of_tt=Sexp.List(List.map(to_string_listt)~f:(funx->Sexp.Atomx));;moduleExn=structletset_recording=Caml.Printexc.record_backtraceletam_recording=Caml.Printexc.backtrace_statusletmost_recent()=Caml.Printexc.get_raw_backtrace();;(* We turn on backtraces by default if OCAMLRUNPARAM isn't set. *)letmaybe_set_recording()=matchSys.getenv"OCAMLRUNPARAM"with|exception_->set_recordingtrue|(_:string)->()(* the caller set something, they are responsible *);;letwith_recordingb~f=letsaved=am_recording()inset_recordingb;Exn.protect~f~finally:(fun()->set_recordingsaved);;endletinitialize_module()=Exn.maybe_set_recording();;;