···129129 (Bernhard Schommer, review by Daniel Bünzli, Gabriel Scherer and
130130 Alain Frisch)
131131132132+- #9663: Extend Printexc API for raw backtrace entries.
133133+ (Stephen Dolan, review by Nicolás Ojeda Bär and Gabriel Scherer)
134134+132135### Other libraries:
133136134137* #9206, #9419: update documentation of the threads library;
···110110(** {1 Raw backtraces} *)
111111112112type raw_backtrace
113113-(** The abstract type [raw_backtrace] stores a backtrace in
114114- a low-level format, instead of directly exposing them as string as
115115- the [get_backtrace()] function does.
113113+(** The type [raw_backtrace] stores a backtrace in a low-level format,
114114+ which can be converted to usable form using [raw_backtrace_entries]
115115+ and [backtrace_slots_of_raw_entry] below.
116116117117- This allows delaying the formatting of backtraces to when they are
118118- actually printed, which may be useful if you record more
119119- backtraces than you print.
117117+ Converting backtraces to [backtrace_slot]s is slower than capturing the
118118+ backtraces. If an application processes many backtraces, it can be useful
119119+ to use [raw_backtrace] to avoid or delay conversion.
120120121121 Raw backtraces cannot be marshalled. If you need marshalling, you
122122 should use the array returned by the [backtrace_slots] function of
···125125 @since 4.01.0
126126*)
127127128128+type raw_backtrace_entry = private int
129129+(** A [raw_backtrace_entry] is an element of a [raw_backtrace].
130130+131131+ Each [raw_backtrace_entry] is an opaque integer, whose value is not stable
132132+ between different programs, or even between different runs of the same
133133+ binary.
134134+135135+ A [raw_backtrace_entry] can be converted to a usable form using
136136+ [backtrace_slots_of_raw_entry] below. Note that, due to inlining, a
137137+ single [raw_backtrace_entry] may convert to several [backtrace_slot]s.
138138+ Since the values of a [raw_backtrace_entry] are not stable, they cannot
139139+ be marshalled. If they are to be converted, the conversion must be done
140140+ by the process that generated them.
141141+142142+ Again due to inlining, there may be multiple distinct raw_backtrace_entry
143143+ values that convert to equal [backtrace_slot]s. However, if two
144144+ [raw_backtrace_entry]s are equal as integers, then they represent the same
145145+ [backtrace_slot]s.
146146+147147+ @since 4.12.0 *)
148148+149149+val raw_backtrace_entries : raw_backtrace -> raw_backtrace_entry array
150150+(** @since 4.12.0 *)
151151+128152val get_raw_backtrace: unit -> raw_backtrace
129153(** [Printexc.get_raw_backtrace ()] returns the same exception
130154 backtrace that [Printexc.print_backtrace] would print, but in
···224248 @since 4.02.0
225249*)
226250251251+val backtrace_slots_of_raw_entry :
252252+ raw_backtrace_entry -> backtrace_slot array option
253253+(** Returns the slots of a single raw backtrace entry, or [None] if this
254254+ entry lacks debug information.
255255+256256+ Slots are returned in the same order as [backtrace_slots]: the slot
257257+ at index [0] is the most recent call, raise, or primitive, and
258258+ subsequent slots represent callers.
259259+260260+ @since 4.12
261261+*)
262262+263263+227264type location = {
228265 filename : string;
229266 line_number : int;
···296333(** {1 Raw backtrace slots} *)
297334298335type raw_backtrace_slot
299299-(** This type allows direct access to raw backtrace slots, without any
300300- conversion in an OCaml-usable data-structure. Being
301301- process-specific, they must absolutely not be marshalled, and are
302302- unsafe to use for this reason (marshalling them may not fail, but
303303- un-marshalling and using the result will result in
304304- undefined behavior).
336336+(** This type is used to iterate over the slots of a [raw_backtrace].
337337+ For most purposes, [backtrace_slots_of_raw_entry] is easier to use.
305338306306- Elements of this type can still be compared and hashed: when two
307307- elements are equal, then they represent the same source location
308308- (the converse is not necessarily true in presence of inlining,
309309- for example).
339339+ Like [raw_backtrace_entry], values of this type are process-specific and
340340+ must absolutely not be marshalled, and are unsafe to use for this reason
341341+ (marshalling them may not fail, but un-marshalling and using the result
342342+ will result in undefined behavior).
343343+344344+ Elements of this type can still be compared and hashed: when two elements
345345+ are equal, then they represent the same source location (the converse is not
346346+ necessarily true in presence of inlining, for example).
310347311348 @since 4.02.0
312349*)