Repository navigation
Description
Your environment
ruby -v:3.1.2rdbg -v:1.7.0
Describe the bug
Breakpoints added via VS Code seems to be lost after surrounding code is modified and reloaded by Rails.
For example, if we set a breakpoint at
def index
@posts = Post.all # set the breakpoint at this line
endAnd then we insert a new line to the method:
def index
puts "foo"
@posts = Post.all # VS Code would move the breakpoint here after update
endThe breakpoint would not be triggered anymore.
To Reproduce
-
Clone this repo.
-
Run
$ bundle install. -
Run
$ bundle exec bin/rails db:migrate RAILS_ENV=development. -
Run
$ bundle exec rdbg -O -n -c -- bundle exec bin/rails sto run the server with debugger in server mode. -
Press
F5to attach VS Code to the debugger. -
Go to
app/controllers/posts_controller.rband place an VS Code breakpoint at line6.def index @posts = Post.all # set the breakpoint at this line end
-
Verify the breakpoint can be hit:
- In browser, visit http://localhost:3000.
- See the breakpoint being hit.
- Press
F5again to continue the program.
-
Add
puts "foo"atapp/controllers/posts_controller.rb:6def index puts "foo" @posts = Post.all end
-
Refresh the page in browser.
Expected behavior
VS Code breakpoints can still trigger after the file is updated.
Additional context
-
When updating other methods, like adding something to the
newmethod (10 lines away), the breakpoint still works. So I suspect it's related to the breakpoint's iseq being outdated? -
From DAP server logs, it looks like the debugger does receive updated
setBreakpointsrequest:
#25986:[>] {"command":"setBreakpoints","arguments":{"source":{"path":"/Users/hung-wulo/src/github.com/st0012/debug-issue/app/controllers/posts_controller.rb","name":"posts_controller.rb","sourceReference":0},"lines":[6],"breakpoints":[{"line":6}],"sourceModified":true},"type":"request","seq":13}
#25986:[<] {"type":"response","command":"setBreakpoints","request_seq":13,"success":true,"message":"Success","body":{"breakpoints":[{"verified":true}]},"seq":977}
But the breakpoint wasn't actually added/activated.
Activity
st0012 commentedon Dec 16, 2022
I think it's related to
LineBreakpoint's@pendingstate:After the first breakpoint hit, the later breakpoint would has
@iseqlikeAnd this means its
@pendingstate would befalse.So when the
:script_compiledevent is triggeredbps_pending_until_load?would also befalseThreadClient.current.on_loadwouldn't be triggered for the updated codeLineBreakpointsBut I'm not sure which part is the root cause of the issue:
@iseqstill benil?bps_pending_until_load?also take the bps' file path into consideration?Workaround
As a quick workaround, changing
bps_pending_until_load?to just do@bps.any?seems to work.Workaround ruby#870
Workaround ruby#870
Workaround ruby#870
crobbo commentedon Jan 13, 2023
Nothing to add other than to comment I have also been experiencing this bug. For the breakpoints to start registering after changing the code I have restart the server and attach the debug session again.
A fix for this would be great!
ko1 commentedon Mar 25, 2023
ko1 commentedon Mar 25, 2023
Sorry it is not a correct repro-code.
It needs VSCode interaction.
ko1 commentedon Mar 25, 2023
All right, I repro it.
and next
foodoesn't stop.ko1 commentedon Mar 25, 2023
This is repro-code.
remain breakpoints on reloaded files
remain breakpoints on reloaded files
Merge v1.7.2 (#9)