Class: Debugger::SaveCommand

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

Overview

:nodoc:

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



79
80
81
82
83
84
85
86
87
# File 'lib/ruby-debug/commands/save.rb', line 79

def help(cmd)
  %{
save [FILE]
Saves current debugger 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

.help_commandObject



75
76
77
# File 'lib/ruby-debug/commands/save.rb', line 75

def help_command
  'save'
end

Instance Method Details

#executeObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ruby-debug/commands/save.rb', line 57

def execute
  if not @match[1] or @match[1].strip.empty?
    file = open_save()
  else
    file = open(@match[1], 'w')
  end
  save_breakpoints(file)
  save_catchpoints(file)
  # save_displays(file)
  save_settings(file)
  print pr("save.messages.done", path: file.path)
  if @state and @state.interface
    @state.interface.restart_file = file.path
  end
  file.close
end

#regexpObject



51
52
53
54
55
# File 'lib/ruby-debug/commands/save.rb', line 51

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

#save_breakpoints(file) ⇒ Object



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

def save_breakpoints(file)
  Debugger.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/ruby-debug/commands/save.rb', line 25

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

#save_displays(file) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/ruby-debug/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
45
46
47
48
49
# File 'lib/ruby-debug/commands/save.rb', line 39

def save_settings(file)
  # FIXME put routine in set
  %w(autoeval basename debuggertesting).each do |setting|
    on_off = show_onoff(Command.settings[setting.to_sym])
    file.puts "set #{setting} #{on_off}"
  end
  %w(autolist autoirb).each do |setting|
    on_off = show_onoff(Command.settings[setting.to_sym] > 0)
    file.puts "set #{setting} #{on_off}"
  end
end