Class: BreakpointMgr

Inherits:
Object
  • Object
show all
Defined in:
app/brkptmgr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBreakpointMgr

Returns a new instance of BreakpointMgr.



10
11
12
13
# File 'app/brkptmgr.rb', line 10

def initialize
  @list = []
  @set = Set.new
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



7
8
9
# File 'app/brkptmgr.rb', line 7

def list
  @list
end

#setObject (readonly)

Returns the value of attribute set.



8
9
10
# File 'app/brkptmgr.rb', line 8

def set
  @set
end

Instance Method Details

#<<(brkpt) ⇒ Object



15
16
17
18
# File 'app/brkptmgr.rb', line 15

def <<(brkpt)
  @list << brkpt
  @set.add(set_key(brkpt))
end

#[](index) ⇒ Object Also known as: detect

Raises:

  • (TypeError)


20
21
22
23
24
25
# File 'app/brkptmgr.rb', line 20

def [](index)
  raise TypeError, 
  "index #{index} should be a Fixnum, is #{index.class}" unless
    index.is_a?(Fixnum)
  @list.detect {|bp| bp.id == index }
end

#add(*args) ⇒ Object



46
47
48
49
50
51
# File 'app/brkptmgr.rb', line 46

def add(*args)
  brkpt = Trepanning::Breakpoint.new(*args)
  @list << brkpt
  @set.add(set_key(brkpt))
  return brkpt
end

#delete(index) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'app/brkptmgr.rb', line 29

def delete(index)
  bp = detect(index)
  if bp
    delete_by_brkpt(bp)
    return bp
  else
    return nil
  end
end

#delete_by_brkpt(delete_bp) ⇒ Object



39
40
41
42
43
44
# File 'app/brkptmgr.rb', line 39

def delete_by_brkpt(delete_bp)
  @list = @list.reject{|candidate| candidate == delete_bp}
  @set  = Set.new(@list.map{|bp| set_key(bp)})
  delete_bp.remove! unless @set.member?(set_key(delete_bp))
  return delete_bp
end

#empty?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/brkptmgr.rb', line 53

def empty?
  @list.empty?
end

#find(meth, ip) ⇒ Object

def line_breaks(container)

result = {}
@list.each do |bp|
  if bp.source_container == container
    bp.source_location.each do |line|
      result[line] = bp 
    end
  end
end
result

end



69
70
71
72
73
74
75
76
77
78
# File 'app/brkptmgr.rb', line 69

def find(meth, ip)
  @list.detect do |bp| 
    if bp.enabled? && bp.ip == ip
      begin
        return bp ## if bp.condition?(bind)
      rescue
      end 
    end
  end
end

#maxObject



80
81
82
# File 'app/brkptmgr.rb', line 80

def max
  @list.map{|bp| bp.id}.max || 0
end

#resetObject



93
94
95
96
97
# File 'app/brkptmgr.rb', line 93

def reset
  @list.each{|bp| bp.remove!}
  @list = []
  @set  = Set.new
end

#set_key(bp) ⇒ Object

Key used in @set to list unique instruction-sequence offsets.



85
86
87
# File 'app/brkptmgr.rb', line 85

def set_key(bp)
  [bp.method, bp.ip]
end

#sizeObject



89
90
91
# File 'app/brkptmgr.rb', line 89

def size
  @list.size
end