Class: Trepan::BreakpointMgr
- Inherits:
-
Object
- Object
- Trepan::BreakpointMgr
- Defined in:
- app/brkptmgr.rb
Instance Attribute Summary collapse
-
#list ⇒ Object
readonly
Returns the value of attribute list.
-
#set ⇒ Object
readonly
Returns the value of attribute set.
Instance Method Summary collapse
- #<<(brkpt) ⇒ Object
- #[](index) ⇒ Object (also: #detect)
- #add(*args) ⇒ Object
- #clear ⇒ Object
- #delete(index) ⇒ Object
- #delete_by_brkpt(delete_bp) ⇒ Object
- #empty? ⇒ Boolean
-
#finalize ⇒ Object
Remove all breakpoints that we have recorded.
- #find(iseq, offset, bind) ⇒ Object
-
#initialize ⇒ BreakpointMgr
constructor
A new instance of BreakpointMgr.
- #line_breaks(container) ⇒ Object
- #max ⇒ Object
- #reset ⇒ Object
-
#set_key(bp) ⇒ Object
Key used in @set to list unique instruction-sequence offsets.
- #size ⇒ Object
Constructor Details
#initialize ⇒ BreakpointMgr
Returns a new instance of BreakpointMgr.
10 11 12 |
# File 'app/brkptmgr.rb', line 10 def initialize clear end |
Instance Attribute Details
#list ⇒ Object (readonly)
Returns the value of attribute list.
7 8 9 |
# File 'app/brkptmgr.rb', line 7 def list @list end |
#set ⇒ Object (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
28 29 30 31 |
# File 'app/brkptmgr.rb', line 28 def <<(brkpt) @list << brkpt @set.add(set_key(brkpt)) end |
#[](index) ⇒ Object Also known as: detect
33 34 35 36 37 38 |
# File 'app/brkptmgr.rb', line 33 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
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/brkptmgr.rb', line 59 def add(*args) if args[2] unless args[2].member?(:id) args[2][:id] = @next_id @next_id += 1 end else args[2] = {:id => @next_id} @next_id += 1 end brkpt = Trepan::Breakpoint.new(*args) @list << brkpt @set.add(set_key(brkpt)) return brkpt end |
#clear ⇒ Object
14 15 16 17 18 |
# File 'app/brkptmgr.rb', line 14 def clear @list = [] @next_id = 1 @set = Set.new end |
#delete(index) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'app/brkptmgr.rb', line 42 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
52 53 54 55 56 57 |
# File 'app/brkptmgr.rb', line 52 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
76 77 78 |
# File 'app/brkptmgr.rb', line 76 def empty? @list.empty? end |
#finalize ⇒ Object
Remove all breakpoints that we have recorded
21 22 23 24 25 26 |
# File 'app/brkptmgr.rb', line 21 def finalize @list.each do |bp| bp.remove! end clear end |
#find(iseq, offset, bind) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'app/brkptmgr.rb', line 92 def find(iseq, offset, bind) @list.detect do |bp| if bp.enabled? && bp.iseq.equal?(iseq) && bp.offset == offset begin return bp if bp.condition?(bind) rescue end end end end |
#line_breaks(container) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/brkptmgr.rb', line 80 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 |
#max ⇒ Object
103 104 105 |
# File 'app/brkptmgr.rb', line 103 def max @list.map{|bp| bp.id}.max end |
#reset ⇒ Object
116 117 118 119 120 |
# File 'app/brkptmgr.rb', line 116 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.
108 109 110 |
# File 'app/brkptmgr.rb', line 108 def set_key(bp) [bp.iseq, bp.offset] end |
#size ⇒ Object
112 113 114 |
# File 'app/brkptmgr.rb', line 112 def size @list.size end |