Sha256: 7a0bd260150900e9fcf21fb78b032d44157b785d8c2a05ec25dce6362650f760

Contents?: true

Size: 1.62 KB

Versions: 18

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require "byebug/command"

module Byebug
  #
  # Save current settings to use them in another debug session.
  #
  class SaveCommand < Command
    self.allow_in_control = true
    self.allow_in_post_mortem = true

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

    def self.description
      <<-DESCRIPTION
        save[ FILE]

        #{short_description}

        Byebug state is saved as a script file. This includes breakpoints,
        catchpoints, display expressions and some settings. If no filename is
        given, byebug will fabricate one.

        Use the "source" command in another debug session to restore the saved
        file.
      DESCRIPTION
    end

    def self.short_description
      "Saves current byebug session to a file"
    end

    def execute
      file = File.open(@match[1] || Setting[:savefile], "w")

      save_breakpoints(file)
      save_catchpoints(file)
      save_displays(file)
      save_settings(file)

      print pr("save.messages.done", path: file.path)
      file.close
    end

    private

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

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

    def save_displays(file)
      Byebug.displays.each { |d| file.puts "display #{d[1]}" if d[0] }
    end

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

Version data entries

18 entries across 18 versions & 8 rubygems

Version Path
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/byebug-10.0.2/lib/byebug/commands/save.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/byebug-10.0.2/lib/byebug/commands/save.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/byebug-10.0.2/lib/byebug/commands/save.rb
talon_one-2.0.0 vendor/bundle/ruby/2.3.0/gems/byebug-11.0.1/lib/byebug/commands/save.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/byebug-11.0.1/lib/byebug/commands/save.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/byebug-11.0.1/lib/byebug/commands/save.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/byebug-11.0.1/lib/byebug/commands/save.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/byebug-10.0.2/lib/byebug/commands/save.rb
byebug-11.0.1 lib/byebug/commands/save.rb
byebug-11.0.0 lib/byebug/commands/save.rb
jets-0.5.5 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/commands/save.rb
jets-0.5.4 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/commands/save.rb
jets-0.5.3 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/commands/save.rb
jets-0.5.2 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/commands/save.rb
jets-0.5.1 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/commands/save.rb
byebug-10.0.2 lib/byebug/commands/save.rb
byebug-10.0.1 lib/byebug/commands/save.rb
byebug-10.0.0 lib/byebug/commands/save.rb