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
Fixnum.
-
#iseq ⇒ Object
readonly
Returns the value of attribute iseq.
-
#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.
38 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 |
# File 'app/breakpoint.rb', line 38 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)
Fixnum. Number of times encountered to ignore
14 15 16 |
# File 'app/breakpoint.rb', line 14 def ignore @ignore end |
#iseq ⇒ Object (readonly)
Returns the value of attribute iseq.
15 16 17 |
# File 'app/breakpoint.rb', line 15 def iseq @iseq end |
#negate ⇒ Object (readonly)
Fixnum. Offset into an instruction sequence for the location of the breakpoint
21 22 23 |
# File 'app/breakpoint.rb', line 21 def negate @negate end |
#offset ⇒ Object (readonly)
Instruction sequence associated with this breakpoint. From this we can derive information such as source location.
18 19 20 |
# File 'app/breakpoint.rb', line 18 def offset @offset end |
#type ⇒ Object (readonly)
Boolean. Negate sense of condition. Used in break if .. and break unless .. breakpoint
24 25 26 |
# File 'app/breakpoint.rb', line 24 def type @type end |
Class Method Details
.reset ⇒ Object
Really shouldn’t need this after next_id is removed.
128 129 130 |
# File 'app/breakpoint.rb', line 128 def self.reset @@next_id = 1 end |
Instance Method Details
#condition?(bind) ⇒ Boolean
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/breakpoint.rb', line 69 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
83 84 85 |
# File 'app/breakpoint.rb', line 83 def disable @enabled = false end |
#enabled ⇒ Object
87 88 89 |
# File 'app/breakpoint.rb', line 87 def enabled @enabled = true end |
#enabled=(bool) ⇒ Object
91 92 93 |
# File 'app/breakpoint.rb', line 91 def enabled=(bool) @enabled = bool end |
#enabled? ⇒ Boolean
95 96 97 |
# File 'app/breakpoint.rb', line 95 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
103 104 105 |
# File 'app/breakpoint.rb', line 103 def icon_char temp? ? 't' : (enabled? ? 'B' : 'b') end |
#remove! ⇒ Object
123 124 125 |
# File 'app/breakpoint.rb', line 123 def remove! @iseq.brkpt_unset(@offset) end |
#set ⇒ Object
107 108 109 |
# File 'app/breakpoint.rb', line 107 def set @iseq.brkpt_set(@offset) end |
#source_container ⇒ Object
111 112 113 |
# File 'app/breakpoint.rb', line 111 def source_container @iseq.source_container end |
#source_location ⇒ Object
115 116 117 |
# File 'app/breakpoint.rb', line 115 def source_location @iseq.offset2lines(@offset) end |
#temp? ⇒ Boolean
119 120 121 |
# File 'app/breakpoint.rb', line 119 def temp? @temp end |