1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175

(* pseudo-tags

There can be several abbreviated DW_TAGs in the
abbreviation table, each with a different attribute set.

To refer to the duplicated tags, we use the bits above
the 16 bits that are possible for DW_TAGs.

A regular tag is just a pseudo-tag with an ordinal of 0.

 *)

let pseudo_tag base ordinal =
  assert (base > 0 && base <= Dwarf5.dw_TAG_hi_user);
  base lor (ordinal lsl 16)

let dw_TAG_member_Pointer_mark = pseudo_tag Dwarf5.dw_TAG_member 1
let dw_TAG_member_Word_sized_typed = pseudo_tag Dwarf5.dw_TAG_member 2
let dw_TAG_member_Tag_mark = pseudo_tag Dwarf5.dw_TAG_member 3
let dw_TAG_member_Variant_mark = pseudo_tag Dwarf5.dw_TAG_member 4
let dw_TAG_member_In_variant = pseudo_tag Dwarf5.dw_TAG_member 5

let dw_TAG_base_type_Anon = pseudo_tag Dwarf5.dw_TAG_base_type 1
let dw_TAG_base_type_Unsigned_Anon = pseudo_tag Dwarf5.dw_TAG_base_type 2
let dw_TAG_base_type_Unsigned_Bytes_Anon = pseudo_tag Dwarf5.dw_TAG_base_type 3

let dw_TAG_variant_Named = pseudo_tag Dwarf5.dw_TAG_variant 1

let dw_TAG_subprogram_Ret = pseudo_tag Dwarf5.dw_TAG_subprogram 1

type dw_tag_id = int
type dw_bool = int
type dw_attr_id = int
type dw_form = int

type tag_to_contents_assoc = (dw_tag_id * dw_bool * (dw_attr_id * dw_form) list) list

(* The following data associates the expected attribute sequence
   (each with encoding form) and whether it is hierarchic with
   each used tag identifier. It corresponds to the `.debug_abbrev`
   section. *)
let abbreviations : tag_to_contents_assoc =
  let open Dwarf5 in
  [ ( dw_TAG_compile_unit, dw_CHILDREN_yes,
      [ dw_AT_producer, dw_FORM_strp;
        dw_AT_language, dw_FORM_data2;
        dw_AT_name, dw_FORM_strp;
        dw_AT_stmt_list, dw_FORM_sec_offset;
        dw_AT_comp_dir, dw_FORM_strp;
        dw_AT_use_UTF8, dw_FORM_flag_present;
        dw_AT_low_pc, dw_FORM_addr; (* TODO: dw_FORM_addrx? *)
        dw_AT_addr_base, dw_FORM_sec_offset;
        dw_AT_ranges, dw_FORM_sec_offset
      ] );
    ( dw_TAG_subprogram, dw_CHILDREN_yes,
      [ dw_AT_low_pc, dw_FORM_addrx;
        dw_AT_high_pc, dw_FORM_data4(*FIXME*);
         (* dw_AT_GNU_all_call_sites, dw_FORM_flag_present; *)
        dw_AT_name, dw_FORM_strp;
        dw_AT_decl_file, dw_FORM_data1(*FIXME*);
        dw_AT_decl_line, dw_FORM_data1(*FIXME*);
        dw_AT_decl_column, dw_FORM_data1(*FIXME*);
        dw_AT_prototyped, dw_FORM_flag_present;
        dw_AT_external, dw_FORM_flag(*_present*)
      ] );
    ( dw_TAG_subprogram_Ret, dw_CHILDREN_yes,
      [ dw_AT_low_pc, dw_FORM_addrx;
        dw_AT_high_pc, dw_FORM_data4(*FIXME*);
         (* dw_AT_GNU_all_call_sites, dw_FORM_flag_present; *)
        dw_AT_name, dw_FORM_strp;
        dw_AT_type, dw_FORM_ref_udata;
        dw_AT_decl_file, dw_FORM_data1(*FIXME*);
        dw_AT_decl_line, dw_FORM_data1(*FIXME*);
        dw_AT_decl_column, dw_FORM_data1(*FIXME*);
        dw_AT_prototyped, dw_FORM_flag_present;
        dw_AT_external, dw_FORM_flag(*_present*)
      ] );
    ( dw_TAG_formal_parameter, dw_CHILDREN_no,
      [ dw_AT_name, dw_FORM_strp;
        dw_AT_decl_line, dw_FORM_data1;
        dw_AT_decl_column, dw_FORM_data1;
        dw_AT_type, dw_FORM_ref_udata;
        dw_AT_location, dw_FORM_exprloc
      ] );
    ( dw_TAG_lexical_block, dw_CHILDREN_yes,
      [ dw_AT_low_pc, dw_FORM_addr; (* filled-in by tag open *)
        dw_AT_decl_line, dw_FORM_data1(*FIXME*);
        dw_AT_decl_column, dw_FORM_data1(*FIXME*);
        dw_AT_high_pc, dw_FORM_addr (* filled-in by tag close *)
      ] );
    ( dw_TAG_variable, dw_CHILDREN_no,
      [ dw_AT_name, dw_FORM_strp;
        dw_AT_decl_line, dw_FORM_data1;
        dw_AT_decl_column, dw_FORM_data1;
        dw_AT_type, dw_FORM_ref_udata;
        dw_AT_location, dw_FORM_exprloc
      ] );
    ( dw_TAG_typedef, dw_CHILDREN_no,
      [ dw_AT_name, dw_FORM_strp;
        dw_AT_type, dw_FORM_ref4
      ] );
    ( dw_TAG_base_type, dw_CHILDREN_no,
      [ dw_AT_name, dw_FORM_strp;
        dw_AT_bit_size, dw_FORM_data1;
        dw_AT_data_bit_offset, dw_FORM_data1;
        dw_AT_encoding, dw_FORM_data1
      ] );
    ( dw_TAG_base_type_Anon, dw_CHILDREN_no,
      [ dw_AT_bit_size, dw_FORM_data1;
        dw_AT_data_bit_offset, dw_FORM_data1
      ] );
    ( dw_TAG_base_type_Unsigned_Anon, dw_CHILDREN_no,
      [ dw_AT_bit_size, dw_FORM_data1;
        dw_AT_data_bit_offset, dw_FORM_data1;
        dw_AT_encoding, dw_FORM_data1
      ] );
    ( dw_TAG_base_type_Unsigned_Bytes_Anon, dw_CHILDREN_no,
      [ dw_AT_byte_size, dw_FORM_data1;
        dw_AT_encoding, dw_FORM_data1
      ] );
    ( dw_TAG_pointer_type, dw_CHILDREN_no, (* TODO: use dw_TAG_reference_type *)
      [ dw_AT_type, dw_FORM_ref_udata
      ] );
    ( dw_TAG_reference_type, dw_CHILDREN_no, (* TODO: BETTER: DW_TAG_rvalue_reference_type *)
      [ dw_AT_type, dw_FORM_ref_udata
      ] );
    ( dw_TAG_structure_type, dw_CHILDREN_yes,
      [ dw_AT_name, dw_FORM_strp;
        dw_AT_byte_size, dw_FORM_data1
      ] );
    ( dw_TAG_member_Pointer_mark, dw_CHILDREN_no,
      [ dw_AT_name, dw_FORM_strp;
        dw_AT_type, dw_FORM_ref_udata;
        dw_AT_artificial, dw_FORM_flag_present;
        dw_AT_bit_size, dw_FORM_data1;
        dw_AT_data_bit_offset, dw_FORM_data1
      ] );
    ( dw_TAG_member_Tag_mark, dw_CHILDREN_no,
      [ dw_AT_artificial, dw_FORM_flag_present;
        dw_AT_byte_size, dw_FORM_data1
      ] );
    ( dw_TAG_member_Variant_mark, dw_CHILDREN_no,
      [ dw_AT_artificial, dw_FORM_flag_present;
        dw_AT_byte_size, dw_FORM_data1;
        dw_AT_data_member_location, dw_FORM_data1
      ] );
    ( dw_TAG_member_Word_sized_typed, dw_CHILDREN_no,
      [ dw_AT_name, dw_FORM_strp;
        dw_AT_type, dw_FORM_ref_udata;
        dw_AT_byte_size, dw_FORM_data1
      ] );
    ( dw_TAG_member_In_variant, dw_CHILDREN_no,
      [ dw_AT_name, dw_FORM_strp;
        dw_AT_type, dw_FORM_ref_udata;
        dw_AT_data_member_location, dw_FORM_data1
      ] );
    ( dw_TAG_variant_part, dw_CHILDREN_yes,
      [ dw_AT_discr, dw_FORM_ref_udata
      ] );
    ( dw_TAG_variant, dw_CHILDREN_yes,
      [ dw_AT_discr_value, dw_FORM_data1
      ] );
    ( dw_TAG_variant_Named, dw_CHILDREN_yes,
      [ dw_AT_name, dw_FORM_strp;
        dw_AT_discr_value, dw_FORM_data4
      ] );
    ( dw_TAG_enumeration_type, dw_CHILDREN_yes,
      [ dw_AT_artificial, dw_FORM_flag_present (* to avoid elimination *)
      ] );
    ( dw_TAG_enumerator, dw_CHILDREN_no,
      [ dw_AT_name, dw_FORM_strp;
        dw_AT_const_value, dw_FORM_data4
      ] )
  ]