Class: Debugger::ListCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/ruby-debug/commands/list.rb

Overview

Implements debugger “list” command.

Constant Summary

Constants inherited from Command

Command::DEF_OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

commands, #find, inherited, #initialize, load_commands, #match, method_missing, options, register_setting_get, register_setting_set, register_setting_var, settings, settings_map

Constructor Details

This class inherits a constructor from Debugger::Command

Class Method Details

.help(cmd) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/ruby-debug/commands/list.rb', line 58

def help(cmd)
  %{
    l[ist]\t\tlist forward
    l[ist] -\tlist backward
    l[ist] =\tlist current line
    l[ist] nn-mm\tlist given lines
    * NOTE - to turn on autolist, use 'set autolist'
  }
end

.help_commandObject



54
55
56
# File 'lib/ruby-debug/commands/list.rb', line 54

def help_command
  'list'
end

Instance Method Details

#executeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ruby-debug/commands/list.rb', line 19

def execute
  listsize = Command.settings[:listsize]
  if !@match || !(@match[1] || @match[2])
    b = @state.previous_line ? 
    @state.previous_line + listsize : @state.line - (listsize/2)
    e = b + listsize - 1
  elsif @match[1] == '-'
    b = if @state.previous_line
          if  @state.previous_line > 0
            @state.previous_line - listsize 
          else
            @state.previous_line
          end
        else 
          @state.line - (listsize/2)
        end
    e = b + listsize - 1
  elsif @match[1] == '='
    @state.previous_line = nil
    b = @state.line - (listsize/2)
    e = b + listsize -1
  else
    b, e = @match[2].split(/[-,]/)
    if e
      b = b.to_i
      e = e.to_i
    else
      b = b.to_i - (listsize/2)
      e = b + listsize - 1
    end
  end
  @state.previous_line = display_list(b, e, @state.file, @state.line)
end

#regexpObject



15
16
17
# File 'lib/ruby-debug/commands/list.rb', line 15

def regexp
  /^\s* l(?:ist)? (?:\s*([-=])|\s+(.+))? $/x
end