class HeapInfo::Segment
Record the base address and name in maps
Attributes
base[R]
Base address of segment
name[R]
Name of segment
Public Class Methods
find(maps, pattern)
click to toggle source
Helper
for creating a {HeapInfo::Segment}.
Search the specific pattern
in maps
and return a {HeapInfo::Segment} object.
@param [Array] maps maps
is in form of the return value of {Helper::ClassMethods#parse_maps}. @param [Regexp, String] pattern
The segment name want to match in maps. If +String+ is given, the pattern is matched as a substring.
@return [HeapInfo::Segment, nil]
The request {HeapInfo::Segment} object. If the pattern is not matched, instance of {Nil} will be returned.
# File lib/heapinfo/segment.rb, line 45 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
new(base, name)
click to toggle source
Instantiate a {HeapInfo::Segment} object @param [Integer] base Base address @param [String] name Name of segment
# File lib/heapinfo/segment.rb, line 14 def initialize(base, name) @base = base @name = name end
Public Instance Methods
coerce(other)
click to toggle source
To support +addr - h.libc+. Treat all operations are manipulating on base
.
@param [Object] other
Any object.
@return [(Object
, Integer)]
# File lib/heapinfo/segment.rb, line 32 def coerce(other) [other, base] end
to_s()
click to toggle source
Hook #to_s
for pretty printing @return [String] Information of name and base address wrapper with color codes.
# File lib/heapinfo/segment.rb, line 21 def to_s format("%-28s\tbase @ #{Helper.color(format('%#x', base))}\n", Helper.color(name.split('/')[-1])) end