class Metasm::ELF::DwarfDebug

Attributes

tree[RW]

Public Instance Methods

decode(elf, info, abbrev, str) click to toggle source

decode a DWARF2 'compilation unit'

Calls superclass method Metasm::SerialStruct#decode
# File metasm/exe_format/elf_decode.rb, line 747
def decode(elf, info, abbrev, str)
        super(elf, info)
        len = @cu_len-7      # @cu_len is size from end of @cu_len field, so we substract ptsz/tag/abroff
        info.ptr += len      # advance for caller
        info = info[info.ptr-len, len]       # we'll work on our segment
        abbrev.ptr = @abbrev_off

        return if abbrev.ptr >= abbrev.length or info.ptr >= info.length

        idx_abbroff = {}

        # returns a list of siblings at current abbrev.ptr
        decode_tree = lambda { |parent|
                siblings = []
                loop {
                        info_idx = elf.decode_leb(info)
                        break siblings if info_idx == 0
                        abbrev.ptr = idx_abbroff[info_idx] if idx_abbroff[info_idx]
                        idx_abbroff[info_idx] ||= abbrev.ptr
                        n = DwarfDebug::Node.decode(elf, info, abbrev, str, idx_abbroff)
                        idx_abbroff[info_idx+1] ||= abbrev.ptr
                        siblings << n
                        n.children = decode_tree[n] if n.has_child == 1
                        n.parent = parent
                        break n if not parent
                }
        }
        @tree = decode_tree[nil]
end