Class: Byebug::SaveCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/byebug/commands/save.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

commands, find, format_subcmd, format_subcmds, help, inherited, #initialize, load_commands, #match

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



71
72
73
74
75
76
77
78
# File 'lib/byebug/commands/save.rb', line 71

def description
  %{save[ FILE]

    Saves current byebug state to FILE as a script file. This includes
    breakpoints, catchpoints, display expressions and some settings. If
    no filename is given, we will fabricate one.
    Use the "source" command in another debug session to restore them.}
end

.namesObject



67
68
69
# File 'lib/byebug/commands/save.rb', line 67

def names
  %w(save)
end

Instance Method Details

#executeObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/byebug/commands/save.rb', line 49

def execute
  if not @match[1]
    file = open_save()
  else
    file = open(@match[1], 'w')
  end
  save_breakpoints(file)
  save_catchpoints(file)
  save_displays(file)
  save_settings(file)
  print "Saved to '#{file.path}'\n"
  if @state and @state.interface
    @state.interface.restart_file = file.path
  end
  file.close
end

#regexpObject



45
46
47
# File 'lib/byebug/commands/save.rb', line 45

def regexp
  /^\s* sa(?:ve)? (?:\s+(\S+))? \s*$/x
end

#save_breakpoints(file) ⇒ Object



18
19
20
21
22
# File 'lib/byebug/commands/save.rb', line 18

def save_breakpoints(file)
  Byebug.breakpoints.each do |b|
    file.puts "break #{b.source}:#{b.pos}#{" if #{b.expr}" if b.expr}"
  end
end

#save_catchpoints(file) ⇒ Object



24
25
26
27
28
# File 'lib/byebug/commands/save.rb', line 24

def save_catchpoints(file)
  Byebug.catchpoints.keys.each do |c|
    file.puts "catch #{c}"
  end
end

#save_displays(file) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/byebug/commands/save.rb', line 30

def save_displays(file)
  for d in @state.display
    if d[0]
      file.puts "display #{d[1]}"
    end
  end
end

#save_settings(file) ⇒ Object



38
39
40
41
42
43
# File 'lib/byebug/commands/save.rb', line 38

def save_settings(file)
  # FIXME put routine in set
  %w(autoeval autoirb autolist basename testing).each do |setting|
    file.puts "set #{setting} #{Setting[setting.to_sym]}"
  end
end