Class: Debugger::JumpCommand

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

Overview

Implements debugger “jump” 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

Constructor Details

This class inherits a constructor from Debugger::Command

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Debugger::Command

Class Method Details

.help(cmd) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/ruby-debug/commands/jump.rb', line 62

def help(cmd)
   %{
     j[ump] line\tjump to line number (absolute)
     j[ump] -line\tjump back to line (relative)
     j[ump] +line\tjump ahead to line (relative)

     Change the next line of code to be executed.
    }
end

.help_commandObject



58
59
60
# File 'lib/ruby-debug/commands/jump.rb', line 58

def help_command
  %w[jump]
end

Instance Method Details

#executeObject



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
52
53
54
55
# File 'lib/ruby-debug/commands/jump.rb', line 20

def execute
  unless @state.context.respond_to?(:jump)
    print_msg "Not implemented"
    return
  end
  if !@match[1]
    print_msg "\"jump\" must be followed by a line number"
    return
  end
  if !numeric?(@match[1])
    print_msg "Bad line number: " + @match[1]
    return
  end
  line = @match[1].to_i
  line = @state.context.frame_line(0) + line if @match[1][0] == '+' or @match[1][0] == '-'
  if line == @state.context.frame_line(0)
    return
  end
  file = @match[2]
  file = @state.context.frame_file(file.to_i) if numeric?(file)
  file = @state.context.frame_file(0) if !file
  case @state.context.jump(line, file)
  when 0
    @state.proceed
    return
  when 1
    print_msg "Not possible to jump from here"
  when 2
    print_msg "Couldn't find debugged frame"
  when 3
    print_msg "Couldn't find active code at " + file + ":" + line.to_s
  else
    print_msg "Unknown error occurred"
  end
  @printer.print_at_line(@state.context, @state.context.frame_file, @state.context.frame_line)
end

#numeric?(object) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/ruby-debug/commands/jump.rb', line 7

def numeric?(object)
  true if Float(object) rescue false
end

#regexpObject



11
12
13
14
15
16
17
18
# File 'lib/ruby-debug/commands/jump.rb', line 11

def regexp
  / ^\s*
     j(?:ump)? \s*
     (?:\s+(\S+))?\s*
     (?:\s+(\S+))?\s*
     $
  /ix
end