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



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

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



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

def names
  %w(save)
end

Instance Method Details

#executeObject



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

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



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

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

#save_breakpoints(file) ⇒ Object



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

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



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

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

#save_displays(file) ⇒ Object



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

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

#save_settings(file) ⇒ Object



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

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