expose Printexc.format_backtrace_slot to facilitate testing

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14781 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Gabriel Scherer 2014-05-10 19:19:55 +00:00
parent 4f913f2498
commit cc6b2ca107
2 changed files with 15 additions and 3 deletions

View File

@ -106,7 +106,7 @@ let convert_raw_backtrace rbckt =
try Some (Array.map convert_raw_backtrace_slot rbckt)
with Failure _ -> None
let format_loc_info pos li =
let format_backtrace_slot pos li =
let is_raise =
match li with
| Known_location(is_raise, _, _, _, _) -> is_raise
@ -133,7 +133,7 @@ let print_exception_backtrace outchan backtrace =
| Some a ->
for i = 0 to Array.length a - 1 do
if a.(i) <> Unknown_location true then
fprintf outchan "%s\n" (format_loc_info i a.(i))
fprintf outchan "%s\n" (format_backtrace_slot i a.(i))
done
let print_raw_backtrace outchan raw_backtrace =
@ -151,7 +151,7 @@ let backtrace_to_string backtrace =
let b = Buffer.create 1024 in
for i = 0 to Array.length a - 1 do
if a.(i) <> Unknown_location true then
bprintf b "%s\n" (format_loc_info i a.(i))
bprintf b "%s\n" (format_backtrace_slot i a.(i))
done;
Buffer.contents b

View File

@ -139,6 +139,18 @@ type backtrace_slot =
*)
val convert_raw_backtrace_slot: raw_backtrace_slot -> backtrace_slot
(** [format_backtrace_slot pos slot] returns the string
representation of the backtrace slot [slot] as
[raw_backtrace_to_string] would format it, assuming it is the
[pos]-th element of the backtrace: the 0-th element is
pretty-printed differently than the other.
Note that Printexc's printing function will skip any slot equal to
[Unknown_location true]; you should as well if you wish to
reproduce its behavior.
*)
val format_backtrace_slot : int -> backtrace_slot -> string
(** {6 Current call stack} *)
val get_callstack: int -> raw_backtrace