-
Notifications
You must be signed in to change notification settings - Fork 138
Description
Your environment
ruby -v
: 2.7.2p137rdbg -v
: 1.6.2
Describe the bug
With certain binary data in a variable, the DAP server fails to dump the frame data and crashes
To Reproduce
I originally detected this when using protobuf, as the inspect
method uses interpolates its value
(which is binary data) into the string that describes it.
A simple way to reproduce is:
- Create a file like:
class PassthroughInspect
def initialize(data)
@data = data
end
def inspect
@data
end
end
with_binary_data = PassthroughInspect.new([8, 200, 1].pack('CCC'))
puts("Put a breakpoint here!")
- Use VSCode, add a breakpoint to the last line, and start debugging
- Immediately after reaching the breakpoint, the session will end
Expected behavior
The debugging session shouldn't crash
Additional context
To debug this, you can add something like this to the same file you are debugging:
require 'json'
JSON.instance_eval do
class << self
alias unsafe_dump dump
end
def dump(obj, *args)
unsafe_dump(obj, *args)
rescue StandardError => e
puts("There was an exception dumping the state: #{e}")
puts("The backtrace is: #{e.backtrace&.join('\n')}")
puts("The offending object is #{obj}")
end
end
This shows that the problem is source sequence is illegal/malformed utf-8
, and the trace is:
<redacted>/json-2.3.1/lib/json/common.rb:430:in `generate'
<redacted>/json-2.3.1/lib/json/common.rb:430:in `generate'
<redacted>/json-2.3.1/lib/json/common.rb:629:in `dump'
target.rb:11:in `dump' # this is the test file
<redacted>/debug-1.6.2/lib/debug/server_dap.rb:206:in `send'
<redacted>/debug-1.6.2/lib/debug/server_dap.rb:220:in `send_response'
<redacted>/debug-1.6.2/lib/debug/server_dap.rb:441:in `respond'
<redacted>/debug-1.6.2/lib/debug/server_dap.rb:650:in `dap_event'
<redacted>/debug-1.6.2/lib/debug/session.rb:307:in `process_event'
<redacted>/debug-1.6.2/lib/debug/session.rb:204:in `session_server_main'
<redacted>/debug-1.6.2/lib/debug/session.rb:174:in `block in activate'
The problem is that the any
variable in my example now has binary data as its value, and when ruby/debug tries to dump it into a String that can send over DAP, JSON complains about it not being a utf-8 string.