Permalink
Browse files

reinstate the deprecated primitive caml_get_exception_backtrace

Jacques-Henri initially removed the primitive, which is deprecated
since 4.01, but I suspect there still are uses in the wild. I guess we
should wait for a few more versions.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14780 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information...
1 parent ebd3778 commit 4f913f2498fe9606730a5516a91e36d34fd97638 @gasche gasche committed May 10, 2014
Showing with 69 additions and 0 deletions.
  1. +31 −0 asmrun/backtrace.c
  2. +38 −0 byterun/backtrace.c
View
@@ -123,6 +123,7 @@ void caml_stash_backtrace(value exn, uintnat pc, char * sp, char * trapsp)
caml_backtrace_last_exn = exn;
}
if (caml_backtrace_buffer == NULL) {
+ Assert(caml_backtrace_pos == 0);
caml_backtrace_buffer = malloc(BACKTRACE_BUFFER_SIZE * sizeof(code_t));
if (caml_backtrace_buffer == NULL) return;
}
@@ -340,3 +341,33 @@ CAMLprim value caml_get_exception_raw_backtrace(value unit)
}
CAMLreturn(res);
}
+
+/* the function below is deprecated: we previously returned directly
+ the OCaml-usable representation, instead of the raw backtrace as an
+ abstract type, but this has a large performance overhead if you
+ store a lot of backtraces and print only some of them.
+
+ It is not used by the Printexc library anymore, or anywhere else in
+ the compiler, but we have kept it in case some user still depends
+ on it as an external.
+*/
+
+CAMLprim value caml_get_exception_backtrace(value unit)
+{
+ CAMLparam0();
+ CAMLlocal4(arr, raw_slot, slot, res);
+
+ arr = caml_alloc(caml_backtrace_pos, 0);
+ if (caml_backtrace_buffer == NULL) {
+ Assert(caml_backtrace_pos == 0);
+ } else {
+ intnat i;
+ for(i = 0; i < caml_backtrace_pos; i++) {
+ raw_slot = Val_Descrptr(caml_backtrace_buffer[i]);
+ slot = caml_convert_raw_backtrace_slot(raw_slot);
+ caml_modify(&Field(arr, i), slot);
+ }
+ }
+ res = caml_alloc_small(1, 0); Field(res, 0) = arr; /* Some */
+ CAMLreturn(res);
+}
View
@@ -103,6 +103,7 @@ void caml_stash_backtrace(value exn, code_t pc, value * sp, int reraise)
caml_backtrace_last_exn = exn;
}
if (caml_backtrace_buffer == NULL) {
+ Assert(caml_backtrace_pos == 0);
caml_backtrace_buffer = malloc(BACKTRACE_BUFFER_SIZE * sizeof(code_t));
if (caml_backtrace_buffer == NULL) return;
}
@@ -461,3 +462,40 @@ CAMLprim value caml_get_exception_raw_backtrace(value unit)
}
CAMLreturn(res);
}
+
+/* the function below is deprecated: we previously returned directly
+ the OCaml-usable representation, instead of the raw backtrace as an
+ abstract type, but this has a large performance overhead if you
+ store a lot of backtraces and print only some of them.
+
+ It is not used by the Printexc library anymore, or anywhere else in
+ the compiler, but we have kept it in case some user still depends
+ on it as an external.
+*/
+
+CAMLprim value caml_get_exception_backtrace(value unit)
+{
+ CAMLparam0();
+ CAMLlocal4(arr, raw_slot, slot, res);
+
+ read_debug_info();
+ if (events == NULL) {
+ res = Val_int(0); /* None */
+ } else {
+ arr = caml_alloc(caml_backtrace_pos, 0);
+ if(caml_backtrace_buffer == NULL) {
+ Assert(caml_backtrace_pos == 0);
+ } else {
+ intnat i;
+ for(i = 0; i < caml_backtrace_pos; i++) {
+ raw_slot = Val_Codet(caml_backtrace_buffer[i]);
+ /* caml_convert_raw_backtrace_slot will not fail with
+ caml_failwith as we checked (events != NULL) already */
+ slot = caml_convert_raw_backtrace_slot(raw_slot);
+ caml_modify(&Field(arr, i), slot);
+ }
+ }
+ res = caml_alloc_small(1, 0); Field(res, 0) = arr; /* Some */
+ }
+ CAMLreturn(res);
+}

0 comments on commit 4f913f2

Please sign in to comment.