@@ -59,7 +59,7 @@ module Debug : sig
5959
6060 val find_loc : t -> position :position -> Code.Addr .t -> Parse_info .t option
6161
62- val find_loc' : t -> int -> (string option * Instruct .debug_event ) option
62+ val find_locs : t -> int -> (string option * Instruct .debug_event ) list
6363
6464 val event_location :
6565 position :position
@@ -301,11 +301,16 @@ end = struct
301301 let dummy_location (loc : Location.t ) =
302302 loc.loc_start.pos_cnum = - 1 || loc.loc_end.pos_cnum = - 1
303303
304- let find_loc' { events_by_pc; _ } pc =
305- match Int_table. find events_by_pc pc with
306- | exception Not_found -> None
307- | { event; source } ->
308- if dummy_location event.ev_loc then None else Some (source, event)
304+ (* We can have several events at the same location when a function
305+ application is followed by a branch target, typically due to some
306+ code like [if ... then f(); ...] : the event after the function
307+ application, and the event at the beginning of the continuation.
308+ Both events are interesting. They are returned by this function
309+ in the expected order: first after the function call, then before
310+ the continuation. *)
311+ let find_locs { events_by_pc; _ } pc =
312+ List. filter_map (Int_table. find_all events_by_pc pc) ~f: (fun { event; source } ->
313+ if dummy_location event.ev_loc then None else Some (source, event))
309314
310315 let event_location ~position ~source ~event =
311316 let pos =
@@ -316,9 +321,9 @@ end = struct
316321 Parse_info. t_of_position ~src: source pos
317322
318323 let find_loc t ~position pc =
319- match find_loc' t pc with
320- | None -> None
321- | Some (source , event ) -> Some (event_location ~position ~source ~event )
324+ match find_locs t pc with
325+ | [] -> None
326+ | (source , event ) :: _ -> Some (event_location ~position ~source ~event )
322327
323328 let rec propagate l1 l2 =
324329 match l1, l2 with
@@ -840,9 +845,9 @@ type compile_info =
840845 }
841846
842847let string_of_addr debug_data addr =
843- match Debug. find_loc' debug_data addr with
844- | None -> None
845- | Some ( src , { ev_loc = loc ; ev_kind = kind ; _ } ) ->
848+ List. map
849+ ( Debug. find_locs debug_data addr)
850+ ~f: ( fun ( src , { Instruct. ev_loc = loc ; ev_kind = kind ; _ } ) ->
846851 let pos (p : Lexing.position ) =
847852 Printf. sprintf " %d:%d" p.pos_lnum (p.pos_cnum - p.pos_bol)
848853 in
@@ -857,7 +862,7 @@ let string_of_addr debug_data addr =
857862 | Event_after _ -> " (after)"
858863 | Event_pseudo -> " (pseudo)"
859864 in
860- Some ( Printf. sprintf " %s:%s-%s %s" file (pos loc.loc_start) (pos loc.loc_end) kind)
865+ Printf. sprintf " %s:%s-%s %s" file (pos loc.loc_start) (pos loc.loc_end) kind)
861866
862867let rec compile_block blocks debug_data code pc state =
863868 match Addr.Map. find_opt pc ! tagged_blocks with
@@ -932,23 +937,23 @@ let rec compile_block blocks debug_data code pc state =
932937and compile infos pc state instrs =
933938 if debug_parser () then State. print state;
934939 assert (pc < = infos.limit);
935- (if debug_parser ()
936- then
937- match string_of_addr infos.debug pc with
938- | None -> ()
939- | Some s -> Format. eprintf " @@@@ %s @@@@@." s);
940+ if debug_parser ()
941+ then
942+ List. iter (string_of_addr infos.debug pc) ~f: (fun s ->
943+ Format. eprintf " @@@@ %s @@@@@." s);
940944
941945 let instrs =
942946 let push_event position source event instrs =
943947 match instrs with
944948 | (Event _ , _ ) :: instrs | instrs ->
945949 (Event (Debug. event_location ~position ~source ~event ), noloc) :: instrs
946950 in
947- match Debug. find_loc' infos.debug pc with
948- | None -> instrs
949- | Some (source , event ) -> (
951+ List. fold_left
952+ (Debug. find_locs infos.debug pc)
953+ ~init: instrs
954+ ~f: (fun instrs (source , event ) ->
950955 match event, instrs with
951- | { ev_kind = Event_pseudo ; ev_info = Event_other ; _ } , _ ->
956+ | { Instruct. ev_kind = Event_pseudo ; ev_info = Event_other ; _ } , _ ->
952957 (* Ignore allocation events (not very interesting) *)
953958 if debug_parser () then Format. eprintf " Ignored allocation event@." ;
954959 instrs
0 commit comments