From 6b09d9235c3d35d0473d0d8a73b6199e0f28745d Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Mon, 29 Apr 1996 13:24:01 +0000 Subject: [PATCH] Detecter le cas ou l'on trace deux fois la meme fonction sous divers noms. git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@770 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02 --- toplevel/topdirs.ml | 27 ++++++++++++++------------- toplevel/trace.ml | 6 +++--- toplevel/trace.mli | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/toplevel/topdirs.ml b/toplevel/topdirs.ml index 8b862ca989d4..569b2cd40573 100644 --- a/toplevel/topdirs.ml +++ b/toplevel/topdirs.ml @@ -198,15 +198,17 @@ external current_environment: unit -> Obj.t = "get_current_environment" let dir_trace lid = try let (path, desc) = Env.lookup_value lid !toplevel_env in - if is_traced path then begin - Printtyp.path path; print_string " is already traced."; - print_newline() - end else begin - let clos = eval_path path in - (* Nothing to do if it's not a closure *) - if Obj.is_block clos & Obj.tag clos = 250 then begin - let old_clos = copy_closure clos in + let clos = eval_path path in + (* Nothing to do if it's not a closure *) + if Obj.is_block clos & Obj.tag clos = 250 then begin + match is_traced clos with + Some opath -> + Printtyp.path path; print_string " is already traced (under the name "; + Printtyp.path opath; print_string ")"; + print_newline() + | None -> (* Instrument the old closure *) + let old_clos = copy_closure clos in traced_functions := { path = path; closure = clos; @@ -228,11 +230,10 @@ let dir_trace lid = | _ -> Printtyp.longident lid; print_string " is now traced."; print_newline() - end else begin - Printtyp.longident lid; print_string " is not a function."; - print_newline() - end - end + end else begin + Printtyp.longident lid; print_string " is not a function."; + print_newline() + end with Not_found -> print_string "Unbound value "; Printtyp.longident lid; print_newline() diff --git a/toplevel/trace.ml b/toplevel/trace.ml index f9d9ed1f0780..a6e3e9f1fc5d 100644 --- a/toplevel/trace.ml +++ b/toplevel/trace.ml @@ -30,10 +30,10 @@ let traced_functions = ref ([] : traced_function list) (* Check if a function is already traced *) -let is_traced path = +let is_traced clos = let rec is_traced = function - [] -> false - | tf :: rem -> Path.same path tf.path or is_traced rem + [] -> None + | tf :: rem -> if tf.closure == clos then Some tf.path else is_traced rem in is_traced !traced_functions (* Make a copy of a closure *) diff --git a/toplevel/trace.mli b/toplevel/trace.mli index 3b1a637bc675..931f05287068 100644 --- a/toplevel/trace.mli +++ b/toplevel/trace.mli @@ -20,7 +20,7 @@ type traced_function = instrumented_fun: Obj.t } val traced_functions: traced_function list ref -val is_traced: Path.t -> bool +val is_traced: Obj.t -> Path.t option val copy_closure: Obj.t -> Obj.t val overwrite_closure: Obj.t -> Obj.t -> unit val instrument_closure: