Class: DEBUGGER__::Breakpoint

Inherits:
Object
  • Object
show all
Includes:
Color, SkipPathHelper
Defined in:
lib/debug/breakpoint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Color

#color_pp, #colored_inspect, #colorize, #colorize_blue, #colorize_code, #colorize_cyan, #colorize_dim, #colorize_magenta, #irb_colorize, #with_inspection_error_guard

Methods included from SkipPathHelper

#skip_config_skip_path?, #skip_internal_path?, #skip_location?

Constructor Details

#initialize(cond, command, path, do_enable: true) ⇒ Breakpoint

Returns a new instance of Breakpoint.



11
12
13
14
15
16
17
18
19
20
# File 'lib/debug/breakpoint.rb', line 11

def initialize cond, command, path, do_enable: true
  @deleted = false

  @cond = cond
  @command = command
  @path = path

  setup
  enable if do_enable
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/debug/breakpoint.rb', line 9

def key
  @key
end

#skip_srcObject (readonly)

Returns the value of attribute skip_src.



9
10
11
# File 'lib/debug/breakpoint.rb', line 9

def skip_src
  @skip_src
end

Instance Method Details

#deleteObject



52
53
54
55
# File 'lib/debug/breakpoint.rb', line 52

def delete
  disable
  @deleted = true
end

#deleted?Boolean

Returns:

  • (Boolean)


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

def deleted?
  @deleted
end

#descriptionObject



80
81
82
# File 'lib/debug/breakpoint.rb', line 80

def description
  to_s
end

#disableObject



44
45
46
# File 'lib/debug/breakpoint.rb', line 44

def disable
  @tp&.disable
end

#duplicable?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/debug/breakpoint.rb', line 84

def duplicable?
  false
end

#enableObject



40
41
42
# File 'lib/debug/breakpoint.rb', line 40

def enable
  @tp.enable
end

#enabled?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/debug/breakpoint.rb', line 48

def enabled?
  @tp.enabled?
end

#generate_label(name) ⇒ Object



101
102
103
# File 'lib/debug/breakpoint.rb', line 101

def generate_label(name)
  colorize(" BP - #{name} ", [:YELLOW, :BOLD, :REVERSE])
end

#oneshot?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/debug/breakpoint.rb', line 32

def oneshot?
  defined?(@oneshot) && @oneshot
end

#safe_eval(b, expr) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/debug/breakpoint.rb', line 22

def safe_eval b, expr
  b.eval(expr)
rescue Exception => e
  puts "[EVAL ERROR]"
  puts "  expr: #{expr}"
  puts "  err: #{e} (#{e.class})"
  puts "Error caused by #{self}."
  nil
end

#setupObject



36
37
38
# File 'lib/debug/breakpoint.rb', line 36

def setup
  raise "not implemented..."
end

#skip_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
91
92
93
94
95
96
97
# File 'lib/debug/breakpoint.rb', line 88

def skip_path?(path)
  case @path
  when Regexp
    !path.match?(@path)
  when String
    !path.include?(@path)
  else
    super
  end
end

#suspendObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/debug/breakpoint.rb', line 61

def suspend
  if @command
    provider, pre_cmds, do_cmds = @command
    nonstop = true if do_cmds
    cmds = [*pre_cmds&.split(';;'), *do_cmds&.split(';;')]
    SESSION.add_preset_commands provider, cmds, kick: false, continue: nonstop
  end

  ThreadClient.current.on_breakpoint @tp, self
end

#to_sObject



72
73
74
75
76
77
78
# File 'lib/debug/breakpoint.rb', line 72

def to_s
  s = ''.dup
  s << " if: #{@cond}"        if defined?(@cond) && @cond
  s << " pre: #{@command[1]}" if defined?(@command) && @command && @command[1]
  s << " do: #{@command[2]}"  if defined?(@command) && @command && @command[2]
  s
end