Skip to content

Commit 0d455ea

Browse files
committed
dwarf_low/ and dwarf_high/ changes for DWARF inlined frames (PR2484)
1 parent b0fe9b0 commit 0d455ea

File tree

8 files changed

+140
-11
lines changed

8 files changed

+140
-11
lines changed

backend/debug/dwarf/dwarf_high/dwarf_attribute_helpers.ml

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,21 @@ let create_low_pc address_label =
3636
AV.create spec
3737
(V.code_address_from_label ~comment:"low PC value" address_label)
3838

39-
let create_high_pc_offset offset =
40-
match Targetint.repr offset with
41-
| Int32 offset ->
42-
let spec = AS.create High_pc Data4 in
43-
AV.create spec (V.int32 ~comment:"high PC value as offset" offset)
44-
| Int64 offset ->
45-
let spec = AS.create High_pc Data8 in
46-
AV.create spec (V.int64 ~comment:"high PC value as offset" offset)
39+
let create_low_pc_with_offset address_label ~offset_in_bytes =
40+
let spec = AS.create Low_pc Addr in
41+
AV.create spec
42+
(V.code_address_from_label_plus_offset ~comment:"low PC value" address_label
43+
~offset_in_bytes)
44+
45+
let create_high_pc_offset ~low_pc ~low_pc_offset_in_bytes ~high_pc
46+
~high_pc_offset_in_bytes =
47+
assert (Targetint.size = 64);
48+
let spec = AS.create High_pc Data8 in
49+
AV.create spec
50+
(V.distance_between_labels_64_bit_with_offsets ~upper:high_pc
51+
~upper_offset:high_pc_offset_in_bytes ~lower:low_pc
52+
~lower_offset:low_pc_offset_in_bytes ~comment:"high PC value as offset"
53+
())
4754

4855
let create_high_pc ~low_pc high_pc =
4956
match Dwarf_arch_sizes.size_addr with
@@ -131,6 +138,24 @@ let create_decl_column column =
131138
let column = Uint64.of_nonnegative_int_exn column in
132139
AV.create spec (V.uleb128 ~comment:"column number" column)
133140

141+
let create_call_file file =
142+
let spec = AS.create Call_file Udata in
143+
let file = Uint64.of_nonnegative_int_exn file in
144+
AV.create spec (V.uleb128 ~comment:"file number" file)
145+
146+
let create_call_line line =
147+
let spec = AS.create Call_line Udata in
148+
let line = Uint64.of_nonnegative_int_exn line in
149+
AV.create spec (V.uleb128 ~comment:"line number" line)
150+
151+
let create_call_column column =
152+
(* CR mshinwell: Check whether "call_file", "call_line" and "call_column" are
153+
indeed supported pre DWARF 5. The gdb manual suggests that they've been
154+
around since DWARF 2. *)
155+
let spec = AS.create Call_column Udata in
156+
let column = Uint64.of_nonnegative_int_exn column in
157+
AV.create spec (V.uleb128 ~comment:"column number" column)
158+
134159
let create_call_pc label =
135160
let spec = AS.create Call_pc Addr in
136161
needs_dwarf_five ();

backend/debug/dwarf/dwarf_high/dwarf_attribute_helpers.mli

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,19 @@ val create_entry_pc : Asm_label.t -> Dwarf_attribute_values.Attribute_value.t
2222

2323
val create_low_pc : Asm_label.t -> Dwarf_attribute_values.Attribute_value.t
2424

25+
val create_low_pc_with_offset :
26+
Asm_label.t ->
27+
offset_in_bytes:Targetint.t ->
28+
Dwarf_attribute_values.Attribute_value.t
29+
2530
(** Creates a [DW_AT_high_pc] attribute value by taking the offset in bytes from
2631
the [DW_AT_low_pc] attribute value. *)
2732
val create_high_pc_offset :
28-
Targetint.t -> Dwarf_attribute_values.Attribute_value.t
33+
low_pc:Asm_label.t ->
34+
low_pc_offset_in_bytes:Targetint.t ->
35+
high_pc:Asm_label.t ->
36+
high_pc_offset_in_bytes:Targetint.t ->
37+
Dwarf_attribute_values.Attribute_value.t
2938

3039
val create_high_pc :
3140
low_pc:Asm_symbol.t -> Asm_label.t -> Dwarf_attribute_values.Attribute_value.t
@@ -63,6 +72,12 @@ val create_decl_line : int -> Dwarf_attribute_values.Attribute_value.t
6372

6473
val create_decl_column : int -> Dwarf_attribute_values.Attribute_value.t
6574

75+
val create_call_file : int -> Dwarf_attribute_values.Attribute_value.t
76+
77+
val create_call_line : int -> Dwarf_attribute_values.Attribute_value.t
78+
79+
val create_call_column : int -> Dwarf_attribute_values.Attribute_value.t
80+
6681
val create_call_pc : Asm_label.t -> Dwarf_attribute_values.Attribute_value.t
6782

6883
val create_call_return_pc :

backend/debug/dwarf/dwarf_high/proto_die.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ type t =
3939
location_list_in_debug_loc_table : Dwarf_4_location_list.t option
4040
}
4141

42+
let equal t1 t2 = t1 == t2
43+
4244
let attribute_values_map attribute_values =
4345
List.fold_left
4446
(fun map attribute_value ->
@@ -100,6 +102,10 @@ let add_or_replace_attribute_value t attribute_value =
100102
in
101103
t.attribute_values <- attribute_values
102104

105+
let replace_all_attribute_values t attribute_values =
106+
let attribute_values = attribute_values_map attribute_values in
107+
{ t with attribute_values }
108+
103109
let set_name t name = t.name <- Some name
104110

105111
type fold_arg =

backend/debug/dwarf/dwarf_high/proto_die.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ val create_ignore :
5959
val add_or_replace_attribute_value :
6060
t -> Dwarf_attribute_values.Attribute_value.t -> unit
6161

62+
val replace_all_attribute_values :
63+
t -> Dwarf_attribute_values.Attribute_value.t list -> t
64+
6265
(* CR-someday mshinwell: add a [name] argument to the creation functions *)
6366
val set_name : t -> Asm_symbol.t -> unit
6467

@@ -102,3 +105,5 @@ val depth_first_fold : t -> init:'a -> f:('a -> fold_arg -> 'a) -> 'a
102105
suppresses a complaint from objdump "Location lists in .debug_loc start at
103106
...". *)
104107
val location_list_in_debug_loc_table : t -> Dwarf_4_location_list.t option
108+
109+
val equal : t -> t -> bool

backend/debug/dwarf/dwarf_low/dwarf_attribute_values.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ module Value = struct
6060
let distance_between_labels_64_bit ?comment ~upper ~lower () =
6161
Dwarf_value (V.distance_between_labels_64_bit ?comment ~upper ~lower ())
6262

63+
let distance_between_labels_64_bit_with_offsets ?comment ~upper ~upper_offset
64+
~lower ~lower_offset () =
65+
Dwarf_value
66+
(V.distance_between_labels_64_bit_with_offsets ?comment ~upper
67+
~upper_offset ~lower ~lower_offset ())
68+
6369
let distance_between_label_and_symbol_32_bit ?comment ~upper ~lower () =
6470
assert (Dwarf_arch_sizes.size_addr = 4);
6571
Dwarf_value
@@ -75,6 +81,10 @@ module Value = struct
7581
let code_address_from_label ?comment lbl =
7682
Dwarf_value (V.code_address_from_label ?comment lbl)
7783

84+
let code_address_from_label_plus_offset ?comment lbl ~offset_in_bytes =
85+
Dwarf_value
86+
(V.code_address_from_label_plus_offset ?comment lbl ~offset_in_bytes)
87+
7888
let code_address_from_symbol ?comment sym =
7989
Dwarf_value (V.code_address_from_symbol ?comment sym)
8090

backend/debug/dwarf/dwarf_low/dwarf_attribute_values.mli

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ module Value : sig
7070
unit ->
7171
Dwarf_attributes.Form.data8 t
7272

73+
val distance_between_labels_64_bit_with_offsets :
74+
?comment:string ->
75+
upper:Asm_label.t ->
76+
upper_offset:Targetint.t ->
77+
lower:Asm_label.t ->
78+
lower_offset:Targetint.t ->
79+
unit ->
80+
Dwarf_attributes.Form.data8 t
81+
7382
val distance_between_label_and_symbol_32_bit :
7483
?comment:string ->
7584
upper:Asm_label.t ->
@@ -87,6 +96,12 @@ module Value : sig
8796
val code_address_from_label :
8897
?comment:string -> Asm_label.t -> Dwarf_attributes.Form.addr t
8998

99+
val code_address_from_label_plus_offset :
100+
?comment:string ->
101+
Asm_label.t ->
102+
offset_in_bytes:Targetint.t ->
103+
Dwarf_attributes.Form.addr t
104+
90105
val code_address_from_symbol :
91106
?comment:string -> Asm_symbol.t -> Dwarf_attributes.Form.addr t
92107

backend/debug/dwarf/dwarf_low/dwarf_value.ml

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ type value =
4444
| Indirect_string of string
4545
| Absolute_address of Targetint.t
4646
| Code_address_from_label of Asm_label.t
47+
| Code_address_from_label_plus_offset of
48+
{ label : Asm_label.t;
49+
offset_in_bytes : Targetint.t
50+
}
4751
| Code_address_from_symbol of Asm_symbol.t
4852
| Code_address_from_label_symbol_diff of
4953
{ upper : Asm_label.t;
@@ -80,6 +84,12 @@ type value =
8084
{ upper : Asm_label.t;
8185
lower : Asm_label.t
8286
}
87+
| Distance_between_labels_64_bit_with_offsets of
88+
{ upper : Asm_label.t;
89+
upper_offset : Targetint.t;
90+
lower : Asm_label.t;
91+
lower_offset : Targetint.t
92+
}
8393

8494
type t =
8595
{ value : value;
@@ -105,6 +115,10 @@ let print ppf { value; comment = _ } =
105115
| Absolute_address addr ->
106116
Format.fprintf ppf "0x%Lx" (Targetint.to_int64 addr)
107117
| Code_address_from_label lbl -> Asm_label.print ppf lbl
118+
| Code_address_from_label_plus_offset
119+
{ label : Asm_label.t; offset_in_bytes : Targetint.t } ->
120+
Format.fprintf ppf "%a + %a" Asm_label.print label Targetint.print
121+
offset_in_bytes
108122
| Code_address_from_symbol sym -> Asm_symbol.print ppf sym
109123
| Code_address_from_label_symbol_diff { upper; lower; offset_upper } ->
110124
Format.fprintf ppf "(%a + %a) - %a" Asm_label.print upper Targetint.print
@@ -143,6 +157,11 @@ let print ppf { value; comment = _ } =
143157
| Distance_between_labels_64_bit { upper; lower } ->
144158
Format.fprintf ppf "%a - %a (64)" Asm_label.print upper Asm_label.print
145159
lower
160+
| Distance_between_labels_64_bit_with_offsets
161+
{ upper; upper_offset; lower; lower_offset } ->
162+
Format.fprintf ppf "(%a + %a) - (%a + %a) (64)" Asm_label.print upper
163+
Targetint.print upper_offset Asm_label.print lower Targetint.print
164+
lower_offset
146165

147166
let flag_true ?comment () = { value = Flag_true; comment }
148167

@@ -177,6 +196,11 @@ let absolute_address ?comment addr = { value = Absolute_address addr; comment }
177196
let code_address_from_label ?comment lbl =
178197
{ value = Code_address_from_label lbl; comment }
179198

199+
let code_address_from_label_plus_offset ?comment label ~offset_in_bytes =
200+
{ value = Code_address_from_label_plus_offset { label; offset_in_bytes };
201+
comment
202+
}
203+
180204
let code_address_from_symbol ?comment sym =
181205
{ value = Code_address_from_symbol sym; comment }
182206

@@ -233,6 +257,14 @@ let distance_between_labels_32_bit ?comment ~upper ~lower () =
233257
let distance_between_labels_64_bit ?comment ~upper ~lower () =
234258
{ value = Distance_between_labels_64_bit { upper; lower }; comment }
235259

260+
let distance_between_labels_64_bit_with_offsets ?comment ~upper ~upper_offset
261+
~lower ~lower_offset () =
262+
{ value =
263+
Distance_between_labels_64_bit_with_offsets
264+
{ upper; upper_offset; lower; lower_offset };
265+
comment
266+
}
267+
236268
let append_to_comment { value; comment } to_append =
237269
let comment =
238270
match comment with
@@ -271,7 +303,8 @@ let size { value; comment = _ } =
271303
| Int64 _ | Uint64 _ -> Dwarf_int.eight ()
272304
| Uleb128 i -> uleb128_size i
273305
| Sleb128 i -> sleb128_size i
274-
| Absolute_address _ | Code_address_from_label _ | Code_address_from_symbol _
306+
| Absolute_address _ | Code_address_from_label _
307+
| Code_address_from_label_plus_offset _ | Code_address_from_symbol _
275308
| Code_address_from_label_symbol_diff _ | Code_address_from_symbol_diff _
276309
| Code_address_from_symbol_plus_bytes _ -> (
277310
match Targetint.size with
@@ -289,7 +322,9 @@ let size { value; comment = _ } =
289322
Dwarf_int.size (Dwarf_int.zero ())
290323
| Distance_between_labels_16_bit _ -> Dwarf_int.two ()
291324
| Distance_between_labels_32_bit _ -> Dwarf_int.four ()
292-
| Distance_between_labels_64_bit _ -> Dwarf_int.eight ()
325+
| Distance_between_labels_64_bit _
326+
| Distance_between_labels_64_bit_with_offsets _ ->
327+
Dwarf_int.eight ()
293328

294329
let emit ~asm_directives { value; comment } =
295330
let module A = (val asm_directives : Asm_directives.S) in
@@ -331,6 +366,8 @@ let emit ~asm_directives { value; comment } =
331366
A.comment abbrev
332367
| Absolute_address addr -> A.targetint ?comment addr
333368
| Code_address_from_label lbl -> A.label ?comment lbl
369+
| Code_address_from_label_plus_offset { label; offset_in_bytes } ->
370+
A.label_plus_offset ?comment label ~offset_in_bytes
334371
| Code_address_from_symbol sym -> A.symbol ?comment sym
335372
| Code_address_from_label_symbol_diff { upper; lower; offset_upper } ->
336373
A.between_symbol_in_current_unit_and_label_offset ?comment ~upper ~lower
@@ -377,3 +414,7 @@ let emit ~asm_directives { value; comment } =
377414
A.between_labels_32_bit ?comment ~upper ~lower ()
378415
| Distance_between_labels_64_bit { upper; lower } ->
379416
A.between_labels_64_bit ?comment ~upper ~lower ()
417+
| Distance_between_labels_64_bit_with_offsets
418+
{ upper; upper_offset; lower; lower_offset } ->
419+
A.between_labels_64_bit_with_offsets ?comment ~upper ~upper_offset ~lower
420+
~lower_offset ()

backend/debug/dwarf/dwarf_low/dwarf_value.mli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ val absolute_address : ?comment:string -> Targetint.t -> t
5353

5454
val code_address_from_label : ?comment:string -> Asm_label.t -> t
5555

56+
val code_address_from_label_plus_offset :
57+
?comment:string -> Asm_label.t -> offset_in_bytes:Targetint.t -> t
58+
5659
val code_address_from_symbol : ?comment:string -> Asm_symbol.t -> t
5760

5861
(* CR mshinwell: This doesn't form a code address. *)
@@ -105,6 +108,15 @@ val distance_between_labels_32_bit :
105108
val distance_between_labels_64_bit :
106109
?comment:string -> upper:Asm_label.t -> lower:Asm_label.t -> unit -> t
107110

111+
val distance_between_labels_64_bit_with_offsets :
112+
?comment:string ->
113+
upper:Asm_label.t ->
114+
upper_offset:Targetint.t ->
115+
lower:Asm_label.t ->
116+
lower_offset:Targetint.t ->
117+
unit ->
118+
t
119+
108120
val append_to_comment : t -> string -> t
109121

110122
val print : Format.formatter -> t -> unit

0 commit comments

Comments
 (0)