From 3e34e72f94e30cf7d19356e817cffc56eacb3280 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 8 Jul 2022 17:11:07 +0900 Subject: [PATCH 1/2] ignore not avilable files --- lib/debug/session.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/debug/session.rb b/lib/debug/session.rb index 37ce3abac..f60899751 100644 --- a/lib/debug/session.rb +++ b/lib/debug/session.rb @@ -1376,6 +1376,8 @@ def clear_line_breakpoints path clear_breakpoints do |k, bp| bp.is_a?(LineBreakpoint) && DEBUGGER__.compare_path(k.first, path) end + rescue Errno::ENOENT + # just ignore end def clear_catch_breakpoints *exception_names From b0faeafde13864217e775b1e8d45816ba447fbf8 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 8 Jul 2022 17:35:44 +0900 Subject: [PATCH 2/2] Introduce `UI_DAP.local_to_remote_path` Breakpoint path is given by DAP client (VSCode, etc) and the path should be translated to remote file name by the mapping configulation. This patch introduce `local_to_remote_path` method to do that. Also `local_fs_map_path` is renamed to `remote_to_local_path`. fix https://github.com/ruby/vscode-rdbg/issues/32 --- lib/debug/server_dap.rb | 75 +++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/lib/debug/server_dap.rb b/lib/debug/server_dap.rb index 5c6b8d4b2..a79d2c72a 100644 --- a/lib/debug/server_dap.rb +++ b/lib/debug/server_dap.rb @@ -75,10 +75,10 @@ def show_protocol dir, msg # nil: no localfs @local_fs_map = nil - def self.local_fs_map_path path + def self.remote_to_local_path path case @local_fs_map when nil - false + nil when true path else # Array @@ -92,6 +92,23 @@ def self.local_fs_map_path path end end + def self.local_to_remote_path path + case @local_fs_map + when nil + nil + when true + path + else # Array + @local_fs_map.each do |(remote_path_prefix, local_path_prefix)| + if path.start_with? local_path_prefix + return path.sub(local_path_prefix){ remote_path_prefix } + end + end + + nil + end + end + def self.local_fs_map_set map return if @local_fs_map # already setup @@ -276,21 +293,29 @@ def process end when 'setBreakpoints' - path = args.dig('source', 'path') - SESSION.clear_line_breakpoints path - - bps = [] - args['breakpoints'].each{|bp| - line = bp['line'] - if cond = bp['condition'] - bps << SESSION.add_line_breakpoint(path, line, cond: cond) - else - bps << SESSION.add_line_breakpoint(path, line) - end - } - send_response req, breakpoints: (bps.map do |bp| {verified: true,} end) + req_path = args.dig('source', 'path') + path = UI_DAP.local_to_remote_path(req_path) + + if path + SESSION.clear_line_breakpoints path + + bps = [] + args['breakpoints'].each{|bp| + line = bp['line'] + if cond = bp['condition'] + bps << SESSION.add_line_breakpoint(path, line, cond: cond) + else + bps << SESSION.add_line_breakpoint(path, line) + end + } + send_response req, breakpoints: (bps.map do |bp| {verified: true,} end) + else + send_response req, success: false, message: "#{req_path} is not available" + end + when 'setFunctionBreakpoints' send_response req + when 'setExceptionBreakpoints' process_filter = ->(filter_id, cond = nil) { bp = @@ -302,19 +327,19 @@ def process else nil end - { - verified: !bp.nil?, - message: bp.inspect, + { + verified: !bp.nil?, + message: bp.inspect, + } } - } - SESSION.clear_catch_breakpoints 'Exception', 'RuntimeError' + SESSION.clear_catch_breakpoints 'Exception', 'RuntimeError' - filters = args.fetch('filters').map {|filter_id| - process_filter.call(filter_id) - } + filters = args.fetch('filters').map {|filter_id| + process_filter.call(filter_id) + } - filters += args.fetch('filterOptions', {}).map{|bp_info| + filters += args.fetch('filterOptions', {}).map{|bp_info| process_filter.call(bp_info['filterId'], bp_info['condition']) } @@ -689,7 +714,7 @@ def process_dap args path = frame.realpath || frame.path source_name = path ? File.basename(path) : frame.location.to_s - if (path && File.exist?(path)) && (local_path = UI_DAP.local_fs_map_path(path)) + if (path && File.exist?(path)) && (local_path = UI_DAP.remote_to_local_path(path)) # ok else ref = frame.file_lines