elf_utils 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.standard.yml +3 -0
  4. data/CODE_OF_CONDUCT.md +132 -0
  5. data/CONTRIBUTING.md +55 -0
  6. data/Gemfile +23 -0
  7. data/LICENSE.txt +21 -0
  8. data/MAINTAINERS.md +3 -0
  9. data/README.md +126 -0
  10. data/Rakefile +76 -0
  11. data/SECURITY.md +57 -0
  12. data/elf_utils.gemspec +41 -0
  13. data/ext/elf_utils/elf_utils.c +53 -0
  14. data/ext/elf_utils/extconf.rb +3 -0
  15. data/lib/elf_utils/elf_file.rb +312 -0
  16. data/lib/elf_utils/section/base.rb +77 -0
  17. data/lib/elf_utils/section/debug_abbrev/abbreviation.rb +171 -0
  18. data/lib/elf_utils/section/debug_abbrev/abbreviation_table.rb +27 -0
  19. data/lib/elf_utils/section/debug_abbrev.rb +15 -0
  20. data/lib/elf_utils/section/debug_addr.rb +9 -0
  21. data/lib/elf_utils/section/debug_arange.rb +54 -0
  22. data/lib/elf_utils/section/debug_info/compilation_unit.rb +189 -0
  23. data/lib/elf_utils/section/debug_info/debug_str_offsets_ref.rb +15 -0
  24. data/lib/elf_utils/section/debug_info/debug_str_ref.rb +17 -0
  25. data/lib/elf_utils/section/debug_info/die/base.rb +130 -0
  26. data/lib/elf_utils/section/debug_info/die.rb +470 -0
  27. data/lib/elf_utils/section/debug_info/die_ref.rb +22 -0
  28. data/lib/elf_utils/section/debug_info/header.rb +26 -0
  29. data/lib/elf_utils/section/debug_info.rb +93 -0
  30. data/lib/elf_utils/section/debug_line/line_number_program/header.rb +48 -0
  31. data/lib/elf_utils/section/debug_line/line_number_program/state_machine.rb +206 -0
  32. data/lib/elf_utils/section/debug_line/line_number_program.rb +134 -0
  33. data/lib/elf_utils/section/debug_line.rb +35 -0
  34. data/lib/elf_utils/section/debug_ranges.rb +22 -0
  35. data/lib/elf_utils/section/debug_str_offsets.rb +16 -0
  36. data/lib/elf_utils/section/dynsym.rb +14 -0
  37. data/lib/elf_utils/section/strtab.rb +9 -0
  38. data/lib/elf_utils/section/symtab.rb +11 -0
  39. data/lib/elf_utils/section.rb +50 -0
  40. data/lib/elf_utils/segment/base.rb +72 -0
  41. data/lib/elf_utils/segment.rb +9 -0
  42. data/lib/elf_utils/string_pread.rb +18 -0
  43. data/lib/elf_utils/symbol.rb +144 -0
  44. data/lib/elf_utils/types/dwarf/expression.rb +34 -0
  45. data/lib/elf_utils/types/dwarf.rb +639 -0
  46. data/lib/elf_utils/types/dwarf32/v2.rb +44 -0
  47. data/lib/elf_utils/types/dwarf32/v3.rb +40 -0
  48. data/lib/elf_utils/types/dwarf32/v4.rb +41 -0
  49. data/lib/elf_utils/types/dwarf32/v5.rb +44 -0
  50. data/lib/elf_utils/types/dwarf32.rb +12 -0
  51. data/lib/elf_utils/types/dwarf64/v3.rb +42 -0
  52. data/lib/elf_utils/types/dwarf64/v4.rb +43 -0
  53. data/lib/elf_utils/types/dwarf64/v5.rb +46 -0
  54. data/lib/elf_utils/types/dwarf64.rb +8 -0
  55. data/lib/elf_utils/types/sleb128.rb +66 -0
  56. data/lib/elf_utils/types/uleb128.rb +56 -0
  57. data/lib/elf_utils/types/unit_length.rb +51 -0
  58. data/lib/elf_utils/types.rb +328 -0
  59. data/lib/elf_utils/version.rb +5 -0
  60. data/lib/elf_utils.rb +83 -0
  61. data/sig/elf_utils.rbs +4 -0
  62. metadata +120 -0
@@ -0,0 +1,639 @@
1
+ require "ctypes"
2
+ require_relative "uleb128"
3
+
4
+ module ElfUtils
5
+ module Types::Dwarf
6
+ extend CTypes::Helpers
7
+ extend self
8
+
9
+ UnitType = CTypes::Enum.new(Types::ULEB128, {
10
+ compile: 0x01,
11
+ type: 0x02,
12
+ partial: 0x03,
13
+ skeleton: 0x04,
14
+ split_compile: 0x05,
15
+ split_type: 0x06,
16
+ lo_user: 0x80,
17
+ hi_user: 0xff
18
+ }).permissive
19
+
20
+ Tag = CTypes::Enum.new(Types::ULEB128, {
21
+ invalid: 0,
22
+ array_type: 0x01,
23
+ class_type: 0x02,
24
+ entry_point: 0x03,
25
+ enumeration_type: 0x04,
26
+ formal_parameter: 0x05,
27
+ imported_declaration: 0x08,
28
+ label: 0x0a,
29
+ lexical_block: 0x0b,
30
+ member: 0x0d,
31
+ pointer_type: 0x0f,
32
+ reference_type: 0x10,
33
+ compile_unit: 0x11,
34
+ string_type: 0x12,
35
+ structure_type: 0x13,
36
+ subroutine_type: 0x15,
37
+ typedef: 0x16,
38
+ union_type: 0x17,
39
+ unspecified_parameters: 0x18,
40
+ variant: 0x19,
41
+ common_block: 0x1a,
42
+ common_inclusion: 0x1b,
43
+ inheritance: 0x1c,
44
+ inlined_subroutine: 0x1d,
45
+ module: 0x1e,
46
+ ptr_to_member_type: 0x1f,
47
+ set_type: 0x20,
48
+ subrange_type: 0x21,
49
+ with_stmt: 0x22,
50
+ access_declaration: 0x23,
51
+ base_type: 0x24,
52
+ catch_block: 0x25,
53
+ const_type: 0x26,
54
+ constant: 0x27,
55
+ enumerator: 0x28,
56
+ file_type: 0x29,
57
+ friend: 0x2a,
58
+ namelist: 0x2b,
59
+ namelist_item: 0x2c,
60
+ packed_type: 0x2d,
61
+ subprogram: 0x2e,
62
+ template_type_parameter: 0x2f,
63
+ template_value_parameter: 0x30,
64
+ thrown_type: 0x31,
65
+ try_block: 0x32,
66
+ variant_part: 0x33,
67
+ variable: 0x34,
68
+ volatile_type: 0x35,
69
+ dwarf_procedure: 0x36,
70
+ restrict_type: 0x37,
71
+ interface_type: 0x38,
72
+ namespace: 0x39,
73
+ imported_module: 0x3a,
74
+ unspecified_type: 0x3b,
75
+ partial_unit: 0x3c,
76
+ imported_unit: 0x3d,
77
+ condition: 0x3f,
78
+ shared_type: 0x40,
79
+ type_unit: 0x41,
80
+ rvalue_reference_type: 0x42,
81
+ template_alias: 0x43,
82
+ coarray_type: 0x44,
83
+ generic_subrange: 0x45,
84
+ dynamic_type: 0x46,
85
+ atomic_type: 0x47,
86
+ call_site: 0x48,
87
+ call_site_parameter: 0x49,
88
+ skeleton_unit: 0x4a,
89
+ immutable_type: 0x4b
90
+ }).permissive
91
+
92
+ Form = CTypes::Enum.new(Types::ULEB128, {
93
+ zero: 0,
94
+ addr: 0x01,
95
+ block2: 0x03,
96
+ block4: 0x04,
97
+ data2: 0x05,
98
+ data4: 0x06,
99
+ data8: 0x07,
100
+ string: 0x08,
101
+ block: 0x09,
102
+ block1: 0x0a,
103
+ data1: 0x0b,
104
+ flag: 0x0c,
105
+ sdata: 0x0d,
106
+ strp: 0x0e,
107
+ udata: 0x0f,
108
+ ref_addr: 0x10,
109
+ ref1: 0x11,
110
+ ref2: 0x12,
111
+ ref4: 0x13,
112
+ ref8: 0x14,
113
+ ref_udata: 0x15,
114
+ indirect: 0x16,
115
+ sec_offset: 0x17,
116
+ exprloc: 0x18,
117
+ flag_present: 0x19,
118
+ strx: 0x1a,
119
+ addrx: 0x1b,
120
+ ref_sup4: 0x1c,
121
+ strp_sup: 0x1d,
122
+ data16: 0x1e,
123
+ line_strp: 0x1f,
124
+ ref_sig8: 0x20,
125
+ implicit_const: 0x21,
126
+ loclistx: 0x22,
127
+ rnglistx: 0x23,
128
+ ref_sup8: 0x24,
129
+ strx1: 0x25,
130
+ strx2: 0x26,
131
+ strx3: 0x27,
132
+ strx4: 0x28,
133
+ addrx1: 0x29,
134
+ addrx2: 0x2a,
135
+ addrx3: 0x2b,
136
+ addrx4: 0x2c
137
+ }).permissive
138
+
139
+ Attribute = CTypes::Enum.new(Types::ULEB128, {
140
+ zero: 0,
141
+ sibling: 0x01,
142
+ location: 0x02,
143
+ name: 0x03,
144
+ ordering: 0x09,
145
+ byte_size: 0x0b,
146
+ bit_offset: 0x0c,
147
+ bit_size: 0x0d,
148
+ stmt_list: 0x10,
149
+ low_pc: 0x11,
150
+ high_pc: 0x12,
151
+ language: 0x13,
152
+ discr: 0x15,
153
+ discr_value: 0x16,
154
+ visibility: 0x17,
155
+ import: 0x18,
156
+ string_length: 0x19,
157
+ common_reference: 0x1a,
158
+ comp_dir: 0x1b,
159
+ const_value: 0x1c,
160
+ containing_type: 0x1d,
161
+ default_value: 0x1e,
162
+ inline: 0x20,
163
+ is_optional: 0x21,
164
+ lower_bound: 0x22,
165
+ producer: 0x25,
166
+ prototyped: 0x27,
167
+ return_addr: 0x2a,
168
+ start_scope: 0x2c,
169
+ bit_stride: 0x2e,
170
+ upper_bound: 0x2f,
171
+ abstract_origin: 0x31,
172
+ accessibility: 0x32,
173
+ address_class: 0x33,
174
+ artificial: 0x34,
175
+ base_types: 0x35,
176
+ calling_convention: 0x36,
177
+ count: 0x37,
178
+ data_member_location: 0x38,
179
+ decl_column: 0x39,
180
+ decl_file: 0x3a,
181
+ decl_line: 0x3b,
182
+ declaration: 0x3c,
183
+ discr_list: 0x3d,
184
+ encoding: 0x3e,
185
+ external: 0x3f,
186
+ frame_base: 0x40,
187
+ friend: 0x41,
188
+ identifier_case: 0x42,
189
+ macro_info: 0x43,
190
+ namelist_item: 0x44,
191
+ priority: 0x45,
192
+ segment: 0x46,
193
+ specification: 0x47,
194
+ static_link: 0x48,
195
+ type: 0x49,
196
+ use_location: 0x4a,
197
+ variable_parameter: 0x4b,
198
+ virtuality: 0x4c,
199
+ vtable_elem_location: 0x4d,
200
+ allocated: 0x4e,
201
+ associated: 0x4f,
202
+ data_location: 0x50,
203
+ byte_stride: 0x51,
204
+ entry_pc: 0x52,
205
+ use_UTF8: 0x53,
206
+ extension: 0x54,
207
+ ranges: 0x55,
208
+ trampoline: 0x56,
209
+ call_column: 0x57,
210
+ call_file: 0x58,
211
+ call_line: 0x59,
212
+ description: 0x5a,
213
+ binary_scale: 0x5b,
214
+ decimal_scale: 0x5c,
215
+ small: 0x5d,
216
+ decimal_sign: 0x5e,
217
+ digit_count: 0x5f,
218
+ picture_string: 0x60,
219
+ mutable: 0x61,
220
+ threads_scaled: 0x62,
221
+ explicit: 0x63,
222
+ object_pointer: 0x64,
223
+ endianity: 0x65,
224
+ elemental: 0x66,
225
+ pure: 0x67,
226
+ recursive: 0x68,
227
+ signature: 0x69,
228
+ main_subprogram: 0x6a,
229
+ data_bit_offset: 0x6b,
230
+ const_expr: 0x6c,
231
+ enum_class: 0x6d,
232
+ linkage_name: 0x6e,
233
+ string_length_bit_size: 0x6f,
234
+ string_length_byte_size: 0x70,
235
+ rank: 0x71,
236
+ str_offsets_base: 0x72,
237
+ addr_base: 0x73,
238
+ rnglists_base: 0x74,
239
+ dwo_name: 0x76,
240
+ reference: 0x77,
241
+ rvalue_reference: 0x78,
242
+ macros: 0x79,
243
+ call_all_calls: 0x7a,
244
+ call_all_source_calls: 0x7b,
245
+ call_all_tail_calls: 0x7c,
246
+ call_return_pc: 0x7d,
247
+ call_value: 0x7e,
248
+ call_origin: 0x7f,
249
+ call_parameter: 0x80,
250
+ call_pc: 0x81,
251
+ call_tail_call: 0x82,
252
+ call_target: 0x83,
253
+ call_target_clobbered: 0x84,
254
+ call_data_location: 0x85,
255
+ call_data_value: 0x86,
256
+ noreturn: 0x87,
257
+ alignment: 0x88,
258
+ export_symbols: 0x89,
259
+ deleted: 0x8a,
260
+ defaulted: 0x8b,
261
+ loclists_base: 0x8c,
262
+
263
+ MIPS_fde: 0x2001,
264
+ MIPS_loop_begin: 0x2002,
265
+ MIPS_tail_loop_begin: 0x2003,
266
+ MIPS_epilog_begin: 0x2004,
267
+ MIPS_loop_unroll_factor: 0x2005,
268
+ MIPS_software_pipeline_depth: 0x2006,
269
+ MIPS_linkage_name: 0x2007,
270
+ MIPS_stride: 0x2008,
271
+ MIPS_abstract_name: 0x2009,
272
+ MIPS_clone_origin: 0x200a,
273
+ MIPS_has_inlines: 0x200b,
274
+ MIPS_stride_byte: 0x200c,
275
+ MIPS_stride_elem: 0x200d,
276
+ MIPS_ptr_dopetype: 0x200e,
277
+ MIPS_allocatable_dopetype: 0x200f,
278
+ MIPS_assumed_shape_dopetype: 0x2010,
279
+ MIPS_assumed_size: 0x2011,
280
+
281
+ sf_names: 0x2101,
282
+ src_info: 0x2102,
283
+ mac_info: 0x2103,
284
+ src_coords: 0x2104,
285
+ body_begin: 0x2105,
286
+ body_end: 0x2106,
287
+ GNU_vector: 0x2107,
288
+ GNU_guarded_by: 0x2108,
289
+ GNU_pt_guarded_by: 0x2109,
290
+ GNU_guarded: 0x210a,
291
+ GNU_pt_guarded: 0x210b,
292
+ GNU_locks_excluded: 0x210c,
293
+ GNU_exclusive_locks_required: 0x210d,
294
+ GNU_shared_locks_required: 0x210e,
295
+ GNU_odr_signature: 0x210f,
296
+ GNU_template_name: 0x2110,
297
+ GNU_call_site_value: 0x2111,
298
+ GNU_call_site_data_value: 0x2112,
299
+ GNU_call_site_target: 0x2113,
300
+ GNU_call_site_target_clobbered: 0x2114,
301
+ GNU_tail_call: 0x2115,
302
+ GNU_all_tail_call_sites: 0x2116,
303
+ GNU_all_call_sites: 0x2117,
304
+ GNU_all_source_call_sites: 0x2118,
305
+ GNU_locviews: 0x2137,
306
+ GNU_entry_view: 0x2138,
307
+ GNU_macros: 0x2119,
308
+ GNU_deleted: 0x211a,
309
+ GNU_dwo_name: 0x2130,
310
+ GNU_dwo_id: 0x2131,
311
+ GNU_ranges_base: 0x2132,
312
+ GNU_addr_base: 0x2133,
313
+ GNU_pubnames: 0x2134,
314
+ GNU_pubtypes: 0x2135
315
+ }).permissive
316
+
317
+ Encoding = CTypes::Enum.new(uint8, {
318
+ void: 0x0,
319
+ address: 0x1,
320
+ boolean: 0x2,
321
+ complex_float: 0x3,
322
+ float: 0x4,
323
+ signed: 0x5,
324
+ signed_char: 0x6,
325
+ unsigned: 0x7,
326
+ unsigned_char: 0x8,
327
+ imaginary_float: 0x9,
328
+ packed_decimal: 0xa,
329
+ numeric_string: 0xb,
330
+ edited: 0xc,
331
+ signed_fixed: 0xd,
332
+ unsigned_fixed: 0xe,
333
+ decimal_float: 0xf,
334
+ UTF: 0x10,
335
+ UCS: 0x11,
336
+ ASCII: 0x12
337
+ }).permissive
338
+
339
+ # Line Number Program `directory_entry_format` and `file_name_entry_format`
340
+ # type field
341
+ EntryFormatType = CTypes::Enum.new(Types::ULEB128, {
342
+ path: 1,
343
+ directory_index: 2,
344
+ timestamp: 3,
345
+ size: 4,
346
+ md5: 5
347
+ }).permissive
348
+
349
+ # common unit header used within various debug sections
350
+ class UnitHeader < CTypes::Union
351
+ layout do
352
+ member :unit_length, uint32
353
+ member :dwarf32, struct(unit_length: uint32, version: uint16)
354
+ member :dwarf64, struct(
355
+ _marker: uint32,
356
+ unit_length: uint64,
357
+ version: uint16
358
+ )
359
+ end
360
+
361
+ def format
362
+ case unit_length
363
+ when 0xffffffff
364
+ :dwarf64
365
+ when proc { |v| v < 0xfffffff0 }
366
+ :dwarf32
367
+ else
368
+ raise Error, "unsupported format: 0x%08x" % hdr[:unit_length]
369
+ end
370
+ end
371
+
372
+ def inner
373
+ # PERF: we're caching this here because the Union type will do a bunch
374
+ # of extra work if we keep accessing the union via different members.
375
+ @inner ||= send(format)
376
+ end
377
+
378
+ def version
379
+ inner.version
380
+ end
381
+
382
+ def unit_size
383
+ inner.unit_length + inner.class.offsetof(:version)
384
+ end
385
+
386
+ def type
387
+ :"#{format}_v#{version}"
388
+ end
389
+
390
+ def addr_type
391
+ case format
392
+ when :dwarf64
393
+ CTypes::Helpers.uint64.with_endian(@endian)
394
+ when :dwarf32
395
+ CTypes::Helpers.uint32.with_endian(@endian)
396
+ end
397
+ end
398
+ end
399
+
400
+ class AbbreviationDeclaration < CTypes::Struct
401
+ layout do
402
+ attribute :code, Types::ULEB128
403
+ attribute :tag, Tag
404
+ attribute :children, uint8
405
+ attribute :attribute_specifications,
406
+ array(struct({
407
+ name: Attribute,
408
+ form: Form
409
+ }),
410
+ terminator: {name: :zero, form: :zero})
411
+ end
412
+
413
+ def inspect
414
+ buf = "<%s\n [%d] DW_TAG_%s\tDW_CHILDREN_%s\n" %
415
+ [self.class.name, code, tag, (children == 0) ? "no" : "yes"]
416
+ attribute_specifications.each do |spec|
417
+ buf << " %-15s DW_FORM_%s\n" %
418
+ ["DW_AT_#{spec.name}", spec.form]
419
+ end
420
+
421
+ buf.chomp! << ">"
422
+ end
423
+
424
+ def children?
425
+ @children == 1
426
+ end
427
+ end
428
+
429
+ Operation = CTypes::Enum.new(uint8, {
430
+ addr: 0x03,
431
+ deref: 0x06,
432
+ const1u: 0x08,
433
+ const1s: 0x09,
434
+ const2u: 0x0a,
435
+ const2s: 0x0b,
436
+ const4u: 0x0c,
437
+ const4s: 0x0d,
438
+ const8u: 0x0e,
439
+ const8s: 0x0f,
440
+ constu: 0x10,
441
+ consts: 0x11,
442
+ dup: 0x12,
443
+ drop: 0x13,
444
+ over: 0x14,
445
+ pick: 0x15,
446
+ swap: 0x16,
447
+ rot: 0x17,
448
+ xderef: 0x18,
449
+ abs: 0x19,
450
+ and: 0x1a,
451
+ div: 0x1b,
452
+ minus: 0x1c,
453
+ mod: 0x1d,
454
+ mul: 0x1e,
455
+ neg: 0x1f,
456
+ not: 0x20,
457
+ or: 0x21,
458
+ plus: 0x22,
459
+ plus_uconst: 0x23,
460
+ shl: 0x24,
461
+ shr: 0x25,
462
+ shra: 0x26,
463
+ xor: 0x27,
464
+ bra: 0x28,
465
+ eq: 0x29,
466
+ ge: 0x2a,
467
+ gt: 0x2b,
468
+ le: 0x2c,
469
+ lt: 0x2d,
470
+ ne: 0x2e,
471
+ skip: 0x2f,
472
+ lit0: 0x30,
473
+ lit1: 0x31,
474
+ lit2: 0x32,
475
+ lit3: 0x33,
476
+ lit4: 0x34,
477
+ lit5: 0x35,
478
+ lit6: 0x36,
479
+ lit7: 0x37,
480
+ lit8: 0x38,
481
+ lit9: 0x39,
482
+ lit10: 0x3a,
483
+ lit11: 0x3b,
484
+ lit12: 0x3c,
485
+ lit13: 0x3d,
486
+ lit14: 0x3e,
487
+ lit15: 0x3f,
488
+ lit16: 0x40,
489
+ lit17: 0x41,
490
+ lit18: 0x42,
491
+ lit19: 0x43,
492
+ lit20: 0x44,
493
+ lit21: 0x45,
494
+ lit22: 0x46,
495
+ lit23: 0x47,
496
+ lit24: 0x48,
497
+ lit25: 0x49,
498
+ lit26: 0x4a,
499
+ lit27: 0x4b,
500
+ lit28: 0x4c,
501
+ lit29: 0x4d,
502
+ lit30: 0x4e,
503
+ lit31: 0x4f,
504
+ reg0: 0x50,
505
+ reg1: 0x51,
506
+ reg2: 0x52,
507
+ reg3: 0x53,
508
+ reg4: 0x54,
509
+ reg5: 0x55,
510
+ reg6: 0x56,
511
+ reg7: 0x57,
512
+ reg8: 0x58,
513
+ reg9: 0x59,
514
+ reg10: 0x5a,
515
+ reg11: 0x5b,
516
+ reg12: 0x5c,
517
+ reg13: 0x5d,
518
+ reg14: 0x5e,
519
+ reg15: 0x5f,
520
+ reg16: 0x60,
521
+ reg17: 0x61,
522
+ reg18: 0x62,
523
+ reg19: 0x63,
524
+ reg20: 0x64,
525
+ reg21: 0x65,
526
+ reg22: 0x66,
527
+ reg23: 0x67,
528
+ reg24: 0x68,
529
+ reg25: 0x69,
530
+ reg26: 0x6a,
531
+ reg27: 0x6b,
532
+ reg28: 0x6c,
533
+ reg29: 0x6d,
534
+ reg30: 0x6e,
535
+ reg31: 0x6f,
536
+ breg0: 0x70,
537
+ breg1: 0x71,
538
+ breg2: 0x72,
539
+ breg3: 0x73,
540
+ breg4: 0x74,
541
+ breg5: 0x75,
542
+ breg6: 0x76,
543
+ breg7: 0x77,
544
+ breg8: 0x78,
545
+ breg9: 0x79,
546
+ breg10: 0x7a,
547
+ breg11: 0x7b,
548
+ breg12: 0x7c,
549
+ breg13: 0x7d,
550
+ breg14: 0x7e,
551
+ breg15: 0x7f,
552
+ breg16: 0x80,
553
+ breg17: 0x81,
554
+ breg18: 0x82,
555
+ breg19: 0x83,
556
+ breg20: 0x84,
557
+ breg21: 0x85,
558
+ breg22: 0x86,
559
+ breg23: 0x87,
560
+ breg24: 0x88,
561
+ breg25: 0x89,
562
+ breg26: 0x8a,
563
+ breg27: 0x8b,
564
+ breg28: 0x8c,
565
+ breg29: 0x8d,
566
+ breg30: 0x8e,
567
+ breg31: 0x8f,
568
+ regx: 0x90,
569
+ fbreg: 0x91,
570
+ bregx: 0x92,
571
+ piece: 0x93,
572
+ deref_size: 0x94,
573
+ xderef_size: 0x95,
574
+ nop: 0x96,
575
+ push_object_address: 0x97,
576
+ call2: 0x98,
577
+ call4: 0x99,
578
+ call_ref: 0x9a,
579
+ form_tls_address: 0x9b,
580
+ call_frame_cfa: 0x9c,
581
+ bit_piece: 0x9d,
582
+ implicit_value: 0x9e,
583
+ stack_value: 0x9f,
584
+ implicit_pointer: 0xa0,
585
+ addrx: 0xa1,
586
+ constx: 0xa2,
587
+ entry_value: 0xa3,
588
+ const_type: 0xa4,
589
+ regval_type: 0xa5,
590
+ deref_type: 0xa6,
591
+ xderef_type: 0xa7,
592
+ convert: 0xa8,
593
+ reinterpret: 0xa9,
594
+
595
+ GNU_push_tls_address: 0xe0,
596
+ GNU_uninit: 0xf0,
597
+ GNU_encoded_addr: 0xf1,
598
+ GNU_implicit_pointer: 0xf2,
599
+ GNU_entry_value: 0xf3,
600
+ GNU_const_type: 0xf4,
601
+ GNU_regval_type: 0xf5,
602
+ GNU_deref_type: 0xf6,
603
+ GNU_convert: 0xf7,
604
+ GNU_reinterpret: 0xf9,
605
+ GNU_parameter_ref: 0xfa,
606
+ GNU_addr_index: 0xfb,
607
+ GNU_const_index: 0xfc,
608
+ GNU_variable_value: 0xfd
609
+ }).permissive
610
+
611
+ # Line Number Program Standard Opcodes
612
+ StandardOpCodes = CTypes::Enum.new(uint8, {
613
+ copy: 1,
614
+ advance_pc: 2,
615
+ advance_line: 3,
616
+ set_file: 4,
617
+ set_column: 5,
618
+ negate_stmt: 6,
619
+ set_basic_block: 7,
620
+ const_add_pc: 8,
621
+ fixed_advance_pc: 9,
622
+ set_prologue_end: 10,
623
+ set_epilogue_begin: 11,
624
+ set_isa: 12
625
+ }).permissive
626
+
627
+ # Line Number Program Extended Opcodes
628
+ ExtendedOpCodes = CTypes::Enum.new(uint8, {
629
+ end_sequence: 1,
630
+ set_address: 2,
631
+ define_file: 3,
632
+ set_discriminator: 4,
633
+ lo_user: 128,
634
+ hi_user: 255
635
+ }).permissive
636
+ end
637
+ end
638
+
639
+ require_relative "dwarf/expression"
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ctypes"
4
+
5
+ module ElfUtils::Types::Dwarf32::V2
6
+ extend CTypes::Helpers
7
+
8
+ class CU_Header < CTypes::Struct # standard:disable Naming/ClassAndModuleCamelCase
9
+ layout do
10
+ attribute :unit_length, uint32
11
+ attribute :version, uint16
12
+ attribute :debug_abbrev_offset, uint32
13
+ attribute :addr_size, uint8
14
+ attribute :data, string(trim: false)
15
+ size { |h| offsetof(:version) + h[:unit_length] }
16
+ end
17
+
18
+ def format
19
+ :dwarf32
20
+ end
21
+ end
22
+
23
+ # called a "Statement Program Prologue" in the v2 spec, gets renamed to
24
+ # "Line Number Program Header" in v3 spec and above. Using the more modern
25
+ # naming of struct & fields to simplify working with all versions.
26
+ class LineNumberProgramHeader < CTypes::Struct
27
+ layout do
28
+ attribute :unit_length, uint32
29
+ attribute :version, uint16
30
+ attribute :header_length, uint32
31
+ attribute :minimum_instruction_length, uint8
32
+ attribute :default_is_stmt, uint8
33
+ attribute :line_base, int8
34
+ attribute :line_range, uint8
35
+ attribute :opcode_base, uint8
36
+ attribute :_rest, string(trim: false)
37
+ end
38
+
39
+ def addr_type
40
+ CTypes::Helpers.uint32.with_endian(@endian)
41
+ end
42
+ end
43
+ StatementProgramPrologue = LineNumberProgramHeader
44
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ctypes"
4
+
5
+ module ElfUtils::Types::Dwarf32::V3
6
+ extend CTypes::Helpers
7
+
8
+ class CU_Header < CTypes::Struct # standard:disable Naming/ClassAndModuleCamelCase
9
+ layout do
10
+ attribute :unit_length, uint32
11
+ attribute :version, uint16
12
+ attribute :debug_abbrev_offset, uint32
13
+ attribute :addr_size, uint8
14
+ attribute :data, string(trim: false)
15
+ size { |h| offsetof(:version) + h[:unit_length] }
16
+ end
17
+
18
+ def format
19
+ :dwarf32
20
+ end
21
+ end
22
+
23
+ class LineNumberProgramHeader < CTypes::Struct
24
+ layout do
25
+ attribute :unit_length, uint32
26
+ attribute :version, uint16
27
+ attribute :header_length, uint32
28
+ attribute :minimum_instruction_length, uint8
29
+ attribute :default_is_stmt, uint8
30
+ attribute :line_base, int8
31
+ attribute :line_range, uint8
32
+ attribute :opcode_base, uint8
33
+ attribute :_rest, string(trim: false)
34
+ end
35
+
36
+ def addr_type
37
+ CTypes::Helpers.uint32.with_endian(@endian)
38
+ end
39
+ end
40
+ end