-
Notifications
You must be signed in to change notification settings - Fork 80
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
Breakpoints come back if removed during a hot restart #1529
Comments
Thanks @DanTup for reporting this! I removed my previous message because I realized I need to experiment with it a bit first:) will ask more questions when I know what potential solutions are. |
@DanTup a question -
Is there a call to If there is not such call, dwds would not know that the breakpoint needs to be removed. Maybe we can then add it in dart-code, even if there are no current isolates? |
Oh, that's a good question. There is not in the log above, because the previous isolate has exited, and the new isolate has not started. So there is no isolate to send a breakpoint for. Is this a difference with web versus the VM? My assumption is that for normal VM:
It seems like here, dwds is trying to preserve breakpoints itself across the old/new isolate, which is what causes the issue - because VS Code/DAP does not know about this - it believes breakpoints only exist that it has sent (which are per-isolate). We perhaps could change VS Code/DAP to understand breakpoints that are added that it did not request, although I don't know how simple that'll be without doing digging (or whether it might change any other behaviour), although I wonder whether dwds behaviour should try to match the VM? |
Web does not support hot reload yet (ie both buttons just hot restart)
Some questions to help clarify the intended behavior: @bkonyi do you know if this is the expected behavior of the VM? I was not aware that IDEs track breakpoints between hot restarts. @grouma do you remember by any chance why we needed to keep track of breakpoints in dwds between hot restarts? Do we have vm service uses without IDEs that can set/remove dart breakpoints and hot restart? Dwds (which is running inside flutter tools) keeps track of breakpoints currently. We remove all breakpoints before hot restart so hot restart can continue, and put them back right after hot restart has finished and a new isolate is created. So if a breakpoint is removed in-between isolates, dwds would need to see a Depending on the answers to the questions above, we can remove the tracking altogether or keep it as is. |
I don't think this will work for a few different reasons:
|
Actually, DAP does allow us to send breakpoint events to the editor.. In theory, we could detect the new breakpoint being re-added (assuming there's an event for it) and send it back to the editor, so it would show up again (so the UI is in-sync with the VM Service). But it would require some work to support that and it would still result in a sub-optimal experience ("I removed a breakpoint and it came back a few seconds later") so if we can fix it a better way, I think that would be better. I wonder if the reason for the breakpoints being persisted is because web pretends to hot reload (where an IDE expects them to persist and doesn't re-send them) but actually restarts? I've never really been a fan of that behaviour though, because it means the user has two buttons in the IDE labelled Hot Reload and Hot Restart that both do the same thing. This is pretty confusing IMO (users may wonder why Hot Reload isn't preserving state as they're taught it should). I think originally the Hot Reload service was not loaded, and in VS Code this would disable Hot Reload and we changed the on-save behaviour to fall back to Hot Restart - that seemed much clearer to me (for ex. the progress notification when saving would show "Hot Restarting..." instead of "Hot Reloading..."). (I also think changing the isolate ID when the IDE things it's just hot reloading could lead to other issues, because the IDE may be tracking which isolates it has sent breakpoints for - although I'd have to test/check the code to understand the implications of that) |
Hot restart creates a completely new isolate, so breakpoints aren't persisted. Hot reload replaces modified script objects in the VM. Since breakpoints are tied to these objects and the VM doesn't know how to re-map these breakpoints, breakpoints aren't persisted in modified files after a hot reload. It's up to the client to reset these breakpoints (part of the reason we added the client synchronization capabilities to DDS). |
Apparently my understanding was not correct. I thought they persisted over reloads. Now I'm not certain VS Code does the right thing (I think it only re-sends them for Hot Restart) - I'll do some testing! |
@bkonyi do I understand correctly that to be consistent with VM, dwds should clear all breakpoints on hot restart and not bring them back after? I think there would be currently a problem in internal scenarios where we do not clear and reestablish breakpoints but just let chrome keep track of them. Those scenarios would need to be fixed as well (ideally to invoke the same functionality as flutter tools for web does). @elliette FYI |
That's correct. The service doesn't have enough context to know where to put breakpoints since scripts could have changed significantly after reload, completely changing the behavior of breakpoints inserted at the same lines. |
Turns out I was mis-remembering. During a hot reload, we still get paused isolates ( Although, I did find one weird case where if you do not reload, but you modify a file and save it, the IDE will send the new breakpoint locations even though the VM is still running old code. So editing files and not reloading can do unexpected things with breakpoints - but I'm not sure there's a reasonable fix there (we have no way of knowing from the debug adapter whether breakpoints being sent by the IDE correspond to the same version of the file in the VM, or a newly modified one that has not been reloaded yet). (TL;DR, VS Code does re-send breakpoints on a hot reload too and this tangent was not all that relevant 🙃). |
@DanTup I will try to remove the breakpoint tracking from dwds and see if it breaks any of our scenarios. Will report back! |
@DanTup apologies for the delay! I've tried removing tracking from dwds but that does not work in scenarios without and editor like VSCode or IntelliJ to control the debugging (i.e. in @elliette @kenzieschmoll do you know how this works when running flutter tools for non-web platforms and using DevTools to debug without another editor? Does DevTools track breakpoints for other platforms but not for web? |
This came up again in Flutter discord today (or at least, we believe it's the same issue). I had a quick look in DevTools code and found some code that's updating breakpoints after a reload: However I can't see anything for a Hot Restart. I tested this running the counter app on iOS Simulator, and the breakpoints disappear on a hot restart. So as far as I can tell, that is normal behaviour for DevTools, and not something DWDS needs to handle for web, since DevTools will need to do it to support all platforms? |
Closing as duplicate of #2257 |
This came up at Dart-Code/Dart-Code#3829, though I believe it's happening in dwds.
If you remove a breakpoint at the right point during a restart (it's a narrow window, but removing breakpoints after you just fixed something is probably not uncommon), it still is hit - but since your IDE doesn't know about it, you're unable to remove it and you continue to hit it until you restart your debugging session.
I believe it happens because during a restart, dwds moves all breakpoints to a set of
"disabledBreakpoints"
, performs the restart, and then puts them back. If the IDE removed them during that period, I believe they remain indisabledBreakpoints
and come back.Here's an excerpt from the log:
The text was updated successfully, but these errors were encountered: