@@ -602,8 +602,13 @@ module DwarfPrinter(Target: DWARF_TARGET):
602602 print_sleb128 oc " " 0 ;
603603 print_label oc debug_end (* End of the debug section *)
604604
605- let print_location_entry oc c_low l =
605+ let print_location_entry oc needs_base c_low l =
606606 print_label oc (loc_to_label l.loc_id);
607+ (* If we have multiple ranges per compilation unit we need to specify a base address for the location *)
608+ if needs_base then begin
609+ fprintf oc " %s -1\n " address;
610+ fprintf oc " %s %a\n " address label c_low;
611+ end ;
607612 List. iter (fun (b ,e ,loc ) ->
608613 fprintf oc " %s %a-%a\n " address label b label c_low;
609614 fprintf oc " %s %a-%a\n " address label e label c_low;
@@ -621,11 +626,11 @@ module DwarfPrinter(Target: DWARF_TARGET):
621626 fprintf oc " %s 0\n " address
622627
623628
624- let print_location_list oc ( c_low , l ) =
625- let f = match c_low with
626- | Some s -> print_location_entry oc s
627- | None -> print_location_entry_abs oc in
628- List. iter f l
629+ let print_location_list oc needs_base l =
630+ let f l = match l.loc_sec_begin with
631+ | Some s -> print_location_entry oc needs_base s l
632+ | None -> print_location_entry_abs oc l in
633+ List. iter f l
629634
630635 let list_opt l f =
631636 match l with
@@ -635,15 +640,15 @@ module DwarfPrinter(Target: DWARF_TARGET):
635640 let print_diab_entries oc entries =
636641 let abbrev_start = new_label () in
637642 abbrev_start_addr := abbrev_start;
638- List. iter (fun e -> compute_abbrev e.entry ) entries;
643+ List. iter (fun e -> compute_abbrev e.diab_entry ) entries;
639644 print_abbrev oc;
640645 List. iter (fun e ->
641646 let name = if e.section_name <> " .text" then Some e.section_name else None in
642647 section oc (Section_debug_info name);
643- print_debug_info oc e.start_label e.line_label e.entry ) entries;
644- if List. exists (fun e -> match e.dlocs with _ , [] -> false | _ , _ -> true ) entries then begin
648+ print_debug_info oc e.start_label e.line_label e.diab_entry ) entries;
649+ if List. exists (fun e -> match e.diab_locs with [] -> false | _ -> true ) entries then begin
645650 section oc Section_debug_loc ;
646- List. iter (fun e -> print_location_list oc e.dlocs ) entries
651+ List. iter (fun e -> print_location_list oc false e.diab_locs ) entries
647652 end
648653
649654 let print_ranges oc r =
@@ -665,27 +670,27 @@ module DwarfPrinter(Target: DWARF_TARGET):
665670 fprintf oc " %s 0\n " address;
666671 fprintf oc " %s 0\n " address) r
667672
668- let print_gnu_entries oc cp ( lpc , loc ) s r =
669- compute_abbrev cp ;
673+ let print_gnu_entries oc entries =
674+ compute_abbrev entries.gnu_entry ;
670675 let line_start = new_label ()
671676 and start = new_label ()
672677 and abbrev_start = new_label ()
673678 and range_label = new_label () in
674679 debug_ranges_addr := range_label;
675680 abbrev_start_addr := abbrev_start;
676681 section oc (Section_debug_info None );
677- print_debug_info oc start line_start cp ;
682+ print_debug_info oc start line_start entries.gnu_entry ;
678683 print_abbrev oc;
679- list_opt loc (fun () ->
684+ list_opt entries.gnu_locs (fun () ->
680685 section oc Section_debug_loc ;
681- print_location_list oc (lpc,loc) );
682- list_opt r (fun () ->
683- print_ranges oc r );
686+ print_location_list oc entries.several_secs entries.gnu_locs );
687+ list_opt entries.range_table (fun () ->
688+ print_ranges oc entries.range_table );
684689 section oc (Section_debug_line None );
685690 print_label oc line_start;
686- list_opt s (fun () ->
691+ list_opt entries.string_table (fun () ->
687692 section oc Section_debug_str ;
688- let s = List. sort (fun (a ,_ ) (b ,_ ) -> compare a b) s in
693+ let s = List. sort (fun (a ,_ ) (b ,_ ) -> compare a b) entries.string_table in
689694 List. iter (fun (id ,s ) ->
690695 print_label oc (loc_to_label id);
691696 fprintf oc " .asciz %S\n " s) s)
@@ -698,6 +703,6 @@ module DwarfPrinter(Target: DWARF_TARGET):
698703 Hashtbl. clear loc_labels;
699704 match debug with
700705 | Diab entries -> print_diab_entries oc entries
701- | Gnu ( cp , loc , s , r ) -> print_gnu_entries oc cp loc s r
706+ | Gnu entries -> print_gnu_entries oc entries
702707
703708 end
0 commit comments