class Byebug::CommandProcessor - byebug-4.0.5 Documentation

# class Byebug::CommandProcessor

Processes commands in regular mode

### Attributes

display[R]
state[R]

### Public Class Methods

new(interface = LocalInterface.new) click to toggle source
Calls superclass method Byebug::Processor.new

    # File lib/byebug/processors/command_processor.rb, line 10
    def initialize(interface = LocalInterface.new)
      super(interface)

      @display = []
      @last_cmd = nil # To allow empty (just <RET>) commands
      @context_was_dead = false # Assume we haven't started.
    end

### Public Instance Methods

at_breakpoint(_context, breakpoint) click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 25
    def at_breakpoint(_context, breakpoint)
      n = Byebug.breakpoints.index(breakpoint) + 1
      file = normalize(breakpoint.source)
      line = breakpoint.pos

      puts "Stopped by breakpoint #{n} at #{file}:#{line}"
    end

at_catchpoint(context, excpt) click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 33
    def at_catchpoint(context, excpt)
      file = normalize(context.frame_file(0))
      line = context.frame_line(0)

      puts "Catchpoint at #{file}:#{line}: `#{excpt}' (#{excpt.class})"
    end

at_line(context, file, line) click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 46
    def at_line(context, file, line)
      process_commands(context, file, line)
    end

at_return(context, file, line) click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 50
    def at_return(context, file, line)
      process_commands(context, file, line)
    end

at_tracing(context, file, line) click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 40
    def at_tracing(context, file, line)
      puts "Tracing: #{normalize(file)}:#{line} #{get_line(file, line)}"

      always_run(context, file, line, 2)
    end

interface=(interface) click to toggle source

    # File lib/byebug/processors/command_processor.rb, line 18
    def interface=(interface)
      @interface.close if @interface
      @interface = interface
    end

### Private Instance Methods

always_run(context, file, line, run_level) click to toggle source

Run commands everytime.

For example display commands or possibly the list or irb in an “autolist” or “autoirb”.

@return List of commands acceptable to run bound to the current state

    # File lib/byebug/processors/command_processor.rb, line 71
    def always_run(context, file, line, run_level)
      @state = RegularState.new(context, @display, file, @interface, line)

      # Change default when in irb or code included in command line
      Setting[:autolist] = false if ['(irb)', '-e'].include?(file)

      # Bind commands to the current state.
      Command.commands.each do |cmd|
        cmd.new(state).execute if cmd.always_run >= run_level
      end
    end

match_cmd(input) click to toggle source

Finds a matches the command matching the input

    # File lib/byebug/processors/command_processor.rb, line 147
    def match_cmd(input)
      Command.commands.each do |c|
        cmd = c.new(state)
        return cmd if cmd.match(input)
      end

      nil
    end

one_cmd(context, input) click to toggle source

Executes a single byebug command

    # File lib/byebug/processors/command_processor.rb, line 132
    def one_cmd(context, input)
      cmd = match_cmd(input)

      return one_unknown_cmd(input) unless cmd

      if context.dead? && !cmd.class.allow_in_post_mortem
        return errmsg('Command unavailable in post mortem mode.')
      end

      cmd.execute
    end

one_unknown_cmd(input) click to toggle source

Autoevals a single command

    # File lib/byebug/processors/command_processor.rb, line 118
    def one_unknown_cmd(input)
      unless Setting[:autoeval]
        return errmsg("Unknown command: \"#{input}\". Try \"help\"")
      end

      eval_cmd = EvalCommand.new(state)
      eval_cmd.match(input)
      eval_cmd.execute
    end

process_commands(context, file, line) click to toggle source

Handle byebug commands.

    # File lib/byebug/processors/command_processor.rb, line 86
    def process_commands(context, file, line)
      always_run(context, file, line, 1)

      puts 'The program finished.' if program_just_finished?(context)
      puts(state.location) if Setting[:autolist] == 0

      @interface.autorestore

      repl(context)
    ensure
      @interface.autosave
    end

program_just_finished?(context) click to toggle source

Returns true first time control is given to the user after program termination.

    # File lib/byebug/processors/command_processor.rb, line 160
    def program_just_finished?(context)
      result = context.dead? && !@context_was_dead
      @context_was_dead = false if result == true
      result
    end

prompt(context) click to toggle source

Prompt shown before reading a command.

    # File lib/byebug/processors/command_processor.rb, line 59
    def prompt(context)
      "(byebug#{context.dead? ? ':post-mortem' : ''}) "
    end

repl(context) click to toggle source

Main byebug's REPL

    # File lib/byebug/processors/command_processor.rb, line 102
    def repl(context)
      until state.proceed?
        cmd = @interface.read_command(prompt(context))
        return unless cmd

        next if cmd == '' && @last_cmd.nil?

        cmd.empty? ? cmd = @last_cmd : @last_cmd = cmd

        one_cmd(context, cmd)
      end
    end