Class: Rubinius::Debugger::Command::ListCode

Inherits:
Rubinius::Debugger::Command show all
Defined in:
lib/rubinius/debugger/commands.rb

Instance Method Summary collapse

Methods inherited from Rubinius::Debugger::Command

commands, #current_frame, #current_method, descriptor, ext_help, help, #initialize, #listen, match?, pattern, #run_code, #variables

Methods included from Display

#ask, #crit, #display, #error, #info, #section

Constructor Details

This class inherits a constructor from Rubinius::Debugger::Command

Instance Method Details

#run(args) ⇒ Object



716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
# File 'lib/rubinius/debugger/commands.rb', line 716

def run(args)
  path         = nil
  line         = nil
  lines_around = 10

  if args =~ /^[\w#{File::Separator}]+(\.rb)?:\d+$/
    path, line = args.split(':')
    line = line.to_i
  elsif args.nil?
    line = if @debugger.variables[:list_command_history][:center_line]
      @debugger.variables[:list_command_history][:center_line] + 1 + lines_around
    else
      @debugger.current_frame.line.to_i
    end
    path = @debugger.variables[:list_command_history][:path] || @debugger.current_frame.method.active_path
  elsif args == "-"
    if @debugger.variables[:list_command_history][:center_line].nil? || @debugger.variables[:list_command_history][:path].nil?
      return
    else
      line = @debugger.variables[:list_command_history][:center_line] - lines_around
      path = @debugger.variables[:list_command_history][:path]
    end
  elsif args =~ /^\d+$/
    line = args.to_i
    path = @debugger.current_frame.method.active_path
  elsif match = /^(\d+),(\d+)$/.match(args)
    start_line = match[1].to_i
    end_line   = match[2].to_i
    path       = @debugger.current_frame.method.active_path

    @debugger.list_code_range(path, start_line, end_line, end_line)
    return
  else
    error 'Invalid args for list'
    return
  end

   @debugger.list_code_around_line(path, line, lines_around)
end