1 (***********************************************************************)
5 (* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *)
6 (* Objective Caml port by John Malecki and Xavier Leroy *)
8 (* Copyright 1996 Institut National de Recherche en Informatique et *)
9 (* en Automatique. All rights reserved. This file is distributed *)
10 (* under the terms of the Q Public License version 1.0. *)
12 (***********************************************************************)
25 (* To name printed and ellipsed values *)
28 (Hashtbl.create
29 : (int, Debugcom.Remote_value.t
* type_expr
) Hashtbl.t
)
31 let reset_named_values () =
32 Hashtbl.clear
named_values;
36 let name = !next_name in
38 Hashtbl.add
named_values name (v
, ty
);
41 let find_named_value name =
42 Hashtbl.find
named_values name
44 let check_depth ppf depth obj ty
=
45 if depth
<= 0 then begin
46 let n = name_value obj ty
in
47 Some
(Outcometree.Oval_stuff
("$" ^ string_of_int
n))
52 type value = Debugcom.Remote_value.t
54 let rec eval_path = function
57 Debugcom.Remote_value.global
(Symtable.get_global_position id
)
58 with Symtable.Error _
->
61 | Pdot
(root
, fieldname
, pos
) ->
62 let v = eval_path root
in
63 if not
(Debugcom.Remote_value.is_block
v)
65 else Debugcom.Remote_value.field
v pos
68 let same_value = Debugcom.Remote_value.same
71 module Printer
= Genprintval.Make
(Debugcom.Remote_value
)(EvalPath
)
73 let install_printer path ty ppf fn
=
74 Printer.install_printer path ty
75 (fun ppf remote_val
->
77 fn ppf
(Obj.repr
(Debugcom.Remote_value.obj remote_val
))
79 Debugcom.Marshalling_error
->
80 fprintf ppf
"<cannot fetch remote object>")
82 let remove_printer = Printer.remove_printer
84 let max_printer_depth = ref 20
85 let max_printer_steps = ref 300
87 let print_exception ppf obj
=
88 let t = Printer.outval_of_untyped_exception obj
in
89 !Oprint.out_value ppf
t
91 let print_value max_depth env obj
(ppf
: Format.formatter
) ty
=
93 Printer.outval_of_value
!max_printer_steps max_depth
94 (check_depth ppf
) env obj ty
in
95 !Oprint.out_value ppf
t
97 let print_named_value max_depth exp env obj ppf ty
=
98 let print_value_name ppf
= function
100 Printtyp.longident ppf lid
104 let n = name_value obj ty
in
105 fprintf ppf
"$%i" n in
106 Printtyp.reset_and_mark_loops ty
;
107 fprintf ppf
"@[<2>%a :@ %a@ =@ %a@]@."
109 Printtyp.type_expr ty
110 (print_value max_depth env obj
) ty