Class: Trepanning::Breakpoint

Inherits:
Object
  • Object
show all
Defined in:
app/breakpoint.rb

Constant Summary collapse

BRKPT_DEFAULT_SETTINGS =
{
  :condition => 'true',
  :enabled   => 'true',
  :temp      =>  false,
  :event     =>  :Unknown,
}
@@next_id =
1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, method, ip, line, id = nil, opts = {}) ⇒ Breakpoint

Returns a new instance of Breakpoint.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/breakpoint.rb', line 30

def initialize(name, method, ip, line, id=nil, opts = {})
  @descriptor = name
  @id = id
  @method = method
  @ip = ip
  @line = line

  # If not nil, is a Rubinius::VariableScope. This is what we 
  # check to have call-frame-specific breakpoints.
  @scope = nil

  @related_bp = []

  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

  @set = false
end

Instance Attribute Details

#conditionObject

Returns the value of attribute condition.



4
5
6
# File 'app/breakpoint.rb', line 4

def condition
  @condition
end

#descriptorObject (readonly)

Returns the value of attribute descriptor.



57
58
59
# File 'app/breakpoint.rb', line 57

def descriptor
  @descriptor
end

#eventObject (readonly)

If non-nil, this is a String to be eval’d which must be true to enter the debugger



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

def event
  @event
end

#hitsObject

Symbol. Optional type of event associated with breakpoint.



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

def hits
  @hits
end

#idObject (readonly)

Fixnum. The number of timea a breakpoint has been hit (with a true condition). Do we want to (also) record hits independent of the condition?



12
13
14
# File 'app/breakpoint.rb', line 12

def id
  @id
end

#ipObject (readonly)

Returns the value of attribute ip.



57
58
59
# File 'app/breakpoint.rb', line 57

def ip
  @ip
end

#lineObject (readonly)

Returns the value of attribute line.



57
58
59
# File 'app/breakpoint.rb', line 57

def line
  @line
end

#methodObject (readonly)

Returns the value of attribute method.



57
58
59
# File 'app/breakpoint.rb', line 57

def method
  @method
end

Returns the value of attribute related_bp.



58
59
60
# File 'app/breakpoint.rb', line 58

def related_bp
  @related_bp
end

Class Method Details

.for_ip(exec, ip, opts = {}) ⇒ Object



23
24
25
26
27
28
# File 'app/breakpoint.rb', line 23

def self.for_ip(exec, ip, opts={})
  name = opts[:name] || :anon
  line = exec.line_from_ip(ip)

  Breakpoint.new(name, exec, ip, line, nil, opts)
end

Instance Method Details

#activateObject



80
81
82
83
# File 'app/breakpoint.rb', line 80

def activate
  @set = true
  @method.set_breakpoint @ip, self
end

#delete!Object

def condition?(bind)

if eval(@condition, bind)
  if @ignore > 0
    @ignore -= 1
    return false
  else
    @hits += 1
    return true
  end
else
  return false
end

end



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

def delete!
  remove!
end

#describeObject



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

def describe
  "#{descriptor} - #{location}"
end

#disableObject



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

def disable
  @enabled = false
end

#enabledObject



124
125
126
# File 'app/breakpoint.rb', line 124

def enabled
  @enabled = true
end

#enabled=(bool) ⇒ Object



128
129
130
# File 'app/breakpoint.rb', line 128

def enabled=(bool)
  @enabled = bool
end

#enabled?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'app/breakpoint.rb', line 132

def enabled?
  @enabled
end

#hit!(test_scope) ⇒ Object

Return true if the breakpoint is relevant. That is, the breakpoint is either not a scoped or it is scoped and test_scope matches the desired scope. We also remove the breakpoint and any related breakpoints if it was hit and temporary.



89
90
91
92
93
94
95
96
# File 'app/breakpoint.rb', line 89

def hit!(test_scope)
  return true unless @temp
  return false if @scope && test_scope != @scope

  @related_bp.each { |bp| bp.remove! }
  remove!
  return true
end

#icon_charObject

Return a one-character “icon” giving the state of the breakpoint ‘t’: temporary breakpoint ‘B’: enabled breakpoint ‘b’: disabled breakpoint



140
141
142
# File 'app/breakpoint.rb', line 140

def icon_char
  temp? ? 't' : (enabled? ? 'B' : 'b')
end

#locationObject



144
145
146
# File 'app/breakpoint.rb', line 144

def location
  "#{@method.active_path}:#{@line} (@#{ip})"
end


73
74
75
76
77
78
# File 'app/breakpoint.rb', line 73

def related_with(bp)
  @related_bp += [bp] + bp.related_bp
  @related_bp.uniq!
  # List of related breakpoints should be shared.
  bp.related_bp = @related_bp
end

#remove!Object



148
149
150
151
152
153
# File 'app/breakpoint.rb', line 148

def remove!
  return unless @set

  @set = false
  @method.clear_breakpoint(@ip)
end

#scoped!(scope, temp = true) ⇒ Object



60
61
62
63
# File 'app/breakpoint.rb', line 60

def scoped!(scope, temp = true)
  @temp = temp
  @scope = scope
end

#scoped?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/breakpoint.rb', line 69

def scoped?
  !!@scope
end

#set_temp!Object



65
66
67
# File 'app/breakpoint.rb', line 65

def set_temp!
  @temp = true
end

#temp?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'app/breakpoint.rb', line 155

def temp?
  @temp
end