Class: Byebug::BreakCommand

Inherits:
Command
  • Object
show all
Includes:
Helpers::EvalHelper, Helpers::FileHelper, Helpers::ParseHelper
Defined in:
lib/byebug/commands/break.rb

Overview

Implements breakpoint functionality

Instance Attribute Summary

Attributes inherited from Command

#processor

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::ParseHelper

#get_int, #parse_steps, #syntax_valid?

Methods included from Helpers::FileHelper

#get_line, #get_lines, #n_lines, #normalize, #shortpath, #virtual_file?

Methods included from Helpers::EvalHelper

#error_eval, #multiple_thread_eval, #separate_thread_eval, #silent_eval, #warning_eval

Methods inherited from Command

#arguments, columnize, #context, #frame, help, #initialize, match, to_s

Methods included from Helpers::StringHelper

#camelize, #prettify

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/byebug/commands/break.rb', line 21

def self.description
  <<-EOD
    b[reak] [file:]line [if expr]
    b[reak] [module::...]class(.|#)method [if expr]

    They can be specified by line or method and an expression can be added
    for conditionally enabled breakpoints.

    #{short_description}
  EOD
end

.regexpObject



17
18
19
# File 'lib/byebug/commands/break.rb', line 17

def self.regexp
  /^\s* b(?:reak)? (?:\s+ (.+?))? (?:\s+ if \s+(.+))? \s*$/x
end

.short_descriptionObject



33
34
35
# File 'lib/byebug/commands/break.rb', line 33

def self.short_description
  'Sets breakpoints in the source code'
end

Instance Method Details

#executeObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/byebug/commands/break.rb', line 37

def execute
  return puts(help) unless @match[1]

  b = line_breakpoint(@match[1]) || method_breakpoint(@match[1])
  return errmsg(pr('break.errors.location')) unless b

  if syntax_valid?(@match[2])
    return puts(pr('break.created', id: b.id, file: b.source, line: b.pos))
  end

  errmsg(pr('break.errors.expression', expr: @match[2]))
  b.enabled = false
end