Class: Squash::Symbolicator::Symbols

Inherits:
Object
  • Object
show all
Includes:
Enumerable, SerialBox
Defined in:
lib/squash/symbolicator/symbols.rb

Overview

An aggregation of the ‘Symbolicator::Symbol`s of a binary. This class is enumerable.

Instance Method Summary collapse

Constructor Details

#initializeSymbols

Creates a new empty aggregation.



51
52
53
# File 'lib/squash/symbolicator/symbols.rb', line 51

def initialize
  @symbols = Array.new
end

Instance Method Details

#[](*args) ⇒ Object

Delegated to ‘Array`.



92
# File 'lib/squash/symbolicator/symbols.rb', line 92

def [](*args) @symbols[*args] end

#add(start_address, end_address, file, line, symbol) ⇒ Object

Adds a symbol definition to the aggregation.

Parameters:

  • start_address (Fixnum)

    The lowest program counter address corresponding to this method or function.

  • end_address (Fixnum)

    The highest program counter address corresponding to this method or function.

  • file (String)

    The path to the file where this symbol is declared.

  • line (Fixnum)

    The line number in ‘file` where this symbol is declared.

  • symbol (String)

    The method or function name.



66
67
68
69
70
71
72
73
74
75
# File 'lib/squash/symbolicator/symbols.rb', line 66

def add(start_address, end_address, file, line, symbol)
  index   = @symbols.find_index { |sym| sym.start_address > start_address || (sym.start_address == start_address && sym.end_address >= end_address) }
  new_sym = Squash::Symbolicator::Symbol.new(start_address, end_address, file, line, symbol)

  if index
    @symbols.insert index, new_sym
  else
    @symbols << new_sym
  end
end

#clear(*args) ⇒ Object

Delegated to ‘Array`.



94
# File 'lib/squash/symbolicator/symbols.rb', line 94

def clear(*args) @symbols.clear(*args) end

#each(*args) ⇒ Object

Delegated to ‘Array`.



90
# File 'lib/squash/symbolicator/symbols.rb', line 90

def each(*args) @symbols.each(*args) end

#for(address) ⇒ Symbol?

Returns the ‘Symbolicator::Symbol` containing a given program counter address. If there are symbols with overlapping address ranges, the one with the smallest range is returned.

Parameters:

  • address (Fixnum)

    A program counter address.

Returns:

  • (Symbol, nil)

    The symbol corresponding to that address, or ‘nil` if the address is not symbolicated.



85
86
87
# File 'lib/squash/symbolicator/symbols.rb', line 85

def for(address)
  @symbols.detect { |sym| sym.start_address <= address && sym.end_address >= address }
end

#inspectObject



99
# File 'lib/squash/symbolicator/symbols.rb', line 99

def inspect() "#<#{self.class} [#{size} symbols]>" end

#size(*args) ⇒ Object

Delegated to ‘Array`.



96
# File 'lib/squash/symbolicator/symbols.rb', line 96

def size(*args) @symbols.size(*args) end