@@ -53,6 +53,14 @@ module Debug : sig
5353
5454 val mem : t -> Code.Addr .t -> bool
5555
56+ val read_event :
57+ paths :string list
58+ -> crcs :(string , string option ) Hashtbl .t
59+ -> orig :int
60+ -> t
61+ -> Instruct .debug_event
62+ -> unit
63+
5664 val read :
5765 t -> crcs :(string * string option ) list -> includes :string list -> in_channel -> unit
5866
@@ -125,6 +133,67 @@ end = struct
125133 | Some _ as x -> x
126134 | None -> Fs. find_in_path paths (name ^ " .ml" )
127135
136+ let read_event
137+ ~paths
138+ ~crcs
139+ ~orig
140+ { events_by_pc; units; pos_fname_to_source; names; enabled; include_cmis = _ }
141+ ev =
142+ let pos_fname =
143+ match ev.ev_loc.Location. loc_start.Lexing. pos_fname with
144+ | "_none_" -> None
145+ | x -> Some x
146+ in
147+ let ev_module = ev.ev_module in
148+ let unit =
149+ try Hashtbl. find units (ev_module, pos_fname)
150+ with Not_found ->
151+ let crc = try Hashtbl. find crcs ev_module with Not_found -> None in
152+ let source : path option =
153+ (* First search the source based on [pos_fname] because the
154+ filename of the source might be unreleased to the
155+ module name. (e.g. pos_fname = list.ml, module = Stdlib__list) *)
156+ let from_pos_fname =
157+ match pos_fname with
158+ | None -> None
159+ | Some pos_fname -> (
160+ match Fs. find_in_path paths pos_fname with
161+ | Some _ as x -> x
162+ | None -> Fs. find_in_path paths (Filename. basename pos_fname))
163+ in
164+ match from_pos_fname with
165+ | None -> find_ml_in_paths paths ev_module
166+ | Some _ as x -> x
167+ in
168+ let source =
169+ match source with
170+ | None -> None
171+ | Some source -> Some (Fs. absolute_path source)
172+ in
173+ if debug_sourcemap ()
174+ then
175+ Format. eprintf
176+ " module:%s - source:%s - name:%s\n %!"
177+ ev_module
178+ (match source with
179+ | None -> " NONE"
180+ | Some x -> x)
181+ (match pos_fname with
182+ | None -> " NONE"
183+ | Some x -> x);
184+ let u = { module_name = ev_module; crc; source; paths } in
185+ (match pos_fname, source with
186+ | None , _ | _ , None -> ()
187+ | Some pos_fname , Some source ->
188+ String_table. add pos_fname_to_source pos_fname source);
189+ Hashtbl. add units (ev_module, pos_fname) u;
190+ u
191+ in
192+ relocate_event orig ev;
193+ if enabled || names
194+ then Int_table. add events_by_pc ev.ev_pos { event = ev; source = unit .source };
195+ ()
196+
128197 let read_event_list =
129198 let rewrite_path path =
130199 if Filename. is_relative path
@@ -135,73 +204,15 @@ end = struct
135204 | None -> path
136205 in
137206 let read_paths ic : string list = List. map (input_value ic) ~f: rewrite_path in
138- fun { events_by_pc; units; pos_fname_to_source; names; enabled; include_cmis = _ }
139- ~crcs
140- ~includes
141- ~orig
142- ic ->
207+ fun debug ~crcs ~includes ~orig ic ->
143208 let crcs =
144209 let t = Hashtbl. create 17 in
145210 List. iter crcs ~f: (fun (m , crc ) -> Hashtbl. add t m crc);
146211 t
147212 in
148213 let evl : debug_event list = input_value ic in
149214 let paths = read_paths ic @ includes in
150- List. iter evl ~f: (fun ev ->
151- let pos_fname =
152- match ev.ev_loc.Location. loc_start.Lexing. pos_fname with
153- | "_none_" -> None
154- | x -> Some x
155- in
156- let ev_module = ev.ev_module in
157- let unit =
158- try Hashtbl. find units (ev_module, pos_fname)
159- with Not_found ->
160- let crc = try Hashtbl. find crcs ev_module with Not_found -> None in
161- let source : path option =
162- (* First search the source based on [pos_fname] because the
163- filename of the source might be unreleased to the
164- module name. (e.g. pos_fname = list.ml, module = Stdlib__list) *)
165- let from_pos_fname =
166- match pos_fname with
167- | None -> None
168- | Some pos_fname -> (
169- match Fs. find_in_path paths pos_fname with
170- | Some _ as x -> x
171- | None -> Fs. find_in_path paths (Filename. basename pos_fname))
172- in
173- match from_pos_fname with
174- | None -> find_ml_in_paths paths ev_module
175- | Some _ as x -> x
176- in
177- let source =
178- match source with
179- | None -> None
180- | Some source -> Some (Fs. absolute_path source)
181- in
182- if debug_sourcemap ()
183- then
184- Format. eprintf
185- " module:%s - source:%s - name:%s\n %!"
186- ev_module
187- (match source with
188- | None -> " NONE"
189- | Some x -> x)
190- (match pos_fname with
191- | None -> " NONE"
192- | Some x -> x);
193- let u = { module_name = ev_module; crc; source; paths } in
194- (match pos_fname, source with
195- | None , _ | _ , None -> ()
196- | Some pos_fname , Some source ->
197- String_table. add pos_fname_to_source pos_fname source);
198- Hashtbl. add units (ev_module, pos_fname) u;
199- u
200- in
201- relocate_event orig ev;
202- if enabled || names
203- then Int_table. add events_by_pc ev.ev_pos { event = ev; source = unit .source };
204- () )
215+ List. iter evl ~f: (read_event ~paths ~crcs ~orig debug)
205216
206217 let find_source { pos_fname_to_source; _ } pos_fname =
207218 match pos_fname with
@@ -675,7 +686,7 @@ module State = struct
675686 | Some loc -> Var. loc v (pi_of_loc debug loc));
676687 Var. name v nm;
677688 name_rec debug (i + 1 ) lrem srem summary
678- | (j , _ , _ ) :: _ , _ :: srem when i < j -> name_rec debug (i + 1 ) l srem summary
689+ | (j , _nm , _ ) :: _ , _ :: srem when i < j -> name_rec debug (i + 1 ) l srem summary
679690 | _ -> assert false
680691
681692 let name_vars st debug pc =
@@ -2455,8 +2466,13 @@ let from_exe
24552466 { code; cmis; debug = debug_data }
24562467
24572468(* As input: list of primitives + size of global table *)
2458- let from_bytes primitives (code : bytecode ) =
2459- let debug_data = Debug. create ~include_cmis: false false in
2469+ let from_bytes ~prims ~debug (code : bytecode ) =
2470+ let debug_data = Debug. create ~include_cmis: false true in
2471+ if Debug. names debug_data
2472+ then
2473+ Array. iter debug ~f: (fun l ->
2474+ List. iter l ~f: (fun ev ->
2475+ Debug. read_event ~paths: [] ~crcs: (Hashtbl. create 17 ) ~orig: 0 debug_data ev));
24602476 let ident_table =
24612477 let t = Hashtbl. create 17 in
24622478 if Debug. names debug_data
@@ -2466,7 +2482,7 @@ let from_bytes primitives (code : bytecode) =
24662482 (Symtable. current_state () );
24672483 t
24682484 in
2469- let globals = make_globals 0 [||] primitives in
2485+ let globals = make_globals 0 [||] prims in
24702486 let p = parse_bytecode code globals debug_data in
24712487 let gdata = Var. fresh_n " global_data" in
24722488 let need_gdata = ref false in
@@ -2500,7 +2516,7 @@ let from_bytes primitives (code : bytecode) =
25002516 in
25012517 prepend p body, debug_data
25022518
2503- let from_string primitives (code : string ) = from_bytes primitives code
2519+ let from_string ~ prims ~ debug (code : string ) = from_bytes ~prims ~debug code
25042520
25052521module Reloc = struct
25062522 let gen_patch_int buff pos n =
0 commit comments