Skip to content

Commit

Permalink
Introduce caml_record_backtraces
Browse files Browse the repository at this point in the history
The manual suggests calling caml_record_backtrace (which is the
primitive), but this symbol is not declared publicly in the headers. All
occurrences in C, and the use-case detailed in the manual, are for
turning backtraces on, so introduce an actual C function to do this and
remove the declaration of the primitive.
  • Loading branch information
dra27 committed Sep 15, 2020
1 parent 58e6164 commit e3ad3cc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
3 changes: 2 additions & 1 deletion manual/manual/cmds/intf-c.etex
Expand Up @@ -1712,7 +1712,8 @@ information is available, but the backtrace mechanism needs to be
turned on programmatically. This can be achieved from the OCaml side
by calling "Printexc.record_backtrace true" in the initialization of
one of the OCaml modules. This can also be achieved from the C side
by calling "caml_record_backtrace(Val_int(1));" in the OCaml-C glue code.
by calling "caml_record_backtraces();" in the OCaml-C glue code.
("ocaml_receord_backtraces" is declared in "backtrace.h")

\paragraph{Unloading the runtime.}

Expand Down
6 changes: 6 additions & 0 deletions runtime/backtrace.c
Expand Up @@ -51,6 +51,12 @@ CAMLprim value caml_record_backtrace(value vflag)
return Val_unit;
}

CAMLexport void caml_record_backtraces(void)
{
caml_record_backtrace(Val_true);
return;
}

/* Return the status of the backtrace machinery */
CAMLprim value caml_backtrace_status(value vunit)
{
Expand Down
22 changes: 11 additions & 11 deletions runtime/caml/backtrace.h
Expand Up @@ -16,6 +16,15 @@
#ifndef CAML_BACKTRACE_H
#define CAML_BACKTRACE_H

/* [caml_record_backtraces] turns backtrace recording on.
* This function can be called at runtime by user-code, or during
* initialization if backtraces were requested.
*
* It might be called before GC initialization, so it shouldn't do OCaml
* allocation.
*/
CAMLextern void caml_record_backtraces(void);

#ifdef CAML_INTERNALS

#include "mlvalues.h"
Expand Down Expand Up @@ -52,7 +61,8 @@
* OCaml values of algebraic data-type [Printexc.backtrace_slot]
*/
/* [Caml_state->backtrace_active] is non zero iff backtraces are recorded.
* This variable must be changed with [caml_record_backtrace].
* This variable must be changed with [caml_record_backtrace] in OCaml or
* caml_record_backtraces in C.
*/
#define caml_backtrace_active (Caml_state_field(backtrace_active))
/* The [Caml_state->backtrace_buffer] and [Caml_state->backtrace_last_exn]
Expand Down Expand Up @@ -89,16 +99,6 @@
runtimes for raise.
*/

/* [caml_record_backtrace] toggle backtrace recording on and off.
* This function can be called at runtime by user-code, or during
* initialization if backtraces were requested.
*
* It might be called before GC initialization, so it shouldn't do OCaml
* allocation.
*/
CAMLextern value caml_record_backtrace(value vflag);


#ifndef NATIVE_CODE

/* Path to the file containing debug information, if any, or NULL. */
Expand Down
2 changes: 1 addition & 1 deletion runtime/startup_aux.c
Expand Up @@ -116,7 +116,7 @@ void caml_parse_ocamlrunparam(void)
switch (*opt++){
case 'a': scanmult (opt, &p); caml_set_allocation_policy ((intnat) p);
break;
case 'b': scanmult (opt, &p); caml_record_backtrace(Val_bool (p));
case 'b': scanmult (opt, &p); if (p) caml_record_backtraces();
break;
case 'c': scanmult (opt, &p); caml_cleanup_on_exit = (p != 0); break;
case 'h': scanmult (opt, &caml_init_heap_wsz); break;
Expand Down
2 changes: 1 addition & 1 deletion runtime/startup_byt.c
Expand Up @@ -297,7 +297,7 @@ static int parse_command_line(char_os **argv)
exit(0);
break;
case 'b':
caml_record_backtrace(Val_true);
caml_record_backtraces();
break;
case 'I':
if (argv[i + 1] != NULL) {
Expand Down

0 comments on commit e3ad3cc

Please sign in to comment.