aboutsummaryrefslogtreecommitdiffstats
path: root/debug
diff options
context:
space:
mode:
authorBernhard Schommer <bernhardschommer@gmail.com>2020-02-06 14:55:34 +0100
committerBernhard Schommer <bschommer@users.noreply.github.com>2020-02-06 17:28:39 +0100
commit6ca9f9bfc7119f1ca4f48de3b5a37cbaee07e4fd (patch)
tree10d82488c0f84f927888deaa5de76e30535e2f53 /debug
parentd5435a34169d92a96f1436128f3e90df7f4f9e9a (diff)
downloadcompcert-kvx-6ca9f9bfc7119f1ca4f48de3b5a37cbaee07e4fd.tar.gz
compcert-kvx-6ca9f9bfc7119f1ca4f48de3b5a37cbaee07e4fd.zip
Added base address if needed.
Ranges of locations are relative to some base address. Most times this is just the same as the compilation unit. However if the compilation unit contains functions in multiple sections we need to add a base address of the section that the locations are contained.
Diffstat (limited to 'debug')
-rw-r--r--debug/DwarfPrinter.ml45
-rw-r--r--debug/DwarfTypes.mli25
-rw-r--r--debug/Dwarfgen.ml16
3 files changed, 53 insertions, 33 deletions
diff --git a/debug/DwarfPrinter.ml b/debug/DwarfPrinter.ml
index 9a24041b..2cb8c7d9 100644
--- a/debug/DwarfPrinter.ml
+++ b/debug/DwarfPrinter.ml
@@ -602,8 +602,13 @@ module DwarfPrinter(Target: DWARF_TARGET):
print_sleb128 oc "" 0;
print_label oc debug_end (* End of the debug section *)
- let print_location_entry oc c_low l =
+ let print_location_entry oc needs_base c_low l =
print_label oc (loc_to_label l.loc_id);
+ (* If we have multiple ranges per compilation unit we need to specify a base address for the location *)
+ if needs_base then begin
+ fprintf oc " %s -1\n" address;
+ fprintf oc " %s %a\n" address label c_low;
+ end;
List.iter (fun (b,e,loc) ->
fprintf oc " %s %a-%a\n" address label b label c_low;
fprintf oc " %s %a-%a\n" address label e label c_low;
@@ -621,11 +626,11 @@ module DwarfPrinter(Target: DWARF_TARGET):
fprintf oc " %s 0\n" address
- let print_location_list oc (c_low,l) =
- let f = match c_low with
- | Some s -> print_location_entry oc s
- | None -> print_location_entry_abs oc in
- List.iter f l
+ let print_location_list oc needs_base l =
+ let f l = match l.loc_sec_begin with
+ | Some s -> print_location_entry oc needs_base s l
+ | None -> print_location_entry_abs oc l in
+ List.iter f l
let list_opt l f =
match l with
@@ -635,15 +640,15 @@ module DwarfPrinter(Target: DWARF_TARGET):
let print_diab_entries oc entries =
let abbrev_start = new_label () in
abbrev_start_addr := abbrev_start;
- List.iter (fun e -> compute_abbrev e.entry) entries;
+ List.iter (fun e -> compute_abbrev e.diab_entry) entries;
print_abbrev oc;
List.iter (fun e ->
let name = if e.section_name <> ".text" then Some e.section_name else None in
section oc (Section_debug_info name);
- print_debug_info oc e.start_label e.line_label e.entry) entries;
- if List.exists (fun e -> match e.dlocs with _,[] -> false | _,_ -> true) entries then begin
+ print_debug_info oc e.start_label e.line_label e.diab_entry) entries;
+ if List.exists (fun e -> match e.diab_locs with [] -> false | _ -> true) entries then begin
section oc Section_debug_loc;
- List.iter (fun e -> print_location_list oc e.dlocs) entries
+ List.iter (fun e -> print_location_list oc false e.diab_locs) entries
end
let print_ranges oc r =
@@ -665,8 +670,8 @@ module DwarfPrinter(Target: DWARF_TARGET):
fprintf oc " %s 0\n" address;
fprintf oc " %s 0\n" address) r
- let print_gnu_entries oc cp (lpc,loc) s r =
- compute_abbrev cp;
+ let print_gnu_entries oc entries =
+ compute_abbrev entries.gnu_entry;
let line_start = new_label ()
and start = new_label ()
and abbrev_start = new_label ()
@@ -674,18 +679,18 @@ module DwarfPrinter(Target: DWARF_TARGET):
debug_ranges_addr := range_label;
abbrev_start_addr := abbrev_start;
section oc (Section_debug_info None);
- print_debug_info oc start line_start cp;
+ print_debug_info oc start line_start entries.gnu_entry;
print_abbrev oc;
- list_opt loc (fun () ->
+ list_opt entries.gnu_locs (fun () ->
section oc Section_debug_loc;
- print_location_list oc (lpc,loc));
- list_opt r (fun () ->
- print_ranges oc r);
+ print_location_list oc entries.several_secs entries.gnu_locs);
+ list_opt entries.range_table (fun () ->
+ print_ranges oc entries.range_table);
section oc (Section_debug_line None);
print_label oc line_start;
- list_opt s (fun () ->
+ list_opt entries.string_table (fun () ->
section oc Section_debug_str;
- let s = List.sort (fun (a,_) (b,_) -> compare a b) s in
+ let s = List.sort (fun (a,_) (b,_) -> compare a b) entries.string_table in
List.iter (fun (id,s) ->
print_label oc (loc_to_label id);
fprintf oc " .asciz %S\n" s) s)
@@ -698,6 +703,6 @@ module DwarfPrinter(Target: DWARF_TARGET):
Hashtbl.clear loc_labels;
match debug with
| Diab entries -> print_diab_entries oc entries
- | Gnu (cp,loc,s,r) -> print_gnu_entries oc cp loc s r
+ | Gnu entries -> print_gnu_entries oc entries
end
diff --git a/debug/DwarfTypes.mli b/debug/DwarfTypes.mli
index 5a2bce3b..567c65cd 100644
--- a/debug/DwarfTypes.mli
+++ b/debug/DwarfTypes.mli
@@ -266,11 +266,13 @@ type dw_entry =
(* The type for the location list. *)
type location_entry =
- {
- loc: (address * address * location_value) list;
- loc_id: reference;
- }
-type dw_locations = constant option * location_entry list
+ {
+ loc: (address * address * location_value) list;
+ loc_id: reference;
+ loc_sec_begin : address option;
+ }
+
+type dw_locations = location_entry list
type range_entry =
| AddressRange of (address * address) list
@@ -285,13 +287,20 @@ type diab_entry =
section_name: string;
start_label: int;
line_label: int;
- entry: dw_entry;
- dlocs: dw_locations;
+ diab_entry: dw_entry;
+ diab_locs: dw_locations;
}
type diab_entries = diab_entry list
-type gnu_entries = dw_entry * dw_locations * dw_string * dw_ranges
+type gnu_entries =
+ {
+ string_table: dw_string;
+ range_table: dw_ranges;
+ gnu_locs: dw_locations;
+ gnu_entry: dw_entry;
+ several_secs: bool;
+ }
type debug_entries =
| Diab of diab_entries
diff --git a/debug/Dwarfgen.ml b/debug/Dwarfgen.ml
index e1b71f13..6c1d0846 100644
--- a/debug/Dwarfgen.ml
+++ b/debug/Dwarfgen.ml
@@ -408,7 +408,7 @@ module Dwarfgenaux (Target: TARGET) =
and lo = translate_label f_id lo in
hi,lo,range_entry_loc i.var_loc) l in
let id = next_id () in
- Some (LocRef id),[{loc = l;loc_id = id;}]
+ Some (LocRef id),[{loc_sec_begin = !current_section_start; loc = l;loc_id = id;}]
end
with Not_found -> None,[]
else
@@ -574,8 +574,8 @@ let diab_gen_compilation_section sec_name s defs acc =
section_name = s;
start_label = debug_start;
line_label = line_start;
- entry = cp;
- dlocs = Some low_pc,accu.locs;
+ diab_entry = cp;
+ diab_locs = accu.locs;
}::acc
let gen_diab_debug_info sec_name var_section : debug_entries =
@@ -643,6 +643,12 @@ let gen_gnu_debug_info sec_name var_section : debug_entries =
} in
let cp = new_entry (next_id ()) (DW_TAG_compile_unit cp) in
let cp = add_children cp (types@defs) in
- let loc_pc = if StringSet.cardinal sec > 1 then None else low_pc in
let string_table = Hashtbl.fold (fun s i acc -> (i,s)::acc) string_table [] in
- Gnu (cp,(loc_pc,accu.locs),string_table,snd accu.ranges)
+ let cp = {
+ string_table = string_table;
+ range_table = snd accu.ranges;
+ gnu_locs = accu.locs;
+ gnu_entry = cp;
+ several_secs = StringSet.cardinal sec > 1}
+ in
+ Gnu cp