Class: ElfUtils::Types::Dwarf::Expression Private

Inherits:
Object
  • Object
show all
Defined in:
lib/elf_utils/types/dwarf/expression.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(cu, bytes) ⇒ Expression

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Expression.



3
4
5
6
# File 'lib/elf_utils/types/dwarf/expression.rb', line 3

def initialize(cu, bytes)
  @cu = cu
  @bytes = bytes
end

Instance Method Details

#evaluate(addr_type:, stack: [0]) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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
# File 'lib/elf_utils/types/dwarf/expression.rb', line 8

def evaluate(addr_type:, stack: [0])
  return @result if @result

  buf = @bytes
  until buf.empty?
    op, buf = Types::Dwarf::Operation.unpack_one(buf)
    case op
    when :plus_uconst
      a = stack.pop
      b, buf = Types::ULEB128.unpack_one(buf)
      stack.push(a + b)
    when :addr
      v, buf = addr_type.unpack_one(buf)
      stack.push(v)
    when :addrx
      index, buf = Types::ULEB128.unpack_one(buf)
      stack.push(@cu.debug_addr_get!(index))
    when nil
      # noop
    else
      raise Error, "unsupported DWARF operation: %p" % [op]
    end
  end
  @result = stack.freeze
end