class DEBUGGER__::SourceRepository - debug: Ruby Standard Library Documentation

# class DEBUGGER__::SourceRepository

### Constants

SrcInfo

  ruby 3.0 or earlier

### Public Class Methods

new() click to toggle source

    # File debug-1.10.0/lib/debug/source_repository.rb, line 30
    def initialize
      # cache
      @cmap = ObjectSpace::WeakMap.new
      @loaded_file_map = {} # path => nil
    end

### Public Instance Methods

add(iseq, src) click to toggle source

    # File debug-1.10.0/lib/debug/source_repository.rb, line 36
    def add iseq, src
      # only manage loaded file names
      if (path = (iseq.absolute_path || iseq.path)) && File.exist?(path)
        if @loaded_file_map.has_key? path
          return path, true # reloaded
        else
          @loaded_file_map[path] = path
          return path, false
        end
      end
    end

add_iseq(iseq, src) click to toggle source

    # File debug-1.10.0/lib/debug/source_repository.rb, line 104
            def add_iseq iseq, src
      line = iseq.first_line
      if line > 1
        src = ("\n" * (line - 1)) + src
      end

      si = SrcInfo.new(src.each_line.map{|l| l.chomp})
      all_iseq(iseq).each{|e|
        e.instance_variable_set(:@debugger_si, si)
        e.freeze
      }
    end

add_path(path) click to toggle source

    # File debug-1.10.0/lib/debug/source_repository.rb, line 117
            def add_path path
      src_lines = File.readlines(path, chomp: true)
      @files[path] = SrcInfo.new(src_lines)
    rescue SystemCallError
    end

all_iseq(iseq, rs = []) click to toggle source

    # File debug-1.10.0/lib/debug/source_repository.rb, line 96
            def all_iseq iseq, rs = []
      rs << iseq
      iseq.each_child{|ci|
        all_iseq(ci, rs)
      }
      rs
    end

file_src(iseq) click to toggle source

    # File debug-1.10.0/lib/debug/source_repository.rb, line 9
    def file_src iseq
      if (path = (iseq.absolute_path || iseq.path)) && File.exist?(path)
        File.readlines(path, chomp: true)
      end
    end

get(iseq) click to toggle source

    # File debug-1.10.0/lib/debug/source_repository.rb, line 15
    def get iseq
      return unless iseq

      if CONFIG[:show_evaledsrc]
        orig_src(iseq) || file_src(iseq)
      else
        file_src(iseq) || orig_src(iseq)
      end
    end

get_colored(iseq) click to toggle source

    # File debug-1.10.0/lib/debug/source_repository.rb, line 58
    def get_colored iseq
      if lines = @cmap[iseq]
        lines
      else
        if src_lines = get(iseq)
          @cmap[iseq] = colorize_code(src_lines.join("\n")).lines
        else
          nil
        end
      end
    end

get_si(iseq) click to toggle source

    # File debug-1.10.0/lib/debug/source_repository.rb, line 123
            def get_si iseq
      return unless iseq

      if iseq.instance_variable_defined?(:@debugger_si)
        iseq.instance_variable_get(:@debugger_si)
      elsif @files.has_key?(path = (iseq.absolute_path || iseq.path))
        @files[path]
      elsif path
        add_path(path)
      end
    end

orig_src(iseq) click to toggle source

    # File debug-1.10.0/lib/debug/source_repository.rb, line 48
    def orig_src iseq
      lines = iseq.script_lines&.map(&:chomp)
      line = iseq.first_line
      if line > 1
        [*([''] * (line - 1)), *lines]
      else
        lines
      end
    end