Class: Trepan::Breakpoint
- Inherits:
-
Object
- Object
- Trepan::Breakpoint
- Defined in:
- app/breakpoint.rb
Constant Summary collapse
- BRKPT_DEFAULT_SETTINGS =
{ :condition => 'true', :enabled => 'true', :ignore => 0, :temp => false, :negate => false, :type => 'line', }
- @@next_id =
String. ‘line’ if breakpoint requested at “line” boundary or ‘offset’ requested at a specific offset
1
Instance Attribute Summary collapse
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#hits ⇒ Object
If non-nil, this is a String to be eval’d which must be true to enter the debugger.
-
#id ⇒ Object
readonly
Fixnum.
-
#ignore ⇒ Object
readonly
Returns the value of attribute ignore.
-
#iseq ⇒ Object
readonly
Fixnum.
-
#negate ⇒ Object
readonly
Fixnum.
-
#offset ⇒ Object
readonly
Instruction sequence associated with this breakpoint.
-
#type ⇒ Object
readonly
Boolean.
Class Method Summary collapse
-
.reset ⇒ Object
Really shouldn’t need this after next_id is removed.
Instance Method Summary collapse
- #condition?(bind) ⇒ Boolean
- #disable ⇒ Object
- #enabled ⇒ Object
- #enabled=(bool) ⇒ Object
- #enabled? ⇒ Boolean
-
#icon_char ⇒ Object
Return a one-character “icon” giving the state of the breakpoint ‘t’: temporary breakpoint ‘B’: enabled breakpoint ‘b’: disabled breakpoint.
-
#initialize(iseq, offset, opts = {}) ⇒ Breakpoint
constructor
A new instance of Breakpoint.
- #remove! ⇒ Object
- #set ⇒ Object
- #source_container ⇒ Object
- #source_location ⇒ Object
- #temp? ⇒ Boolean
Constructor Details
#initialize(iseq, offset, opts = {}) ⇒ Breakpoint
Returns a new instance of Breakpoint.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/breakpoint.rb', line 39 def initialize(iseq, offset, opts = {}) raise TypeError, "#{iseq} is not an instruction sequence" unless iseq.is_a?(RubyVM::InstructionSequence) @iseq = iseq raise TypeError, "offset #{offset.inspect} not found in instruction sequence" unless iseq.offset2lines(offset) @offset = iseq raise TypeError, "type mismatch: #{offset.class} given, Fixnum expected" unless offset.is_a?(Fixnum) @offset = offset opts = BRKPT_DEFAULT_SETTINGS.merge(opts) opts.keys.each do |key| self.instance_variable_set('@'+key.to_s, opts[key]) end @hits = 0 unless @id @id = @@next_id @@next_id += 1 end raise RuntimeError, "Unable to set breakpoint in #{iseq.name} at offset #{@offset}" unless set end |
Instance Attribute Details
#condition ⇒ Object
Returns the value of attribute condition.
7 8 9 |
# File 'app/breakpoint.rb', line 7 def condition @condition end |
#hits ⇒ Object
If non-nil, this is a String to be eval’d which must be true to enter the debugger
9 10 11 |
# File 'app/breakpoint.rb', line 9 def hits @hits end |
#id ⇒ Object (readonly)
Fixnum. The number of times a breakpoint has been hit (with a true condition). Do we want to (also) record hits independent of the condition?
13 14 15 |
# File 'app/breakpoint.rb', line 13 def id @id end |
#ignore ⇒ Object (readonly)
Returns the value of attribute ignore.
14 15 16 |
# File 'app/breakpoint.rb', line 14 def ignore @ignore end |
#iseq ⇒ Object (readonly)
Fixnum. Number of times to ignore before triggering
16 17 18 |
# File 'app/breakpoint.rb', line 16 def iseq @iseq end |
#negate ⇒ Object (readonly)
Fixnum. Offset into an instruction sequence for the location of the breakpoint
22 23 24 |
# File 'app/breakpoint.rb', line 22 def negate @negate end |
#offset ⇒ Object (readonly)
Instruction sequence associated with this breakpoint. From this we can derive information such as source location.
19 20 21 |
# File 'app/breakpoint.rb', line 19 def offset @offset end |
#type ⇒ Object (readonly)
Boolean. Negate sense of condition. Used in break if .. and break unless .. breakpoint
25 26 27 |
# File 'app/breakpoint.rb', line 25 def type @type end |
Class Method Details
.reset ⇒ Object
Really shouldn’t need this after next_id is removed.
130 131 132 |
# File 'app/breakpoint.rb', line 130 def self.reset @@next_id = 1 end |
Instance Method Details
#condition?(bind) ⇒ Boolean
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/breakpoint.rb', line 71 def condition?(bind) if @negate != eval(@condition, bind) if @ignore > 0 @ignore -= 1 return false else @hits += 1 return true end else return false end end |
#disable ⇒ Object
85 86 87 |
# File 'app/breakpoint.rb', line 85 def disable @enabled = false end |
#enabled ⇒ Object
89 90 91 |
# File 'app/breakpoint.rb', line 89 def enabled @enabled = true end |
#enabled=(bool) ⇒ Object
93 94 95 |
# File 'app/breakpoint.rb', line 93 def enabled=(bool) @enabled = bool end |
#enabled? ⇒ Boolean
97 98 99 |
# File 'app/breakpoint.rb', line 97 def enabled? @enabled end |
#icon_char ⇒ Object
Return a one-character “icon” giving the state of the breakpoint ‘t’: temporary breakpoint ‘B’: enabled breakpoint ‘b’: disabled breakpoint
105 106 107 |
# File 'app/breakpoint.rb', line 105 def icon_char temp? ? 't' : (enabled? ? 'B' : 'b') end |
#remove! ⇒ Object
125 126 127 |
# File 'app/breakpoint.rb', line 125 def remove! @iseq.brkpt_unset(@offset) end |
#set ⇒ Object
109 110 111 |
# File 'app/breakpoint.rb', line 109 def set @iseq.brkpt_set(@offset) end |
#source_container ⇒ Object
113 114 115 |
# File 'app/breakpoint.rb', line 113 def source_container @iseq.source_container end |
#source_location ⇒ Object
117 118 119 |
# File 'app/breakpoint.rb', line 117 def source_location @iseq.offset2lines(@offset) end |
#temp? ⇒ Boolean
121 122 123 |
# File 'app/breakpoint.rb', line 121 def temp? @temp end |