Skip to content

🐛 Respect skip_path when returning the backtrace in ServerDAP #749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/debug/server_dap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,10 @@ def process_dap args
frames = []
@target_frames.each_with_index do |frame, i|
next if i < start_frame
break if (levels -= 1) < 0

path = frame.realpath || frame.path
next if skip_path?(path)
break if (levels -= 1) < 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now needs to be after deciding to skip or not, or we'd return less frames that required

source_name = path ? File.basename(path) : frame.location.to_s

if (path && File.exist?(path)) && (local_path = UI_DAP.remote_to_local_path(path))
Expand Down
62 changes: 62 additions & 0 deletions test/protocol/call_stack_with_skip_dap_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# frozen_string_literal: true

require_relative '../support/protocol_test_case'

module DEBUGGER__
class CallStackWithSkipDAPTest < ProtocolTestCase
def program(path)
<<~RUBY
1| require_relative "#{path}"
2| with_foo do
3| "something"
4| end
RUBY
end

def extra_file
<<~RUBY
def with_foo
yield
end
RUBY
end

def req_stacktrace_file_names
response = send_dap_request('stackTrace', threadId: 1)
stack_frames = response.dig(:body, :stackFrames)
stack_frames.map { |f| f.dig(:source, :name) }
end

def test_it_does_not_skip_a_path
with_extra_tempfile do |extra_file|
run_protocol_scenario(program(extra_file.path), cdp: false) do
req_add_breakpoint 3
req_continue

assert_equal(
[File.basename(temp_file_path), File.basename(extra_file.path), File.basename(temp_file_path)],
req_stacktrace_file_names
)

req_terminate_debuggee
end
end
end

def test_it_skips_a_path
with_extra_tempfile do |extra_file|
ENV['RUBY_DEBUG_SKIP_PATH'] = extra_file.path
run_protocol_scenario(program(extra_file.path), cdp: false) do
req_add_breakpoint 3
req_continue

assert_equal([File.basename(temp_file_path), File.basename(temp_file_path)], req_stacktrace_file_names)

req_terminate_debuggee
end
end
ensure
ENV['RUBY_DEBUG_SKIP_PATH'] = nil
end
end
end