Permalink
Browse files

expose Printexc.format_backtrace_slot to facilitate testing

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14781 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information...
1 parent 4f913f2 commit cc6b2ca107b599c592865250d60b11d845604d55 @gasche gasche committed May 10, 2014
Showing with 15 additions and 3 deletions.
  1. +3 −3 stdlib/printexc.ml
  2. +12 −0 stdlib/printexc.mli
View
@@ -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
@@ -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

0 comments on commit cc6b2ca

Please sign in to comment.