Commit Graph

51 Commits (bfd3d7deb057372162026c5d50b4c2782e4cdd25)

Author SHA1 Message Date
Stephen Dolan 0040c5d783 Print function names (derived from Lambda.scoped_location) in backtraces
Function names now appear in backtraces and are available via Printexc.
2020-04-27 12:58:53 +01:00
Raphael Sousa Santos c9d7cc7da4 Add Printexc.default_uncaught_exception_handler (issue #9248)
Printexc.uncaught_exception_handler ceases to be an option ref and becomes
a ref to the handler function initialized to
Printexc.default_uncaught_exception_handler.
2020-01-26 12:00:27 +01:00
Jacques-Henri Jourdan 23e5bfa3bb Better stack backtraces for C calls in bytecode (#8641)
The previous mechanism worked for C calls that raise an exception, but not for C calls that call back into OCaml code which raises an exception.

This commit addresses the issue by saving the PC in the interpreter stack before a C call, so that the backtrace mechanism always sees it.

However, if an external is declared in the .ml file and exposed in the .mli file as a val, then ocamlc generates a wrapper that adds a spurious entry in the stack frame. In this PR, this change in behavior results in the re-declaration of Printexc.get_callstack as an external instead of a val, so that the spurious stack frame does not appear in call stacks obtained from Printexc.get_callstack.
2019-10-12 18:25:58 +02:00
Andrew Litteken d4ef2eecea Custom Exception Handlers at toplevel (#8594)
fixes #7156 

Two new functions exposed:

```ocaml
val to_string_default: exn -> string
(** [Printexc.to_string_default e] returns a string representation of the
    exception [e], ignoring all registered exception printers.
    @since 4.09
*)

val use_printers: exn -> string option
(** [Printexc.use_printers e] returns [None] if there are no registered
    printers and [Some s] with else as the resulting string otherwise.
    @since 4.09
*)
```
2019-04-14 15:38:27 +02:00
yallop ee1c2a4d7e Add paths for built-in types (#1876)
* Add an Extension_constructor submodule to Obj.

Deprecate top-level functions extension_constructor / extension_name /
extension_id.

* Add 'true' and 'false' to the definition of Bool.t

* Add aliases for the built-in 'list' and 'array' types.

* Add an alias for 'exn' to Printexc.

* Changes entry: built-in type aliases

* Add a Unit module.

* Add paths for built-in exceptions.
2018-11-08 16:08:17 +01:00
Jérémie Dimino 9124ab82d1
Deprecate Pervasives (#1605)
- inline Pervasives in Stdlib and re-add Pervasives as a deprecated
module that aliases all elements of Stdlib except the stdlib modules.

- remove special case for Stdlib.Pervasives in printtyp.ml
2018-08-27 12:42:14 +01:00
octachron e30e82a219 PR#7363: start documentation headers at {1 2017-10-04 13:05:05 +02:00
Max Mouratov 3ef5925dd4 Fixed erroneous comments 2017-04-06 14:16:18 +02:00
Török Edwin 20f61d7fb4 Documentation: improve @since annotations
Add missing @since annotations for OCaml versions 4.00.0 - 4.05.0,
and fix existing annotations as needed:

Format.ikprintf: clarify ambiguity on @since 4.0 annotation
See b81519668f

Hashtbl.is_randomized and ListLabels.sort_uniq should be @since 4.03
List.sort_uniq is 4.02 but ListLabels.sort_uniq is 4.03
See:
512d128918
189d29bfcf
2017-02-21 17:11:51 +02:00
François Bobot 50e9b96564 Recover "Merge pull request #378 from bobot/feature/reraise_raw_backtrace_primitive"
This reverts commit f1b63d4a57.
It is the second time #378 tried to be recovered (e6c779ada8).
2017-02-14 09:21:45 -05:00
Frédéric Bour 99923f7b7a GPR #922 : add GPR#247 to Changes 2016-11-26 11:47:20 -05:00
Damien Doligez 0b4fbc2b30 fix whitespace, long lines, headers 2016-08-01 16:06:59 +02:00
Gabriel Scherer f1b63d4a57 Revert "Merge pull request #378 from bobot/feature/reraise_raw_backtrace_primitive"
This reverts commit 5adf895aac, reversing
changes made to 38c3db40c7.

The reason for the revert is a continuous integration failure on 32bit
arm machines. I don't have the time (or capabilities) to investigate
it right now, and we need functional continuous testing for other
upcoming merges, so the safest choice is to revert -- and hopefully
merge back after the issue is fixed.
2016-07-27 11:30:26 -04:00
François Bobot 131c0e23fd Precise where reliable backtrace can't be obtained
In fact currently even if you use `print_backtrace`,
        `get_backtrace` or `get_raw_backtrace` just at the start of an
        exception handler the backtrace can be wrong if an exception
        have been raised and catched in a `when` clause.
2016-07-17 22:37:03 +02:00
François Bobot 10f5095a15 Add `%reraise_raw_backtrace` primitive
It reraises an exception just after copying the given backtrace to the
  backtrace buffer. The C primitive `caml_restore_raw_backtrace` only does
  the copying part, the compiler adds the reraise.
2016-07-17 22:37:03 +02:00
Damien Doligez a748528b27 GPR#604: minor doc typo 2016-06-07 14:40:07 +02:00
Frédéric Bour 28dc832030 Make backtraces aware of inlining (#247) 2016-05-25 14:00:37 +01:00
Damien Doligez 5401ce8473 Update headers for the new license.
Remains to be done: remove all headers in testsuite/tests.
2016-02-18 16:59:16 +01:00
Gabriel Scherer d6189d83a4 Add @since tags on stdlib functions new in 4.02
make_float was added in 4.02
Buffer.(to_bytes, add_bytes, add_subbytes) were added in 4.02.
BytesLabels was added in 4.02.
Digest.(bytes, subbytes) were added in 4.02.
Marshal.(to_bytes, from_bytes) were added in 4.02.
various Pervasives functions were added in 4.02: print_bytes prerr_bytes output_bytes output_substring really_input_string
Printexc.(backtrace_slots, raw_backtrace_slot) were added in 4.02.
Scanf.(ksscanf, kfscanf) were added in 4.02.
Stream.of_bytes was added in 4.02.

From: Jeremy Yallop <yallop@gmail.com>

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@15687 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-12-19 17:31:47 +00:00
Jérémie Dimino 98e0051f5c PR#6619: update documentation of Printexc.set_uncaught_exception_handler
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@15560 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-10-20 13:15:33 +00:00
Gabriel Scherer 755b19650b Reformulation of the user-facing slot-access API
- The internal [backtrace_slot] type is not exposed anymore, instead
  accessors function return orthogonal information
  (is_raise, location). This is both more extensible and more
  user-friendly.

- The [raw_backtrace_slot] is exposed separately as a low-level type
  that most users should never use. The unsafety of marshalling is
  documented. Instead of defining
  [raw_backtrace = raw_backtrace_slot array], I kept [raw_backtrace]
  an abstract type with [length] and [get] functions for
  random-access. This should allow us to change the implementation in
  the future to be more robust wrt. marshalling (boxing the trace in
  a Custom block, or even possibly the raw slots at access time).

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14784 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-05-10 19:20:00 +00:00
Gabriel Scherer cc6b2ca107 expose Printexc.format_backtrace_slot to facilitate testing
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14781 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-05-10 19:19:55 +00:00
Gabriel Scherer 1fdea57c4c 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 19:19:47 +00:00
Jérémie Dimino d3ec5feb26 PR#5941: add Printexc.set_uncaught_exception_handler
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14643 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-04-18 15:36:08 +00:00
Damien Doligez 7303ac34ca fix some of the whitespace problems in the source
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14582 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-04-12 10:17:02 +00:00
Alain Frisch f16534ef1a Reintegrate raise_variants branch.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14289 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2013-11-13 13:55:13 +00:00
Alain Frisch 171a77daba Fix typos and wording (#6231).
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14274 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2013-11-08 15:36:36 +00:00
Alain Frisch be3c4d6882 Add two functions to get the exception slot id and name from an exception value.
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/raise_variants@14240 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2013-10-23 14:35:43 +00:00
Alain Frisch 7334bb026a #5899: expose Printexc.get_callstack. (Cherry-picked 13884, 13885 from trunk.)
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13886 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2013-07-11 12:37:10 +00:00
Gabriel Scherer 725da3dcc9 user-exposed abstract type for raw backtraces in Printexc.ml (original patch from Jacques-Henri Jourdan)
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13394 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2013-03-11 19:04:12 +00:00
Alain Frisch ba00d09386 Revert bad commit.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13268 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2013-01-23 08:41:02 +00:00
Alain Frisch 20a4b99758 #5902: adapt standard ppx driver to support extra arguments.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13267 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2013-01-23 08:37:01 +00:00
Damien Doligez def31744f9 remove all $Id keywords
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13013 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2012-10-15 17:50:56 +00:00
Damien Doligez 3b507dd1aa renaming of Objective Caml to OCaml and cleanup of copyright headers
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@11156 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2011-07-27 14:17:02 +00:00
Xavier Clerc d9b3046c49 Some precisions about the use of a backtrace from a exception printer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@11088 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2011-06-14 11:08:07 +00:00
Damien Doligez 9209d550c5 PR#4831: use tags @since and @before in std lib
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10457 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-21 18:30:12 +00:00
Alain Frisch e178c1ab62 Fix #5003: document the fact that expressions raised by exception printers are just ignored; custom printers are tried before hard-coded ones.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10272 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-04-19 12:25:46 +00:00
Damien Doligez bdc0fadee2 merge changes from release/3.11.1 to release/3.11.2
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@9540 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-01-20 16:26:46 +00:00
Xavier Leroy 640b24249d Ability to print and capture exception backtraces (see stdlib module Printexc)
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@8839 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2008-03-14 13:47:24 +00:00
Damien Doligez 0e5ca9dca5 nettoyage
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@7164 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2005-10-25 18:34:07 +00:00
Xavier Leroy 7501784c80 MAJ en-tetes pour mentionner la 'special exception' sur la LGPL
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@4144 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2001-12-07 13:41:02 +00:00
Maxence Guesdon ef3d334d4a commentaires après
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@4083 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2001-12-03 22:16:03 +00:00
Maxence Guesdon b95796f461 Modification emplacement et syntaxe commentaires pour OCamldoc
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3926 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2001-10-26 22:38:48 +00:00
Xavier Leroy 65083e9a91 Marquer comme 'deprecated' Printexc.catch
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3540 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2001-06-19 10:04:04 +00:00
Xavier Leroy cc0f32b054 Changement de la licence
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2553 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1999-11-17 18:59:06 +00:00
Damien Doligez 9704b7a5f5 Ajout de Printexc.to_string.
Suppression de Printexc.print_exn qui est redondant.


git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@1589 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1997-06-12 15:29:01 +00:00
Damien Doligez 28a67e328e exportation de Printexc.print_exn et customisation Mac
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@1581 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1997-06-06 14:54:09 +00:00
Xavier Leroy 2301d778e7 Renommage en Objective Caml
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@782 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1996-04-30 14:53:58 +00:00
Xavier Leroy e4066357b1 Ajout des notices de copyright
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@195 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1995-08-09 15:06:35 +00:00
Xavier Leroy d0012c733a MAJ des commentaires de doc dans les interfaces
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@190 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1995-08-09 13:15:01 +00:00