From d4beeebcaa5a675197fb8bf1edea27e148610d55 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Mon, 21 Feb 2022 17:29:05 +0900 Subject: [PATCH] use `ISeq#path` with `ISeq#absolute_path` From Ruby 3.1, a path given by eval does not return by `ISeq#absolute_path`. fix #479 With this fix, use `File.readlines(chomp: true)`. --- lib/debug/source_repository.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/debug/source_repository.rb b/lib/debug/source_repository.rb index ccad1c033..4dcdf2e03 100644 --- a/lib/debug/source_repository.rb +++ b/lib/debug/source_repository.rb @@ -26,7 +26,11 @@ def get iseq if lines = iseq.script_lines&.map(&:chomp) lines else - nil + if (path = (iseq.absolute_path || iseq.path)) && File.exist?(path) + File.readlines(path, chomp: true) + else + nil + end end end @@ -50,7 +54,7 @@ def initialize end def add iseq, src - if (path = iseq.absolute_path) && File.exist?(path) + if (path = (iseq.absolute_path || iseq.path)) && File.exist?(path) add_path path elsif src add_iseq iseq, src @@ -78,9 +82,8 @@ def add iseq, src end private def add_path path - src = File.read(path) - src = src.gsub("\r\n", "\n") # CRLF -> LF - @files[path] = SrcInfo.new(src.lines) + src_lines = File.readlines(path, chomp: true) + @files[path] = SrcInfo.new(src_lines) rescue SystemCallError end @@ -89,7 +92,7 @@ def add iseq, src if iseq.instance_variable_defined?(:@debugger_si) iseq.instance_variable_get(:@debugger_si) - elsif @files.has_key?(path = iseq.absolute_path) + elsif @files.has_key?(path = (iseq.absolute_path || iseq.path)) @files[path] elsif path add_path(path) @@ -105,7 +108,7 @@ def get iseq def get_colored iseq if si = get_si(iseq) si.colored || begin - si.colored = colorize_code(si.src.join).lines + si.colored = colorize_code(si.src.join("\n")).lines end end end