Class: Trepan::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.



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

def initialize
  clear
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



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

def list
  @list
end

#setObject (readonly)

Returns the value of attribute set.



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

def set
  @set
end

Instance Method Details

#<<(brkpt) ⇒ Object



29
30
31
32
# File 'app/brkptmgr.rb', line 29

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

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

Raises:

  • (TypeError)


34
35
36
37
38
39
# File 'app/brkptmgr.rb', line 34

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



60
61
62
63
64
65
# File 'app/brkptmgr.rb', line 60

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

#clearObject



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

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

#delete(index) ⇒ Object



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

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



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

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)


67
68
69
# File 'app/brkptmgr.rb', line 67

def empty?
  @list.empty?
end

#finalizeObject

Remove all breakpoints that we have recorded



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

def finalize
  @list.each do |bp|
    bp.related_bp.each { |bp| bp.remove! }
    bp.remove!
  end
  clear
end

#find(meth, ip) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'app/brkptmgr.rb', line 81

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

#line_breaks(cm) ⇒ Object



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

def line_breaks(cm)
  result = {}
  @list.each do |bp|
    if bp.method == cm
      result[bp.line] = bp 
    end
  end
  result
end

#maxObject



92
93
94
# File 'app/brkptmgr.rb', line 92

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

#resetObject



105
106
107
108
109
# File 'app/brkptmgr.rb', line 105

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.



97
98
99
# File 'app/brkptmgr.rb', line 97

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

#sizeObject



101
102
103
# File 'app/brkptmgr.rb', line 101

def size
  @list.size
end