Class: HeapInfo::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/heapinfo/segment.rb

Overview

Record the base address and name in maps

Direct Known Subclasses

Libc

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, name) ⇒ Segment

Instantiate a HeapInfo::Segment object


11
12
13
14
# File 'lib/heapinfo/segment.rb', line 11

def initialize(base, name)
  @base = base
  @name = name
end

Instance Attribute Details

#baseObject (readonly)

Base address of segment


5
6
7
# File 'lib/heapinfo/segment.rb', line 5

def base
  @base
end

#nameObject (readonly)

Name of segment


7
8
9
# File 'lib/heapinfo/segment.rb', line 7

def name
  @name
end

Class Method Details

.find(maps, pattern) ⇒ HeapInfo::Segment?

Helper for creating a HeapInfo::Segment.

Search the specific pattern in maps and return a HeapInfo::Segment object.


42
43
44
45
46
# File 'lib/heapinfo/segment.rb', line 42

def self.find(maps, pattern)
  return Nil.new if pattern.nil?
  needs = maps.select { |m| pattern.is_a?(Regexp) ? m[3] =~ pattern : m[3].include?(pattern) }
  new(needs.map(&:first).min, needs[0][3]) unless needs.empty?
end

Instance Method Details

#coerce(other) ⇒ (Object, Integer)

To support addr - h.libc. Treat all operations are manipulating on base.


29
30
31
# File 'lib/heapinfo/segment.rb', line 29

def coerce(other)
  [other, base]
end

#to_sString

Hook #to_s for pretty printing


18
19
20
# File 'lib/heapinfo/segment.rb', line 18

def to_s
  format("%-28s\tbase @ #{Helper.color(format('%#x', base))}\n", Helper.color(name.split('/')[-1]))
end