1 #ifndef R2_BIN_DWARF_H
2 #define R2_BIN_DWARF_H
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #define DW_EXTENDED_OPCODE 0
9 #define LOP_EXTENDED 1
10 #define LOP_DISCARD  2
11 #define LOP_STANDARD 3
12 #define LOP_SPECIAL  4
13 
14 #define DW_LNS_copy                     0x01
15 #define DW_LNS_advance_pc               0x02
16 #define DW_LNS_advance_line             0x03
17 #define DW_LNS_set_file                 0x04
18 #define DW_LNS_set_column               0x05
19 #define DW_LNS_negate_stmt              0x06
20 #define DW_LNS_set_basic_block          0x07
21 #define DW_LNS_const_add_pc             0x08
22 #define DW_LNS_fixed_advance_pc         0x09
23 #define DW_LNS_set_prologue_end         0x0a /* DWARF3 */
24 #define DW_LNS_set_epilogue_begin       0x0b /* DWARF3 */
25 #define DW_LNS_set_isa                  0x0c /* DWARF3 */
26 /* Line number extended opcode name. */
27 #define DW_LNE_end_sequence             0x01
28 #define DW_LNE_set_address              0x02
29 #define DW_LNE_define_file              0x03
30 #define DW_LNE_set_discriminator        0x04  /* DWARF4 */
31 #define DW_LNE_lo_user                  0x80
32 #define DW_LNE_hi_user                  0xff
33 
34 /* HP extensions. */
35 #define DW_LNE_HP_negate_is_UV_update       0x11 /* 17 HP */
36 #define DW_LNE_HP_push_context              0x12 /* 18 HP */
37 #define DW_LNE_HP_pop_context               0x13 /* 19 HP */
38 #define DW_LNE_HP_set_file_line_column      0x14 /* 20 HP */
39 #define DW_LNE_HP_set_routine_name          0x15 /* 21 HP */
40 #define DW_LNE_HP_set_sequence              0x16 /* 22 HP */
41 #define DW_LNE_HP_negate_post_semantics     0x17 /* 23 HP */
42 #define DW_LNE_HP_negate_function_exit      0x18 /* 24 HP */
43 #define DW_LNE_HP_negate_front_end_logical  0x19 /* 25 HP */
44 #define DW_LNE_HP_define_proc               0x20 /* 32 HP */
45 
46 #define DW_LNE_lo_user                  0x80 /* DWARF3 */
47 #define DW_LNE_hi_user                  0xff /* DWARF3 */
48 
49 /* debug_info tags */
50 // this is not a real dwarf named entry, but I wanted to give it
51 // a name so it's more obvious and readable that it's just a type of entry
52 #define DW_TAG_null_entry               0x00
53 #define DW_TAG_array_type               0x01
54 #define DW_TAG_class_type               0x02
55 #define DW_TAG_entry_point              0x03
56 #define DW_TAG_enumeration_type         0x04
57 #define DW_TAG_formal_parameter         0x05
58 #define DW_TAG_imported_declaration     0x08
59 #define DW_TAG_label                    0x0a
60 #define DW_TAG_lexical_block            0x0b
61 #define DW_TAG_member                   0x0d
62 #define DW_TAG_pointer_type             0x0f
63 #define DW_TAG_reference_type           0x10
64 #define DW_TAG_compile_unit             0x11 //
65 #define DW_TAG_string_type              0x12
66 #define DW_TAG_structure_type           0x13
67 #define DW_TAG_subroutine_type          0x15
68 #define DW_TAG_typedef                  0x16
69 #define DW_TAG_union_type               0x17
70 #define DW_TAG_unspecified_parameters   0x18
71 #define DW_TAG_variant                  0x19
72 #define DW_TAG_common_block             0x1a
73 #define DW_TAG_common_inclusion         0x1b
74 #define DW_TAG_inheritance              0x1c
75 #define DW_TAG_inlined_subroutine       0x1d
76 #define DW_TAG_module                   0x1e
77 #define DW_TAG_ptr_to_member_type       0x1f
78 #define DW_TAG_set_type                 0x20
79 #define DW_TAG_subrange_type            0x21
80 #define DW_TAG_with_stmt                0x22
81 #define DW_TAG_access_declaration       0x23
82 #define DW_TAG_base_type                0x24
83 #define DW_TAG_catch_block              0x25
84 #define DW_TAG_const_type               0x26
85 #define DW_TAG_constant                 0x27
86 #define DW_TAG_enumerator               0x28
87 #define DW_TAG_file_type                0x29
88 #define DW_TAG_friend                   0x2a
89 #define DW_TAG_namelist                 0x2b
90         /*  Early releases of this header had the following
91             misspelled with a trailing 's' */
92 #define DW_TAG_namelist_item            0x2c /* DWARF3/2 spelling */
93 #define DW_TAG_namelist_items           0x2c /* SGI misspelling/typo */
94 #define DW_TAG_packed_type              0x2d
95 #define DW_TAG_subprogram               0x2e
96         /*  The DWARF2 document had two spellings of the following
97             two TAGs, DWARF3 specifies the longer spelling. */
98 #define DW_TAG_template_type_parameter  0x2f /* DWARF3/2 spelling*/
99 #define DW_TAG_template_type_param      0x2f /* DWARF2   spelling*/
100 #define DW_TAG_template_value_parameter 0x30 /* DWARF3/2 spelling*/
101 #define DW_TAG_template_value_param     0x30 /* DWARF2   spelling*/
102 #define DW_TAG_thrown_type              0x31
103 #define DW_TAG_try_block                0x32
104 #define DW_TAG_variant_part             0x33
105 #define DW_TAG_variable                 0x34
106 #define DW_TAG_volatile_type            0x35
107 #define DW_TAG_dwarf_procedure          0x36  /* DWARF3 */
108 #define DW_TAG_restrict_type            0x37  /* DWARF3 */
109 #define DW_TAG_interface_type           0x38  /* DWARF3 */
110 #define DW_TAG_namespace                0x39  /* DWARF3 */
111 #define DW_TAG_imported_module          0x3a  /* DWARF3 */
112 #define DW_TAG_unspecified_type         0x3b  /* DWARF3 */
113 #define DW_TAG_partial_unit             0x3c  /* DWARF3 */
114 #define DW_TAG_imported_unit            0x3d  /* DWARF3 */
115         /*  Do not use DW_TAG_mutable_type */
116 #define DW_TAG_mutable_type 			0x3e /* Withdrawn from DWARF3 by DWARF3f. */
117 #define DW_TAG_condition                0x3f  /* DWARF3f */
118 #define DW_TAG_shared_type              0x40  /* DWARF3f */
119 #define DW_TAG_type_unit                0x41  /* DWARF4 */
120 #define DW_TAG_rvalue_reference_type    0x42  /* DWARF4 */
121 #define DW_TAG_template_alias           0x43  /* DWARF4 */
122 
123 #define DW_TAG_LAST                     0x44  // correct ?
124 /* <_lo_user ; _hi_user> Interval is reserved for vendor extensions */
125 #define DW_TAG_lo_user                  0x4080
126 #define DW_TAG_hi_user                  0xffff
127 
128 #define DW_CHILDREN_no                  0x00
129 #define DW_CHILDREN_yes                 0x01
130 
131 #define DW_AT_sibling                   0x01
132 #define DW_AT_location                  0x02
133 #define DW_AT_name                      0x03
134 #define DW_AT_ordering                  0x09
135 #define DW_AT_byte_size                 0x0b
136 #define DW_AT_bit_offset                0x0c
137 #define DW_AT_bit_size                  0x0d
138 #define DW_AT_stmt_list                 0x10
139 #define DW_AT_low_pc                    0x11
140 #define DW_AT_high_pc                   0x12
141 #define DW_AT_language                  0x13
142 #define DW_AT_discr                     0x15
143 #define DW_AT_discr_value               0x16
144 #define DW_AT_visibility                0x17
145 #define DW_AT_import                    0x18
146 #define DW_AT_string_length             0x19
147 #define DW_AT_common_reference          0x1a
148 #define DW_AT_comp_dir                  0x1b
149 #define DW_AT_const_value               0x1c
150 #define DW_AT_containing_type           0x1d
151 #define DW_AT_default_value             0x1e
152 #define DW_AT_inline                    0x20
153 #define DW_AT_is_optional               0x21
154 #define DW_AT_lower_bound               0x22
155 #define DW_AT_producer                  0x25
156 #define DW_AT_prototyped                0x27
157 #define DW_AT_return_addr               0x2a
158 #define DW_AT_start_scope               0x2c
159 #define DW_AT_stride_size               0x2e
160 #define DW_AT_upper_bound               0x2f
161 #define DW_AT_abstract_origin           0x31
162 #define DW_AT_accessibility             0x32
163 #define DW_AT_address_class             0x33
164 #define DW_AT_artificial                0x34
165 #define DW_AT_base_types                0x35
166 #define DW_AT_calling_convention        0x36
167 #define DW_AT_count                     0x37
168 #define DW_AT_data_member_location      0x38
169 #define DW_AT_decl_column               0x39
170 #define DW_AT_decl_file                 0x3a
171 #define DW_AT_decl_line                 0x3b
172 #define DW_AT_declaration               0x3c
173 #define DW_AT_discr_list                0x3d
174 #define DW_AT_encoding                  0x3e
175 #define DW_AT_external                  0x3f
176 #define DW_AT_frame_base                0x40
177 #define DW_AT_friend                    0x41
178 #define DW_AT_identifier_case           0x42
179 #define DW_AT_macro_info                0x43
180 #define DW_AT_namelist_item             0x44
181 #define DW_AT_priority                  0x45
182 #define DW_AT_segment                   0x46
183 #define DW_AT_specification             0x47
184 #define DW_AT_static_link               0x48
185 #define DW_AT_type                      0x49
186 #define DW_AT_use_location              0x4a
187 #define DW_AT_variable_parameter        0x4b
188 #define DW_AT_virtuality                0x4c
189 #define DW_AT_vtable_elem_location      0x4d
190 #define DW_AT_allocated                 0x4e // DWARF 3 additions start
191 #define DW_AT_associated                0x4f
192 #define DW_AT_data_location             0x50
193 #define DW_AT_byte_stride               0x51
194 #define DW_AT_entry_pc                  0x52
195 #define DW_AT_use_UTF8                  0x53
196 #define DW_AT_extension                 0x54
197 #define DW_AT_ranges                    0x55
198 #define DW_AT_trampoline                0x56
199 #define DW_AT_call_column               0x57
200 #define DW_AT_call_file                 0x58
201 #define DW_AT_call_line                 0x59
202 #define DW_AT_description               0x5a
203 #define DW_AT_binary_scale              0x5b
204 #define DW_AT_decimal_scale             0x5c
205 #define DW_AT_small                     0x5d
206 #define DW_AT_decimal_sign              0x5e
207 #define DW_AT_digit_count               0x5f
208 #define DW_AT_picture_string            0x60
209 #define DW_AT_mutable                   0x61
210 #define DW_AT_threads_scaled            0x62
211 #define DW_AT_explicit                  0x63
212 #define DW_AT_object_pointer            0x64
213 #define DW_AT_endianity                 0x65
214 #define DW_AT_elemental                 0x66
215 #define DW_AT_pure                      0x67
216 #define DW_AT_recursive                 0x68 // DWARF 3 additions end
217 #define DW_AT_signature                 0x69
218 #define DW_AT_main_subprogram           0x6a
219 #define DW_AT_data_bit_offset           0x6b
220 #define DW_AT_const_expr                0x6c
221 #define DW_AT_enum_class                0x6d
222 #define DW_AT_linkage_name              0x6e
223 
224 #define DW_AT_string_length_bit_size    0x6f
225 #define DW_AT_string_length_byte_size   0x70
226 #define DW_AT_rank                      0x71
227 #define DW_AT_str_offsets_base          0x72
228 #define DW_AT_addr_base                 0x73
229 #define DW_AT_rnglists_base             0x74
230 // #define Reserved 0x75 Unused
231 #define DW_AT_dwo_name                  0x76
232 #define DW_AT_reference                 0x77
233 #define DW_AT_rvalue_reference          0x78
234 #define DW_AT_macros                    0x79
235 #define DW_AT_call_all_calls            0x7a
236 #define DW_AT_call_all_source_calls     0x7b
237 #define DW_AT_call_all_tail_calls       0x7c
238 #define DW_AT_call_return_pc            0x7d
239 #define DW_AT_call_value                0x7e
240 #define DW_AT_call_origin               0x7f
241 #define DW_AT_call_parameter            0x80
242 #define DW_AT_call_pc                   0x81
243 #define DW_AT_call_tail_call            0x82
244 #define DW_AT_call_target               0x83
245 #define DW_AT_call_target_clobbered     0x84
246 #define DW_AT_call_data_location        0x85
247 #define DW_AT_call_data_value           0x86
248 #define DW_AT_noreturn                  0x87
249 #define DW_AT_alignment                 0x88
250 #define DW_AT_export_symbols            0x89
251 #define DW_AT_deleted                   0x8a
252 #define DW_AT_defaulted                 0x8b
253 #define DW_AT_loclists_base             0x8c
254 
255 /* <_lo_user ; _hi_user> Interval is reserved for vendor extensions */
256 #define DW_AT_lo_user                   0x2000
257 // extensions:
258 #define DW_AT_MIPS_linkage_name         0x2007 // Same as DWARF4 DW_AT_linkage_name
259 #define DW_AT_GNU_call_site_value       0x2111
260 #define DW_AT_GNU_call_site_data_value  0x2112
261 #define DW_AT_GNU_call_site_target      0x2113
262 #define DW_AT_GNU_call_site_target_clobbered   0x2114
263 #define DW_AT_GNU_tail_call             0x2115
264 #define DW_AT_GNU_all_tail_call_sites   0x2116
265 #define DW_AT_GNU_all_call_sites        0x2117
266 #define DW_AT_GNU_all_source_call_sites 0x2118
267 #define DW_AT_GNU_macros                0x2119
268 #define DW_AT_GNU_deleted               0x211a
269 #define DW_AT_GNU_dwo_name              0x2130
270 #define DW_AT_GNU_dwo_id                0x2131
271 #define DW_AT_GNU_ranges_base           0x2132
272 #define DW_AT_GNU_addr_base             0x2133
273 #define DW_AT_GNU_pubnames              0x2134
274 #define DW_AT_GNU_pubtypes              0x2135
275 #define DW_AT_hi_user                   0x3fff
276 
277 #define DW_FORM_addr                    0x01
278 #define DW_FORM_block2                  0x03
279 #define DW_FORM_block4                  0x04
280 #define DW_FORM_data2                   0x05
281 #define DW_FORM_data4                   0x06
282 #define DW_FORM_data8                   0x07
283 #define DW_FORM_string                  0x08
284 #define DW_FORM_block                   0x09
285 #define DW_FORM_block1                  0x0a
286 #define DW_FORM_data1                   0x0b
287 #define DW_FORM_flag                    0x0c
288 #define DW_FORM_sdata                   0x0d
289 #define DW_FORM_strp                    0x0e
290 #define DW_FORM_udata                   0x0f
291 #define DW_FORM_ref_addr                0x10
292 #define DW_FORM_ref1                    0x11
293 #define DW_FORM_ref2                    0x12
294 #define DW_FORM_ref4                    0x13
295 #define DW_FORM_ref8                    0x14
296 #define DW_FORM_ref_udata               0x15
297 #define DW_FORM_indirect                0x16
298 #define DW_FORM_sec_offset              0x17 // DWARF 4 new attribute for section offset
299 #define DW_FORM_exprloc                 0x18
300 #define DW_FORM_flag_present            0x19
301 #define DW_FORM_strx                    0x1a
302 #define DW_FORM_addrx                   0x1b
303 #define DW_FORM_ref_sup4                0x1c
304 #define DW_FORM_strp_sup                0x1d
305 #define DW_FORM_data16                  0x1e
306 #define DW_FORM_line_ptr                0x1f
307 #define DW_FORM_ref_sig8                0x20
308 #define DW_FORM_implicit_const          0x21
309 #define DW_FORM_loclistx                0x22
310 #define DW_FORM_rnglistx                0x23
311 #define DW_FORM_ref_sup8                0x24
312 #define DW_FORM_strx1                   0x25
313 #define DW_FORM_strx2                   0x26
314 #define DW_FORM_strx3                   0x27
315 #define DW_FORM_strx4                   0x28
316 #define DW_FORM_addrx1                  0x29
317 #define DW_FORM_addrx2                  0x2a
318 #define DW_FORM_addrx3                  0x2b
319 #define DW_FORM_addrx4                  0x2c
320 
321 #define DW_OP_addr                      0x03
322 #define DW_OP_deref                     0x06
323 #define DW_OP_const1u                   0x08
324 #define DW_OP_const1s                   0x09
325 #define DW_OP_const2u                   0x0a
326 #define DW_OP_const2s                   0x0b
327 #define DW_OP_const4u                   0x0c
328 #define DW_OP_const4s                   0x0d
329 #define DW_OP_const8u                   0x0e
330 #define DW_OP_const8s                   0x0f
331 #define DW_OP_constu                    0x10
332 #define DW_OP_consts                    0x11
333 #define DW_OP_dup                       0x12
334 #define DW_OP_drop                      0x13
335 #define DW_OP_over                      0x14
336 #define DW_OP_pick                      0x15
337 #define DW_OP_swap                      0x16
338 #define DW_OP_rot                       0x17
339 #define DW_OP_xderef                    0x18
340 #define DW_OP_abs                       0x19
341 #define DW_OP_and                       0x1a
342 #define DW_OP_div                       0x1b
343 #define DW_OP_minus                     0x1c
344 #define DW_OP_mod                       0x1d
345 #define DW_OP_mul                       0x1e
346 #define DW_OP_neg                       0x1f
347 #define DW_OP_not                       0x20
348 #define DW_OP_or                        0x21
349 #define DW_OP_plus                      0x22
350 #define DW_OP_plus_uconst               0x23
351 #define DW_OP_shl                       0x24
352 #define DW_OP_shr                       0x25
353 #define DW_OP_shra                      0x26
354 #define DW_OP_xor                       0x27
355 #define DW_OP_skip                      0x2f
356 #define DW_OP_bra                       0x28
357 #define DW_OP_eq                        0x29
358 #define DW_OP_ge                        0x2a
359 #define DW_OP_gt                        0x2b
360 #define DW_OP_le                        0x2c
361 #define DW_OP_lt                        0x2d
362 #define DW_OP_ne                        0x2e
363 #define DW_OP_lit0                      0x30
364 #define DW_OP_lit1                      0x31
365 #define DW_OP_lit2                      0x32
366 #define DW_OP_lit3                      0x33
367 #define DW_OP_lit4                      0x34
368 #define DW_OP_lit5                      0x35
369 #define DW_OP_lit6                      0x36
370 #define DW_OP_lit7                      0x37
371 #define DW_OP_lit8                      0x38
372 #define DW_OP_lit9                      0x39
373 #define DW_OP_lit10                     0x3a
374 #define DW_OP_lit11                     0x3b
375 #define DW_OP_lit12                     0x3c
376 #define DW_OP_lit13                     0x3d
377 #define DW_OP_lit14                     0x3e
378 #define DW_OP_lit15                     0x3f
379 #define DW_OP_lit16                     0x40
380 #define DW_OP_lit17                     0x41
381 #define DW_OP_lit18                     0x42
382 #define DW_OP_lit19                     0x43
383 #define DW_OP_lit20                     0x44
384 #define DW_OP_lit21                     0x45
385 #define DW_OP_lit22                     0x46
386 #define DW_OP_lit23                     0x47
387 #define DW_OP_lit24                     0x48
388 #define DW_OP_lit25                     0x49
389 #define DW_OP_lit26                     0x4a
390 #define DW_OP_lit27                     0x4b
391 #define DW_OP_lit28                     0x4c
392 #define DW_OP_lit29                     0x4d
393 #define DW_OP_lit30                     0x4e
394 #define DW_OP_lit31                     0x4f
395 #define DW_OP_reg0                      0x50
396 #define DW_OP_reg1                      0x51
397 #define DW_OP_reg2                      0x52
398 #define DW_OP_reg3                      0x53
399 #define DW_OP_reg4                      0x54
400 #define DW_OP_reg5                      0x55
401 #define DW_OP_reg6                      0x56
402 #define DW_OP_reg7                      0x57
403 #define DW_OP_reg8                      0x58
404 #define DW_OP_reg9                      0x59
405 #define DW_OP_reg10                     0x5a
406 #define DW_OP_reg11                     0x5b
407 #define DW_OP_reg12                     0x5c
408 #define DW_OP_reg13                     0x5d
409 #define DW_OP_reg14                     0x5e
410 #define DW_OP_reg15                     0x5f
411 #define DW_OP_reg16                     0x60
412 #define DW_OP_reg17                     0x61
413 #define DW_OP_reg18                     0x62
414 #define DW_OP_reg19                     0x63
415 #define DW_OP_reg20                     0x64
416 #define DW_OP_reg21                     0x65
417 #define DW_OP_reg22                     0x66
418 #define DW_OP_reg23                     0x67
419 #define DW_OP_reg24                     0x68
420 #define DW_OP_reg25                     0x69
421 #define DW_OP_reg26                     0x6a
422 #define DW_OP_reg27                     0x6b
423 #define DW_OP_reg28                     0x6c
424 #define DW_OP_reg29                     0x6d
425 #define DW_OP_reg30                     0x6e
426 #define DW_OP_reg31                     0x6f
427 #define DW_OP_breg0                     0x70
428 #define DW_OP_breg1                     0x71
429 #define DW_OP_breg2                     0x72
430 #define DW_OP_breg3                     0x73
431 #define DW_OP_breg4                     0x74
432 #define DW_OP_breg5                     0x75
433 #define DW_OP_breg6                     0x76
434 #define DW_OP_breg7                     0x77
435 #define DW_OP_breg8                     0x78
436 #define DW_OP_breg9                     0x79
437 #define DW_OP_breg10                    0x7a
438 #define DW_OP_breg11                    0x7b
439 #define DW_OP_breg12                    0x7c
440 #define DW_OP_breg13                    0x7d
441 #define DW_OP_breg14                    0x7e
442 #define DW_OP_breg15                    0x7f
443 #define DW_OP_breg16                    0x80
444 #define DW_OP_breg17                    0x81
445 #define DW_OP_breg18                    0x82
446 #define DW_OP_breg19                    0x83
447 #define DW_OP_breg20                    0x84
448 #define DW_OP_breg21                    0x85
449 #define DW_OP_breg22                    0x86
450 #define DW_OP_breg23                    0x87
451 #define DW_OP_breg24                    0x88
452 #define DW_OP_breg25                    0x89
453 #define DW_OP_breg26                    0x8a
454 #define DW_OP_breg27                    0x8b
455 #define DW_OP_breg28                    0x8c
456 #define DW_OP_breg29                    0x8d
457 #define DW_OP_breg30                    0x8e
458 #define DW_OP_breg31                    0x8f
459 #define DW_OP_regx                      0x90
460 #define DW_OP_fbreg                     0x91
461 #define DW_OP_bregx                     0x92
462 #define DW_OP_piece                     0x93
463 #define DW_OP_deref_size                0x94
464 #define DW_OP_xderef_size               0x95
465 #define DW_OP_nop                       0x96
466 #define DW_OP_push_object_address       0x97
467 #define DW_OP_call2                     0x98
468 #define DW_OP_call4                     0x99
469 #define DW_OP_call_ref                  0x9a
470 #define DW_OP_form_tls_address          0x9b
471 #define DW_OP_call_frame_cfa            0x9c
472 #define DW_OP_bit_piece                 0x9d
473 #define DW_OP_implicit_value            0x9e
474 #define DW_OP_stack_value               0x9f
475 
476 /* <_lo_user ; _hi_user> Interval is reserved for vendor extensions */
477 #define DW_OP_lo_user                   0xe0
478 #define DW_OP_hi_user                   0xff
479 
480 
481 #define DW_ATE_address                  0x01
482 #define DW_ATE_boolean                  0x02
483 #define DW_ATE_complex_float            0x03
484 #define DW_ATE_float                    0x04
485 #define DW_ATE_signed                   0x05
486 #define DW_ATE_signed_char              0x06
487 #define DW_ATE_unsigned                 0x07
488 #define DW_ATE_unsigned_char            0x08
489 #define DW_ATE_imaginary_float          0x09
490 #define DW_ATE_packed_decimal           0x0a
491 #define DW_ATE_numeric_string           0x0b
492 #define DW_ATE_edited                   0x0c
493 #define DW_ATE_signed_fixed             0x0d
494 #define DW_ATE_unsigned_fixed           0x0e
495 #define DW_ATE_decimal_float            0x0f
496 #define DW_ATE_UTF                      0x10
497 
498 /* <_lo_user ; _hi_user> Interval is reserved for vendor extensions */
499 #define DW_ATE_lo_user                  0x80
500 #define DW_ATE_hi_user                  0xff
501 
502 #define DW_DS_unsigned                  0x01
503 #define DW_DS_leading_overpunch         0x02
504 #define DW_DS_trailing_overpunch        0x03
505 #define DW_DS_leading_separate          0x04
506 #define DW_DS_trailing_separate         0x05
507 
508 #define DW_END_default                  0x00
509 #define DW_END_big                      0x01
510 #define DW_END_little                   0x02
511 
512 /* <_lo_user ; _hi_user> Interval is reserved for vendor extensions */
513 #define DW_END_lo_user                  0x40
514 #define DW_END_hi_user                  0xff
515 
516 #define DW_ACCESS_public                0x01
517 #define DW_ACCESS_protected             0x02
518 #define DW_ACCESS_private               0x03
519 
520 #define DW_VIS_local                    0x01
521 #define DW_VIS_exported                 0x02
522 #define DW_VIS_qualified                0x03
523 
524 #define DW_VIRTUALITY_none              0x00
525 #define DW_VIRTUALITY_virtual           0x01
526 #define DW_VIRTUALITY_pure_virtual      0x02
527 
528 #define DW_LANG_C89                     0x0001
529 #define DW_LANG_C                       0x0002
530 #define DW_LANG_Ada83                   0x0003
531 #define DW_LANG_C_plus_plus             0x0004
532 #define DW_LANG_Cobol74                 0x0005
533 #define DW_LANG_Cobol85                 0x0006
534 #define DW_LANG_Fortran77               0x0007
535 #define DW_LANG_Fortran90               0x0008
536 #define DW_LANG_Pascal83                0x0009
537 #define DW_LANG_Modula2                 0x000a
538 #define DW_LANG_Java                    0x000b
539 #define DW_LANG_C99                     0x000c
540 #define DW_LANG_Ada95                   0x000d
541 #define DW_LANG_Fortran95               0x000e
542 #define DW_LANG_PLI                     0x000f
543 #define DW_LANG_ObjC                    0x0010
544 #define DW_LANG_ObjC_plus_plus          0x0011
545 #define DW_LANG_UPC                     0x0012
546 #define DW_LANG_D                       0x0013
547 #define DW_LANG_Python                  0x0014
548 #define DW_LANG_Rust                    0x001c
549 #define DW_LANG_C11                     0x001d
550 #define DW_LANG_Swift                   0x001e
551 #define DW_LANG_Julia                   0x001f
552 #define DW_LANG_Dylan                   0x0020
553 #define DW_LANG_C_plus_plus_14          0x0021
554 #define DW_LANG_Fortran03               0x0022
555 #define DW_LANG_Fortran08               0x0023
556 #define DW_LANG_lo_user                 0x8000
557 #define DW_LANG_hi_user                 0xffff
558 
559 #define DW_ID_case_sensitive            0x00
560 #define DW_ID_up_case                   0x01
561 #define DW_ID_down_case                 0x02
562 #define DW_ID_case_insensitive          0x03
563 
564 #define DW_CC_normal                    0x01
565 #define DW_CC_program                   0x02
566 #define DW_CC_nocall                    0x03
567 #define DW_CC_lo_user                   0x40
568 #define DW_CC_hi_user                   0xff
569 
570 #define DW_INL_not_inlined              0x00
571 #define DW_INL_inlined                  0x01
572 #define DW_INL_declared_not_inlined     0x02
573 #define DW_INL_declared_inlined         0x03
574 
575 #define DW_ORD_row_major                0x00
576 #define DW_ORD_col_major                0x01
577 
578 #define DW_DSC_label                    0x00
579 #define DW_DSC_range                    0x01
580 
581 #define DW_MACINFO_define               0x01
582 #define DW_MACINFO_undef                0x02
583 #define DW_MACINFO_start_file           0x03
584 #define DW_MACINFO_end_file             0x04
585 #define DW_MACINFO_vendor_ext           0xff
586 
587 #define DW_CFA_advance_loc              0x40
588 #define DW_CFA_offset                   0x80
589 #define DW_CFA_restore                  0xc0
590 
591 #define DW_CFA_nop                      0x00
592 #define DW_CFA_set_loc                  0x01
593 #define DW_CFA_advance_loc1             0x02
594 #define DW_CFA_advance_loc2             0x03
595 #define DW_CFA_advance_loc4             0x04
596 #define DW_CFA_offse_extended           0x05
597 #define DW_CFA_restore_extended         0x06
598 #define DW_CFA_undefined                0x07
599 #define DW_CFA_same_value               0x08
600 #define DW_CFA_register                 0x09
601 #define DW_CFA_remember_state           0x0a
602 #define DW_CFA_restore_state            0x0b
603 #define DW_CFA_def_cfa                  0x0c
604 #define DW_CFA_def_cfa_register         0x0d
605 #define DW_CFA_def_cfa_offset           0x0e
606 #define DW_CFA_def_cfa_expression       0x0f
607 #define DW_CFA_expression               0x10
608 #define DW_CFA_offset_extended_sf       0x11
609 #define DW_CFA_def_cfa_sf               0x12
610 #define DW_CFA_def_cfa_offset_sf        0x13
611 #define DW_CFA_val_offset               0x14
612 #define DW_CFA_val_offset_sf            0x15
613 #define DW_CFA_val_expression           0x16
614 #define DW_CFA_lo_user                  0x1c
615 #define DW_CFA_hi_user                  0x3f
616 
617 #define DW_UT_compile                   0x01
618 #define DW_UT_type                      0x02
619 #define DW_UT_partial                   0x03
620 #define DW_UT_skeleton                  0x04
621 #define DW_UT_split_compile             0x05
622 #define DW_UT_split_type                0x06
623 #define DW_UT_lo_user                   0x80
624 #define DW_UT_hi_user                   0xff
625 
626 typedef struct {
627 	ut32 total_length;
628 	ut16 version;
629 	ut32 plen;
630 	ut8 mininstlen;
631 	ut8 is_stmt;
632 	char line_base;
633 	ut8 line_range;
634 	ut8 opcode_base;
635 	ut32 oplentable[12];
636 	const char **incdirs;
637 	const char *file[128];
638 } RBinDwarfInfoHeader;
639 #define R_BIN_DWARF_INFO_HEADER_FILE_LENGTH(x) (sizeof (x->file)/sizeof(*(x->file)))
640 
641 typedef struct {
642 	ut64 address;
643 	unsigned int file;
644 	unsigned int line;
645 	unsigned int column;
646 	int is_stmt;
647 	int basic_block;
648 	int end_sequence;
649 } RBinDwarfState;
650 
651 typedef struct {
652 	ut64 address;
653 	char *file;
654 	unsigned int line;
655 	unsigned int column;
656 } RBinDwarfRow;
657 
658 #define DWARF_INIT_LEN_64	0xffffffff
659 typedef union {
660 	ut32 offset32;
661 	ut64 offset64;
662 } section_offset;
663 
664 typedef struct {
665 	ut64 unit_length;
666 	ut16 version;
667 	section_offset debug_abbrev_offset;
668 	ut8 address_size;
669 	ut64 type_signature;
670 	section_offset type_offset;
671 } RBinDwarfTypeUnitHeader;
672 
673 typedef struct {
674 	ut64 unit_length;
675 	ut16 version;
676 	section_offset debug_info_offset;
677 	ut8 address_size;
678 	ut8 segment_size;
679 } RBinDwarfAddressRangeTable;
680 
681 typedef struct {
682 	ut64	attr_name;
683 	ut64	attr_form;
684 	st64	special; // Used for values coded directly into abbrev
685 } RBinDwarfAttrDef;
686 
687 typedef struct {
688 	ut64 length;
689 	ut8 *data;
690 } RBinDwarfBlock;
691 
692 // http://www.dwarfstd.org/doc/DWARF4.pdf#page=29&zoom=100,0,0
693 typedef enum {
694 	DW_AT_KIND_ADDRESS,
695 	DW_AT_KIND_BLOCK,
696 	DW_AT_KIND_CONSTANT,
697 	DW_AT_KIND_EXPRLOC,
698 	DW_AT_KIND_FLAG,
699 	DW_AT_KIND_LINEPTR,
700 	DW_AT_KIND_LOCLISTPTR,
701 	DW_AT_KIND_MACPTR,
702 	DW_AT_KIND_RANGELISTPTR,
703 	DW_AT_KIND_REFERENCE,
704 	DW_AT_KIND_STRING,
705 } RBinDwarfAttrKind;
706 
707 typedef struct dwarf_attr_kind {
708 	ut64 attr_name;
709 	ut64 attr_form;
710 	RBinDwarfAttrKind kind;
711 	/* This is subideal, as dw_form_data can be anything
712 	   we could lose information example: encoding signed
713 	   2 byte int into ut64 and then interpreting it as st64 TODO*/
714 	union {
715 		ut64 address;
716 		RBinDwarfBlock block;
717 		ut64 uconstant;
718 		st64 sconstant;
719 		ut8 flag;
720 		ut64 reference;
721 		struct {
722 			const char *content;
723 			ut64 offset;
724 		} string;
725 	};
726 } RBinDwarfAttrValue;
727 
728 typedef struct {
729 	// A 4-byte (or 8 byte for 64bit dwarf) unsigned length of the .debug_info contribution
730 	// for that compilation unit, not including the length field itself.
731 	ut64 length;
732 	ut16 version;
733 	// A 4-byte unsigned offset into the .debug_abbrev section.
734 	ut64 abbrev_offset;
735 	// A 1 - byte size of an address on the target architecture.If the system uses
736 	//  segmented addressing, this value represents the size of the offset portion of an address.
737 	ut8 address_size;
738 	ut8 unit_type; // DWARF 5 addition
739 	ut8 dwo_id; // DWARF 5 addition
740 	ut64 type_sig; // DWARF 5 addition
741 	ut64 type_offset; // DWARF 5 addition
742 	ut64 header_size; // excluding length field
743 	ut64 unit_offset;
744 	bool is_64bit;
745 } RBinDwarfCompUnitHdr;
746 
747 typedef struct {
748 	ut64	tag;
749 	ut64	abbrev_code;
750 	size_t	count;
751 	size_t	capacity;
752 	ut64	offset; // important for parsing types
753 	bool	has_children; // important for parsing types
754 	RBinDwarfAttrValue *attr_values;
755 } RBinDwarfDie;
756 
757 typedef struct {
758 	RBinDwarfCompUnitHdr hdr;
759 	ut64	offset;
760 	size_t	count;
761 	size_t	capacity;
762 	RBinDwarfDie *dies;
763 } RBinDwarfCompUnit;
764 
765 #define COMP_UNIT_CAPACITY	8
766 #define DEBUG_INFO_CAPACITY	8
767 typedef struct {
768 	size_t count;
769 	size_t capacity;
770 	RBinDwarfCompUnit *comp_units;
771 	HtUP/*<ut64 offset, DwarfDie *die>*/ *lookup_table;
772 } RBinDwarfDebugInfo;
773 
774 #define	ABBREV_DECL_CAP		8
775 
776 typedef struct {
777 	ut64 code;
778 	ut64 tag;
779 	ut64 offset;
780 	ut8 has_children;
781 	size_t count;
782 	size_t capacity;
783 	RBinDwarfAttrDef *defs;
784 } RBinDwarfAbbrevDecl;
785 
786 #define DEBUG_ABBREV_CAP	32
787 
788 typedef struct {
789 	size_t count;
790 	size_t capacity;
791 	RBinDwarfAbbrevDecl *decls;
792 } RBinDwarfDebugAbbrev;
793 
794 #define		DWARF_FALSE	0
795 #define		DWARF_TRUE	1
796 
797 typedef struct {
798 	ut64 address;
799 	ut64 op_index;
800 	ut64 file;
801 	ut64 line;
802 	ut64 column;
803 	ut8 is_stmt;
804 	ut8 basic_block;
805 	ut8 end_sequence;
806 	ut8 prologue_end;
807 	ut8 epilogue_begin;
808 	ut64 isa;
809 	ut64 discriminator;
810 } RBinDwarfSMRegisters;
811 
812 typedef struct {
813 	char *name;
814 	ut32 id_idx, mod_time, file_len;
815 } file_entry;
816 
817 typedef struct {
818 	ut64 unit_length;
819 	ut16 version;
820 	ut64 header_length;
821 	ut8 min_inst_len;
822 	ut8 max_ops_per_inst;
823 	ut8 default_is_stmt;
824 	st32 line_base;
825 	ut8 line_range;
826 	ut8 opcode_base;
827 	ut8 address_size;
828 	ut8 segment_selector_size;
829 	bool is_64bit;
830 
831 	ut8 *std_opcode_lengths;
832 	char **include_directories;
833 	file_entry *file_names;
834 	size_t file_names_count;
835 } RBinDwarfLineHeader;
836 
837 typedef struct r_bin_dwarf_loc_entry_t {
838 	ut64 start;
839 	ut64 end;
840 	RBinDwarfBlock *expression;
841 } RBinDwarfLocRange;
842 
843 typedef struct r_bin_dwarf_loc_list_t {
844 	RList/*<RBinDwarfLocRange>*/  *list;
845 	ut64 offset;
846 } RBinDwarfLocList;
847 
848 #define r_bin_dwarf_line_new(o,a,f,l) o->address=a, o->file = strdup (r_str_get (f)), o->line = l, o->column =0,o
849 
850 R_API RList *r_bin_dwarf_parse_aranges(RBin *a, int mode);
851 R_API RList *r_bin_dwarf_parse_line(RBin *a, int mode);
852 R_API RBinDwarfDebugAbbrev *r_bin_dwarf_parse_abbrev(RBin *a, int mode);
853 R_API RBinDwarfDebugInfo *r_bin_dwarf_parse_info(RBinDwarfDebugAbbrev *da, RBin *a, int mode);
854 R_API HtUP/*<offset, RBinDwarfLocList*>*/  *r_bin_dwarf_parse_loc(RBin *bin, int addr_size);
855 R_API void r_bin_dwarf_print_loc(HtUP /*<offset, RBinDwarfLocList*>*/  *loc_table, int addr_size, PrintfCallback print);
856 R_API void r_bin_dwarf_free_loc(HtUP /*<offset, RBinDwarfLocList*>*/  *loc_table);
857 R_API void r_bin_dwarf_free_debug_info(RBinDwarfDebugInfo *inf);
858 R_API void r_bin_dwarf_free_debug_abbrev(RBinDwarfDebugAbbrev *da);
859 
860 #ifdef __cplusplus
861 }
862 #endif
863 
864 #endif
865