2016-02-18 07:11:59 -08:00
|
|
|
/**************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* OCaml */
|
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
|
|
|
/* Copyright 2000 Institut National de Recherche en Informatique et */
|
|
|
|
/* en Automatique. */
|
|
|
|
/* */
|
|
|
|
/* All rights reserved. This file is distributed under the terms of */
|
|
|
|
/* the GNU Lesser General Public License version 2.1, with the */
|
|
|
|
/* special exception on linking described in the file LICENSE. */
|
|
|
|
/* */
|
|
|
|
/**************************************************************************/
|
2001-02-19 04:29:00 -08:00
|
|
|
|
2016-07-04 10:00:57 -07:00
|
|
|
#define CAML_INTERNALS
|
|
|
|
|
2001-02-19 04:29:00 -08:00
|
|
|
/* Stack backtrace for uncaught exceptions */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2001-06-15 07:22:38 -07:00
|
|
|
#include <stdlib.h>
|
2013-03-22 11:22:51 -07:00
|
|
|
#include <string.h>
|
2013-03-22 11:36:22 -07:00
|
|
|
|
2014-12-27 06:41:49 -08:00
|
|
|
#include "caml/alloc.h"
|
|
|
|
#include "caml/memory.h"
|
|
|
|
#include "caml/backtrace.h"
|
2015-08-21 23:04:18 -07:00
|
|
|
#include "caml/backtrace_prim.h"
|
2014-12-27 06:41:49 -08:00
|
|
|
#include "caml/fail.h"
|
2019-05-02 08:05:15 -07:00
|
|
|
#include "caml/debugger.h"
|
2018-12-10 23:54:49 -08:00
|
|
|
#include "caml/startup.h"
|
2001-02-19 04:29:00 -08:00
|
|
|
|
2015-08-21 23:04:22 -07:00
|
|
|
void caml_init_backtrace(void)
|
|
|
|
{
|
2019-06-07 02:02:14 -07:00
|
|
|
caml_register_global_root(&Caml_state->backtrace_last_exn);
|
2015-08-21 23:04:22 -07:00
|
|
|
}
|
|
|
|
|
2008-03-14 06:47:24 -07:00
|
|
|
/* Start or stop the backtrace machinery */
|
|
|
|
CAMLprim value caml_record_backtrace(value vflag)
|
2001-11-26 04:47:03 -08:00
|
|
|
{
|
2008-03-14 06:47:24 -07:00
|
|
|
int flag = Int_val(vflag);
|
|
|
|
|
2019-06-07 02:02:14 -07:00
|
|
|
if (flag != Caml_state->backtrace_active) {
|
|
|
|
Caml_state->backtrace_active = flag;
|
|
|
|
Caml_state->backtrace_pos = 0;
|
|
|
|
Caml_state->backtrace_last_exn = Val_unit;
|
|
|
|
/* Note: We do lazy initialization of Caml_state->backtrace_buffer when
|
2016-12-05 07:56:56 -08:00
|
|
|
needed in order to simplify the interface with the thread
|
|
|
|
library (thread creation doesn't need to allocate
|
2019-06-07 02:02:14 -07:00
|
|
|
Caml_state->backtrace_buffer). So we don't have to allocate it here.
|
2016-12-05 07:56:56 -08:00
|
|
|
*/
|
2008-03-14 06:47:24 -07:00
|
|
|
}
|
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the status of the backtrace machinery */
|
|
|
|
CAMLprim value caml_backtrace_status(value vunit)
|
|
|
|
{
|
2019-06-07 02:02:14 -07:00
|
|
|
return Val_bool(Caml_state->backtrace_active);
|
2001-11-26 04:47:03 -08:00
|
|
|
}
|
|
|
|
|
2015-08-21 23:04:18 -07:00
|
|
|
/* Print location information -- same behavior as in Printexc
|
2008-03-14 06:47:24 -07:00
|
|
|
|
2015-08-21 23:04:18 -07:00
|
|
|
note that the test for compiler-inserted raises is slightly redundant:
|
|
|
|
(!li->loc_valid && li->loc_is_raise)
|
2016-05-25 06:00:37 -07:00
|
|
|
caml_debuginfo_location guarantees that when li->loc_valid is
|
2015-08-21 23:04:18 -07:00
|
|
|
0, then li->loc_is_raise is always 1, so the latter test is
|
2018-06-20 08:43:29 -07:00
|
|
|
useless. We kept it to keep code identical to the runtime/
|
2015-08-21 23:04:18 -07:00
|
|
|
implementation. */
|
|
|
|
static void print_location(struct caml_loc_info * li, int index)
|
2008-03-14 06:47:24 -07:00
|
|
|
{
|
|
|
|
char * info;
|
2016-05-25 06:00:37 -07:00
|
|
|
char * inlined;
|
2008-03-14 06:47:24 -07:00
|
|
|
|
|
|
|
/* Ignore compiler-inserted raise */
|
|
|
|
if (!li->loc_valid && li->loc_is_raise) return;
|
|
|
|
|
|
|
|
if (li->loc_is_raise) {
|
2001-11-26 04:47:03 -08:00
|
|
|
/* Initial raise if index == 0, re-raise otherwise */
|
|
|
|
if (index == 0)
|
|
|
|
info = "Raised at";
|
|
|
|
else
|
|
|
|
info = "Re-raised at";
|
2001-02-19 04:29:00 -08:00
|
|
|
} else {
|
2002-11-26 02:47:21 -08:00
|
|
|
if (index == 0)
|
|
|
|
info = "Raised by primitive operation at";
|
|
|
|
else
|
|
|
|
info = "Called from";
|
2001-02-19 04:29:00 -08:00
|
|
|
}
|
2016-05-25 06:00:37 -07:00
|
|
|
if (li->loc_is_inlined) {
|
|
|
|
inlined = " (inlined)";
|
|
|
|
} else {
|
|
|
|
inlined = "";
|
|
|
|
}
|
2008-03-14 06:47:24 -07:00
|
|
|
if (! li->loc_valid) {
|
2016-05-25 06:00:37 -07:00
|
|
|
fprintf(stderr, "%s unknown location%s\n", info, inlined);
|
2001-02-19 04:29:00 -08:00
|
|
|
} else {
|
2019-11-20 07:48:10 -08:00
|
|
|
fprintf (stderr, "%s %s in file \"%s\"%s, line %d, characters %d-%d\n",
|
|
|
|
info, li->loc_defname, li->loc_filename, inlined, li->loc_lnum,
|
2008-03-14 06:47:24 -07:00
|
|
|
li->loc_startchr, li->loc_endchr);
|
2001-02-19 04:29:00 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print a backtrace */
|
2003-12-31 06:20:40 -08:00
|
|
|
CAMLexport void caml_print_exception_backtrace(void)
|
2001-02-19 04:29:00 -08:00
|
|
|
{
|
2001-09-24 05:45:55 -07:00
|
|
|
int i;
|
2015-08-21 23:04:18 -07:00
|
|
|
struct caml_loc_info li;
|
2016-05-25 06:00:37 -07:00
|
|
|
debuginfo dbg;
|
2001-02-19 04:29:00 -08:00
|
|
|
|
2015-08-21 23:04:18 -07:00
|
|
|
if (!caml_debug_info_available()) {
|
2015-09-11 04:58:31 -07:00
|
|
|
fprintf(stderr, "(Cannot print stack backtrace: "
|
|
|
|
"no debug information available)\n");
|
2001-10-09 07:02:23 -07:00
|
|
|
return;
|
|
|
|
}
|
2015-02-08 06:10:12 -08:00
|
|
|
|
2019-06-07 02:02:14 -07:00
|
|
|
for (i = 0; i < Caml_state->backtrace_pos; i++) {
|
|
|
|
for (dbg = caml_debuginfo_extract(Caml_state->backtrace_buffer[i]);
|
2016-05-25 06:00:37 -07:00
|
|
|
dbg != NULL;
|
|
|
|
dbg = caml_debuginfo_next(dbg))
|
|
|
|
{
|
|
|
|
caml_debuginfo_location(dbg, &li);
|
|
|
|
print_location(&li, i);
|
|
|
|
}
|
2008-03-14 06:47:24 -07:00
|
|
|
}
|
2018-12-10 23:54:49 -08:00
|
|
|
|
2018-12-11 01:17:04 -08:00
|
|
|
/* See also printexc.ml */
|
2018-12-10 23:54:49 -08:00
|
|
|
switch (caml_debug_info_status()) {
|
|
|
|
case FILE_NOT_FOUND:
|
|
|
|
fprintf(stderr,
|
|
|
|
"(Cannot print locations:\n "
|
|
|
|
"bytecode executable program file not found)\n");
|
|
|
|
break;
|
|
|
|
case BAD_BYTECODE:
|
|
|
|
fprintf(stderr,
|
|
|
|
"(Cannot print locations:\n "
|
|
|
|
"bytecode executable program file appears to be corrupt)\n");
|
|
|
|
break;
|
|
|
|
case WRONG_MAGIC:
|
|
|
|
fprintf(stderr,
|
|
|
|
"(Cannot print locations:\n "
|
|
|
|
"bytecode executable program file has wrong magic number)\n");
|
|
|
|
break;
|
|
|
|
case NO_FDS:
|
|
|
|
fprintf(stderr,
|
|
|
|
"(Cannot print locations:\n "
|
|
|
|
"bytecode executable program file cannot be opened;\n "
|
2018-12-11 01:17:04 -08:00
|
|
|
"-- too many open files. Try running with OCAMLRUNPARAM=b=2)\n");
|
2018-12-10 23:54:49 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the status of loading backtrace information (error reporting in
|
|
|
|
bytecode) */
|
|
|
|
CAMLprim value caml_ml_debug_info_status(value unit)
|
|
|
|
{
|
|
|
|
return Val_int(caml_debug_info_status());
|
2008-03-14 06:47:24 -07:00
|
|
|
}
|
|
|
|
|
2015-08-21 23:04:18 -07:00
|
|
|
/* Get a copy of the latest backtrace */
|
|
|
|
CAMLprim value caml_get_exception_raw_backtrace(value unit)
|
|
|
|
{
|
|
|
|
CAMLparam0();
|
|
|
|
CAMLlocal1(res);
|
2008-03-14 06:47:24 -07:00
|
|
|
|
2019-06-07 02:02:14 -07:00
|
|
|
if (!Caml_state->backtrace_active ||
|
|
|
|
Caml_state->backtrace_buffer == NULL ||
|
|
|
|
Caml_state->backtrace_pos == 0) {
|
2015-08-21 23:04:18 -07:00
|
|
|
res = caml_alloc(0, 0);
|
|
|
|
}
|
|
|
|
else {
|
2019-05-14 08:05:10 -07:00
|
|
|
intnat i, len = Caml_state->backtrace_pos;
|
2015-08-21 23:04:18 -07:00
|
|
|
|
2019-05-14 08:05:10 -07:00
|
|
|
res = caml_alloc(len, 0);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
Field(res, i) = Val_backtrace_slot(Caml_state->backtrace_buffer[i]);
|
2015-08-21 23:04:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
CAMLreturn(res);
|
|
|
|
}
|
|
|
|
|
2016-12-05 07:56:56 -08:00
|
|
|
/* 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;
|
|
|
|
|
2019-06-07 02:02:14 -07:00
|
|
|
Caml_state->backtrace_last_exn = exn;
|
2016-12-05 07:56:56 -08:00
|
|
|
|
|
|
|
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){
|
2019-06-07 02:02:14 -07:00
|
|
|
Caml_state->backtrace_pos = 0;
|
2016-12-05 07:56:56 -08:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate if needed and copy the backtrace buffer */
|
2019-06-17 11:07:49 -07:00
|
|
|
if (Caml_state->backtrace_buffer == NULL &&
|
|
|
|
caml_alloc_backtrace_buffer() == -1) {
|
2016-12-05 07:56:56 -08:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2019-06-07 02:02:14 -07:00
|
|
|
Caml_state->backtrace_pos = bt_size;
|
|
|
|
for(i=0; i < Caml_state->backtrace_pos; i++){
|
|
|
|
Caml_state->backtrace_buffer[i] = Backtrace_slot_val(Field(backtrace, i));
|
2016-12-05 07:56:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2016-05-25 06:00:37 -07:00
|
|
|
#define Val_debuginfo(bslot) (Val_long((uintnat)(bslot)>>1))
|
|
|
|
#define Debuginfo_val(vslot) ((debuginfo)(Long_val(vslot) << 1))
|
|
|
|
|
2015-08-21 23:04:18 -07:00
|
|
|
/* Convert the raw backtrace to a data structure usable from OCaml */
|
2016-05-25 06:00:37 -07:00
|
|
|
static value caml_convert_debuginfo(debuginfo dbg)
|
2015-08-21 23:04:18 -07:00
|
|
|
{
|
2016-05-25 06:00:37 -07:00
|
|
|
CAMLparam0();
|
2019-11-20 07:48:10 -08:00
|
|
|
CAMLlocal3(p, fname, dname);
|
2015-08-21 23:04:18 -07:00
|
|
|
struct caml_loc_info li;
|
2008-03-14 06:47:24 -07:00
|
|
|
|
2016-05-25 06:00:37 -07:00
|
|
|
caml_debuginfo_location(dbg, &li);
|
Printexc: OCaml-friendly access to individual backtrace slots
(Patch by Jacques-Henri Jourdan)
There are several changes:
- `raw_backtrace` is no longer an abstract type, but rather an
`raw_backtrace_slot array`, where `raw_backtrace_slot` is a new
abstract type. `raw_backtrace_slot` elements are hashable and
comparable. At runtime, values of this type contain either
a bytecode pointer or a frame_descr pointer. In order to prevent the
GC from walking through this pointer, the low-order bit is set to
1 when stored in the array.
- The old `loc_info` type is know public, renamed into `backtrace_slot`:
type backtrace_slot =
| Known_location of bool (* is_raise *)
* string (* filename *)
* int (* line number *)
* int (* start char *)
* int (* end char *)
| Unknown_location of bool (*is_raise*)
- new primitive :
val convert_raw_backtrace_slot: raw_backtrace_slot -> backtrace_slot
Rather than returning an option, it raises Failure when it is not
possible to get the debugging information. It seems more idiomatic,
especially because the exceptional case cannot appear only for a part
of the executable.
- the caml_convert_raw_backtrace primitive is removed; it is more
difficult to implement in the C side because of the new exception
interface described above.
- In the bytecode runtime, the events are no longer deserialized once
for each conversion, but once and for all at the first conversion,
and stored in a global array (*outside* the OCaml heap), sorted by
program counter value. I believe this information should not take
much memory in practice (it uses the same order of magnitude memory
as the bytecode executable). It also makes location lookup much more
efficient, as a dichomoty is used instead of linear search as
previously.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14776 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-05-10 12:19:47 -07:00
|
|
|
|
|
|
|
if (li.loc_valid) {
|
|
|
|
fname = caml_copy_string(li.loc_filename);
|
2019-11-20 07:48:10 -08:00
|
|
|
dname = caml_copy_string(li.loc_defname);
|
|
|
|
p = caml_alloc_small(7, 0);
|
Printexc: OCaml-friendly access to individual backtrace slots
(Patch by Jacques-Henri Jourdan)
There are several changes:
- `raw_backtrace` is no longer an abstract type, but rather an
`raw_backtrace_slot array`, where `raw_backtrace_slot` is a new
abstract type. `raw_backtrace_slot` elements are hashable and
comparable. At runtime, values of this type contain either
a bytecode pointer or a frame_descr pointer. In order to prevent the
GC from walking through this pointer, the low-order bit is set to
1 when stored in the array.
- The old `loc_info` type is know public, renamed into `backtrace_slot`:
type backtrace_slot =
| Known_location of bool (* is_raise *)
* string (* filename *)
* int (* line number *)
* int (* start char *)
* int (* end char *)
| Unknown_location of bool (*is_raise*)
- new primitive :
val convert_raw_backtrace_slot: raw_backtrace_slot -> backtrace_slot
Rather than returning an option, it raises Failure when it is not
possible to get the debugging information. It seems more idiomatic,
especially because the exceptional case cannot appear only for a part
of the executable.
- the caml_convert_raw_backtrace primitive is removed; it is more
difficult to implement in the C side because of the new exception
interface described above.
- In the bytecode runtime, the events are no longer deserialized once
for each conversion, but once and for all at the first conversion,
and stored in a global array (*outside* the OCaml heap), sorted by
program counter value. I believe this information should not take
much memory in practice (it uses the same order of magnitude memory
as the bytecode executable). It also makes location lookup much more
efficient, as a dichomoty is used instead of linear search as
previously.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14776 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-05-10 12:19:47 -07:00
|
|
|
Field(p, 0) = Val_bool(li.loc_is_raise);
|
|
|
|
Field(p, 1) = fname;
|
|
|
|
Field(p, 2) = Val_int(li.loc_lnum);
|
|
|
|
Field(p, 3) = Val_int(li.loc_startchr);
|
|
|
|
Field(p, 4) = Val_int(li.loc_endchr);
|
2016-05-25 06:00:37 -07:00
|
|
|
Field(p, 5) = Val_bool(li.loc_is_inlined);
|
2019-11-20 07:48:10 -08:00
|
|
|
Field(p, 6) = dname;
|
2008-03-14 06:47:24 -07:00
|
|
|
} else {
|
Printexc: OCaml-friendly access to individual backtrace slots
(Patch by Jacques-Henri Jourdan)
There are several changes:
- `raw_backtrace` is no longer an abstract type, but rather an
`raw_backtrace_slot array`, where `raw_backtrace_slot` is a new
abstract type. `raw_backtrace_slot` elements are hashable and
comparable. At runtime, values of this type contain either
a bytecode pointer or a frame_descr pointer. In order to prevent the
GC from walking through this pointer, the low-order bit is set to
1 when stored in the array.
- The old `loc_info` type is know public, renamed into `backtrace_slot`:
type backtrace_slot =
| Known_location of bool (* is_raise *)
* string (* filename *)
* int (* line number *)
* int (* start char *)
* int (* end char *)
| Unknown_location of bool (*is_raise*)
- new primitive :
val convert_raw_backtrace_slot: raw_backtrace_slot -> backtrace_slot
Rather than returning an option, it raises Failure when it is not
possible to get the debugging information. It seems more idiomatic,
especially because the exceptional case cannot appear only for a part
of the executable.
- the caml_convert_raw_backtrace primitive is removed; it is more
difficult to implement in the C side because of the new exception
interface described above.
- In the bytecode runtime, the events are no longer deserialized once
for each conversion, but once and for all at the first conversion,
and stored in a global array (*outside* the OCaml heap), sorted by
program counter value. I believe this information should not take
much memory in practice (it uses the same order of magnitude memory
as the bytecode executable). It also makes location lookup much more
efficient, as a dichomoty is used instead of linear search as
previously.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14776 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-05-10 12:19:47 -07:00
|
|
|
p = caml_alloc_small(1, 1);
|
|
|
|
Field(p, 0) = Val_bool(li.loc_is_raise);
|
2008-03-14 06:47:24 -07:00
|
|
|
}
|
2013-03-11 12:04:12 -07:00
|
|
|
|
2015-08-21 23:04:18 -07:00
|
|
|
CAMLreturn(p);
|
2013-03-11 12:04:12 -07:00
|
|
|
}
|
2014-05-10 12:19:53 -07:00
|
|
|
|
2016-05-25 06:00:37 -07:00
|
|
|
CAMLprim value caml_convert_raw_backtrace_slot(value slot)
|
|
|
|
{
|
|
|
|
if (!caml_debug_info_available())
|
|
|
|
caml_failwith("No debug information available");
|
|
|
|
|
|
|
|
return (caml_convert_debuginfo(Debuginfo_val(slot)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert the raw backtrace to a data structure usable from OCaml */
|
|
|
|
CAMLprim value caml_convert_raw_backtrace(value bt)
|
|
|
|
{
|
|
|
|
CAMLparam1(bt);
|
|
|
|
CAMLlocal1(array);
|
|
|
|
intnat i, index;
|
|
|
|
|
|
|
|
if (!caml_debug_info_available())
|
|
|
|
caml_failwith("No debug information available");
|
|
|
|
|
|
|
|
for (i = 0, index = 0; i < Wosize_val(bt); ++i)
|
|
|
|
{
|
|
|
|
debuginfo dbg;
|
|
|
|
for (dbg = caml_debuginfo_extract(Backtrace_slot_val(Field(bt, i)));
|
|
|
|
dbg != NULL;
|
|
|
|
dbg = caml_debuginfo_next(dbg))
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
array = caml_alloc(index, 0);
|
|
|
|
|
|
|
|
for (i = 0, index = 0; i < Wosize_val(bt); ++i)
|
|
|
|
{
|
|
|
|
debuginfo dbg;
|
|
|
|
for (dbg = caml_debuginfo_extract(Backtrace_slot_val(Field(bt, i)));
|
|
|
|
dbg != NULL;
|
|
|
|
dbg = caml_debuginfo_next(dbg))
|
|
|
|
{
|
|
|
|
Store_field(array, index, caml_convert_debuginfo(dbg));
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CAMLreturn(array);
|
|
|
|
}
|
|
|
|
|
|
|
|
CAMLprim value caml_raw_backtrace_length(value bt)
|
|
|
|
{
|
|
|
|
return Val_int(Wosize_val(bt));
|
|
|
|
}
|
|
|
|
|
|
|
|
CAMLprim value caml_raw_backtrace_slot(value bt, value index)
|
|
|
|
{
|
|
|
|
uintnat i;
|
|
|
|
debuginfo dbg;
|
|
|
|
|
|
|
|
i = Long_val(index);
|
|
|
|
if (i >= Wosize_val(bt))
|
|
|
|
caml_invalid_argument("Printexc.get_raw_backtrace_slot: "
|
|
|
|
"index out of bounds");
|
|
|
|
dbg = caml_debuginfo_extract(Backtrace_slot_val(Field(bt, i)));
|
|
|
|
return Val_debuginfo(dbg);
|
|
|
|
}
|
|
|
|
|
|
|
|
CAMLprim value caml_raw_backtrace_next_slot(value slot)
|
|
|
|
{
|
|
|
|
debuginfo dbg;
|
|
|
|
|
|
|
|
CAMLparam1(slot);
|
|
|
|
CAMLlocal1(v);
|
|
|
|
|
|
|
|
dbg = Debuginfo_val(slot);
|
|
|
|
dbg = caml_debuginfo_next(dbg);
|
|
|
|
|
|
|
|
if (dbg == NULL)
|
|
|
|
v = Val_int(0); /* None */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
v = caml_alloc(1, 0);
|
|
|
|
Field(v, 0) = Val_debuginfo(dbg);
|
|
|
|
}
|
|
|
|
|
|
|
|
CAMLreturn(v);
|
|
|
|
}
|
|
|
|
|
2014-05-10 12:19:53 -07:00
|
|
|
/* 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
|
2015-08-21 23:04:24 -07:00
|
|
|
on it as an external. */
|
2014-05-10 12:19:53 -07:00
|
|
|
CAMLprim value caml_get_exception_backtrace(value unit)
|
|
|
|
{
|
|
|
|
CAMLparam0();
|
2015-08-21 23:04:18 -07:00
|
|
|
CAMLlocal3(arr, res, backtrace);
|
|
|
|
intnat i;
|
2014-05-10 12:19:53 -07:00
|
|
|
|
2015-08-21 23:04:18 -07:00
|
|
|
if (!caml_debug_info_available()) {
|
2016-05-25 06:00:37 -07:00
|
|
|
res = Val_int(0); /* None */
|
2014-05-10 12:19:53 -07:00
|
|
|
} else {
|
2015-08-21 23:04:18 -07:00
|
|
|
backtrace = caml_get_exception_raw_backtrace(Val_unit);
|
|
|
|
|
|
|
|
arr = caml_alloc(Wosize_val(backtrace), 0);
|
|
|
|
for (i = 0; i < Wosize_val(backtrace); i++) {
|
2016-05-25 06:00:37 -07:00
|
|
|
backtrace_slot slot = Backtrace_slot_val(Field(backtrace, i));
|
|
|
|
debuginfo dbg = caml_debuginfo_extract(slot);
|
|
|
|
Store_field(arr, i, caml_convert_debuginfo(dbg));
|
2015-08-21 23:04:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
res = caml_alloc_small(1, 0); Field(res, 0) = arr; /* Some */
|
2014-05-10 12:19:53 -07:00
|
|
|
}
|
2015-08-21 23:04:18 -07:00
|
|
|
|
2014-05-10 12:19:53 -07:00
|
|
|
CAMLreturn(res);
|
|
|
|
}
|
2019-04-23 00:27:31 -07:00
|
|
|
|
2020-01-29 09:14:05 -08:00
|
|
|
CAMLprim value caml_get_current_callstack(value max_frames_value)
|
|
|
|
{
|
2019-04-23 00:27:31 -07:00
|
|
|
CAMLparam1(max_frames_value);
|
|
|
|
CAMLlocal1(res);
|
2020-01-29 09:14:05 -08:00
|
|
|
value* callstack = NULL;
|
|
|
|
intnat callstack_alloc_len = 0;
|
|
|
|
intnat callstack_len =
|
|
|
|
caml_collect_current_callstack(&callstack, &callstack_alloc_len,
|
|
|
|
Long_val(max_frames_value), -1);
|
|
|
|
res = caml_alloc(callstack_len, 0);
|
|
|
|
memcpy(Op_val(res), callstack, sizeof(value) * callstack_len);
|
|
|
|
caml_stat_free(callstack);
|
2019-04-23 00:27:31 -07:00
|
|
|
CAMLreturn(res);
|
|
|
|
}
|