Class: ElfUtils::Section::DebugAbbrev::Abbreviation
- Inherits:
-
Object
- Object
- ElfUtils::Section::DebugAbbrev::Abbreviation
- Extended by:
- Forwardable
- Defined in:
- lib/elf_utils/section/debug_abbrev/abbreviation.rb
Defined Under Namespace
Classes: UnsupportedDwarfAttributeFormError
Instance Attribute Summary collapse
-
#decl ⇒ Object
readonly
Returns the value of attribute decl.
Instance Method Summary collapse
- #attrs ⇒ Object
- #children? ⇒ Boolean
- #die_size(addr_size:, offset_size:) ⇒ Object
-
#initialize(table, decl) ⇒ Abbreviation
constructor
A new instance of Abbreviation.
- #pretty_print(q) ⇒ Object
- #unpack_die(buf:, endian:, offset_type:, addr_type:) ⇒ Object
- #variable_sized_attrs(addr_size:, offset_size:) ⇒ Object
Constructor Details
#initialize(table, decl) ⇒ Abbreviation
Returns a new instance of Abbreviation.
9 10 11 12 |
# File 'lib/elf_utils/section/debug_abbrev/abbreviation.rb', line 9 def initialize(table, decl) @table = table @decl = decl end |
Instance Attribute Details
#decl ⇒ Object (readonly)
Returns the value of attribute decl.
13 14 15 |
# File 'lib/elf_utils/section/debug_abbrev/abbreviation.rb', line 13 def decl @decl end |
Instance Method Details
#attrs ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/elf_utils/section/debug_abbrev/abbreviation.rb', line 33 def attrs @attrs ||= begin attrs = {} @decl.attribute_specifications.each do |attr| attrs[attr.name] = attr.form end attrs.freeze end end |
#children? ⇒ Boolean
29 30 31 |
# File 'lib/elf_utils/section/debug_abbrev/abbreviation.rb', line 29 def children? @decl.children == 1 end |
#die_size(addr_size:, offset_size:) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/elf_utils/section/debug_abbrev/abbreviation.rb', line 43 def die_size(addr_size:, offset_size:) return nil if @variable_size size = 0 @decl.attribute_specifications.each do |attr| if (s = form_size(form: attr.form, addr_size:, offset_size:)) size += s else @variable_size = true return nil end end size end |
#pretty_print(q) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/elf_utils/section/debug_abbrev/abbreviation.rb', line 16 def pretty_print(q) q.group(4, "<%p [%d] DW_TAG_%s DW_CHILDREN_%s" % [self.class, code, tag, children? ? "yes" : "no"], ">") do q.text("\n" + " " * q.indent) q.seplist(@decl.attribute_specifications) do |attr| q.text("DW_AT_%-15s DW_FORM_%s" % [attr.name, attr.form]) end end end |
#unpack_die(buf:, endian:, offset_type:, addr_type:) ⇒ Object
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 |
# File 'lib/elf_utils/section/debug_abbrev/abbreviation.rb', line 67 def unpack_die(buf:, endian:, offset_type:, addr_type:) out = [] @decl.attribute_specifications.each do |attr| value, buf = case attr.form when :addr addr_type.unpack_one(buf, endian: endian) when :strp, :sec_offset offset_type.unpack_one(buf, endian: endian) when :data1, :flag, :ref1, :strx1 CTypes::UInt8.unpack_one(buf, endian: endian) when :data2, :ref2 CTypes::UInt16.unpack_one(buf, endian: endian) when :data4, :ref4 CTypes::UInt32.unpack_one(buf, endian: endian) when :data8, :ref8 CTypes::UInt64.unpack_one(buf, endian: endian) when :udata, :addrx Types::ULEB128.unpack_one(buf) when :sdata Types::SLEB128.unpack_one(buf) when :string CTypes::String.terminated.unpack_one(buf, endian: endian) when :block1 len, buf = CTypes::UInt8.unpack_one(buf, endian: endian) [buf.byteslice(0, len), buf.byteslice(len..)] when :block2 len, buf = CTypes::UInt16.unpack_one(buf, endian: endian) [buf.byteslice(0, len), buf.byteslice(len..)] when :exprloc len, buf = Types::ULEB128.unpack_one(buf) [buf.byteslice(0, len), buf.byteslice(len..)] when :loclistx Types::ULEB128.unpack_one(buf) when :flag_present [1, buf] else raise UnsupportedDwarfAttributeFormError, "unsupported DWARF form: %p" % [attr.form] end out << [attr.name, attr.form, value] end [out, buf] end |
#variable_sized_attrs(addr_size:, offset_size:) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/elf_utils/section/debug_abbrev/abbreviation.rb', line 58 def variable_sized_attrs(addr_size:, offset_size:) out = [] @decl.attribute_specifications.each do |attr| next if form_size(form: attr.form, addr_size:, offset_size:) out << attr end out end |