llvm.org GIT mirror llvm / a69773c
[OCaml] Expose LLVM's fatal error and stacktrace APIs git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194669 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Zotov 7 years ago
3 changed file(s) with 47 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
278278
279279 external register_exns : exn -> unit = "llvm_register_core_exns"
280280 let _ = register_exns (IoError "")
281
282 external install_fatal_error_handler : (string -> unit) -> unit
283 = "llvm_install_fatal_error_handler"
284 external reset_fatal_error_handler : unit -> unit
285 = "llvm_reset_fatal_error_handler"
286 external enable_pretty_stacktrace : unit -> unit
287 = "llvm_enable_pretty_stacktrace"
281288
282289 type ('a, 'b) llpos =
283290 | At_end of 'a
360360 exception IoError of string
361361
362362
363 (** {6 Global configuration} *)
364
365 (** [enable_pretty_stacktraces ()] enables LLVM's built-in stack trace code.
366 This intercepts the OS's crash signals and prints which component of LLVM
367 you were in at the time of the crash. *)
368 val enable_pretty_stacktrace : unit -> unit
369
370 (** [install_fatal_error_handler f] installs [f] as LLVM's fatal error handler.
371 The handler will receive the reason for termination as a string. After
372 the handler has been executed, LLVM calls [exit(1)]. *)
373 val install_fatal_error_handler : (string -> unit) -> unit
374
375 (** [reset_fatal_error_handler ()] resets LLVM's fatal error handler. *)
376 val reset_fatal_error_handler : unit -> unit
377
363378 (** {6 Contexts} *)
364379
365380 (** [create_context ()] creates a context for storing the "global" state in
3232 CAMLprim value llvm_register_core_exns(value IoError) {
3333 llvm_ioerror_exn = Field(IoError, 0);
3434 register_global_root(&llvm_ioerror_exn);
35
3536 return Val_unit;
3637 }
3738
4748 #ifdef CAMLnoreturn
4849 CAMLnoreturn; /* Silences warnings, but is missing in some versions. */
4950 #endif
51 }
52
53 static value llvm_fatal_error_handler;
54
55 static void llvm_fatal_error_trampoline(const char *Reason) {
56 callback(llvm_fatal_error_handler, copy_string(Reason));
57 }
58
59 CAMLprim value llvm_install_fatal_error_handler(value Handler) {
60 LLVMInstallFatalErrorHandler(llvm_fatal_error_trampoline);
61 llvm_fatal_error_handler = Handler;
62 caml_register_global_root(&llvm_fatal_error_handler);
63 return Val_unit;
64 }
65
66 CAMLprim value llvm_reset_fatal_error_handler(value Unit) {
67 caml_remove_global_root(&llvm_fatal_error_handler);
68 LLVMResetFatalErrorHandler();
69 return Val_unit;
70 }
71
72 CAMLprim value llvm_enable_pretty_stacktrace(value Unit) {
73 LLVMEnablePrettyStackTrace();
74 return Val_unit;
5075 }
5176
5277 static value alloc_variant(int tag, void *Value) {