Sha256: 0f4d40c67305ee36be9ec4a16891016baa02dc60f3829279f9e176d66647e7b3

Contents?: true

Size: 1.52 KB

Versions: 3

Compression:

Stored size: 1.52 KB

Contents

# -*- coding: utf-8 -*-
# Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
require_relative 'base/cmd'
require_relative '../../app/run'
class Trepan::Command::RestartCommand < Trepan::Command

  unless defined?(HELP)
    NAME         = File.basename(__FILE__, '.rb')
    ALIASES      = %w(R run)
    HELP = <<-HELP
#{NAME} 

Restart debugger and program via an exec call. All state is lost, and
new copy of the debugger is used.
    HELP
    
    CATEGORY     = 'running'
    MAX_ARGS     = 0  # Need at most this many
    SHORT_HELP  = '(Hard) restart of program via exec()'
  end
    
  # This method runs the command
  def run(args)

    dbgr = @proc.dbgr
    argv = dbgr.restart_argv
    if argv and argv.size > 0
      # unless File.executable?(argv[0])
      #   msg(["File #{argv[0]} not executable.",
      #        "Adding Ruby interpreter."])
      #   argv.unshift Trepanning::ruby_path
      # end
      @proc.run_cmd(%w(show args))
      if not confirm('Restart (exec)?', false)
        msg "Restart not confirmed"
      else
        msg 'Restarting...'
        @proc.run_cmd(%w(save))
        # FIXME: Run atexit finalize routines?
        Dir.chdir(RubyVM::OS_STARTUP_DIR)
        exec(*argv)
      end
    else
      errmsg("No executable file and command options recorded.")
    end
  end
end

if __FILE__ == $0
  exit if ARGV[-1] == 'exit'
  require_relative '../mock'
  dbgr, cmd = MockDebugger::setup
  dbgr.restart_argv = []
  cmd.run([cmd.name])
  dbgr.restart_argv = RubyVM::OS_ARGV + ['exit']
  cmd.run([cmd.name])
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
trepanning-0.1.0 processor/command/restart.rb
trepanning-0.0.9 processor/command/restart.rb
trepanning-0.0.8 processor/command/restart.rb