Class: Trepan::Breakpoint

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(iseq, offset, opts = {}) ⇒ Breakpoint

Returns a new instance of Breakpoint.

Raises:

  • (TypeError)


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

#conditionObject

Returns the value of attribute condition.



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

def condition
  @condition
end

#hitsObject

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

#idObject (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

#ignoreObject (readonly)

Fixnum. Number of times encountered to ignore



14
15
16
# File 'app/breakpoint.rb', line 14

def ignore
  @ignore
end

#iseqObject (readonly)

Returns the value of attribute iseq.



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

def iseq
  @iseq
end

#negateObject (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

#offsetObject (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

#typeObject (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

.resetObject

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

Returns:

  • (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

#disableObject



83
84
85
# File 'app/breakpoint.rb', line 83

def disable
  @enabled = false
end

#enabledObject



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

Returns:

  • (Boolean)


95
96
97
# File 'app/breakpoint.rb', line 95

def enabled?
  @enabled
end

#icon_charObject

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

#setObject



107
108
109
# File 'app/breakpoint.rb', line 107

def set
  @iseq.brkpt_set(@offset)
end

#source_containerObject



111
112
113
# File 'app/breakpoint.rb', line 111

def source_container
  @iseq.source_container
end

#source_locationObject



115
116
117
# File 'app/breakpoint.rb', line 115

def source_location
  @iseq.offset2lines(@offset)
end

#temp?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'app/breakpoint.rb', line 119

def temp?
  @temp
end