summaryrefslogtreecommitdiff
path: root/byterun/backtrace.c
diff options
context:
space:
mode:
authorFrançois Bobot <francois.bobot@cea.fr>2016-12-05 16:56:56 +0100
committerGabriel Scherer <gabriel.scherer@gmail.com>2017-02-14 09:21:45 -0500
commit50e9b96564895aeb5dd270f1b7965840f98ebbcf (patch)
tree2179500e6a553a80bef2083e052fe266d4271325 /byterun/backtrace.c
parent5839c9827d9fdd55e5a9eff6bbd6173370c30bbb (diff)
downloadocaml-50e9b96564895aeb5dd270f1b7965840f98ebbcf.tar.gz
Recover "Merge pull request #378 from bobot/feature/reraise_raw_backtrace_primitive"
This reverts commit f1b63d4a576793b8725a3ea26f0779f77ecfcf34. It is the second time #378 tried to be recovered (e6c779ada8600a1489d4c764503542ffc1748964).
Diffstat (limited to 'byterun/backtrace.c')
-rw-r--r--byterun/backtrace.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/byterun/backtrace.c b/byterun/backtrace.c
index a5bc780951..8dfe9b7e38 100644
--- a/byterun/backtrace.c
+++ b/byterun/backtrace.c
@@ -49,9 +49,11 @@ CAMLprim value caml_record_backtrace(value vflag)
caml_backtrace_active = flag;
caml_backtrace_pos = 0;
caml_backtrace_last_exn = Val_unit;
- /* Note: lazy initialization of caml_backtrace_buffer in
- caml_stash_backtrace to simplify the interface with the thread
- libraries */
+ /* Note: We do lazy initialization of caml_backtrace_buffer when
+ needed in order to simplify the interface with the thread
+ library (thread creation doesn't need to allocate
+ caml_backtrace_buffer). So we don't have to allocate it here.
+ */
}
return Val_unit;
}
@@ -167,6 +169,41 @@ CAMLprim value caml_get_exception_raw_backtrace(value unit)
CAMLreturn(res);
}
+/* Copy back a backtrace and exception to the global state.
+ This function should be used only with Printexc.raw_backtrace */
+/* noalloc (caml value): so no CAMLparam* CAMLreturn* */
+CAMLprim value caml_restore_raw_backtrace(value exn, value backtrace)
+{
+ intnat i;
+ mlsize_t bt_size;
+
+ caml_backtrace_last_exn = exn;
+
+ bt_size = Wosize_val(backtrace);
+ if(bt_size > BACKTRACE_BUFFER_SIZE){
+ bt_size = BACKTRACE_BUFFER_SIZE;
+ }
+
+ /* We don't allocate if the backtrace is empty (no -g or backtrace
+ not activated) */
+ if(bt_size == 0){
+ caml_backtrace_pos = 0;
+ return Val_unit;
+ }
+
+ /* Allocate if needed and copy the backtrace buffer */
+ if (caml_backtrace_buffer == NULL && caml_alloc_backtrace_buffer() == -1){
+ return Val_unit;
+ }
+
+ caml_backtrace_pos = bt_size;
+ for(i=0; i < caml_backtrace_pos; i++){
+ caml_backtrace_buffer[i] = Backtrace_slot_val(Field(backtrace, i));
+ }
+
+ return Val_unit;
+}
+
#define Val_debuginfo(bslot) (Val_long((uintnat)(bslot)>>1))
#define Debuginfo_val(vslot) ((debuginfo)(Long_val(vslot) << 1))