Skip to content

Support breakpoints for hot reload #2627

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

srujzs
Copy link
Contributor

@srujzs srujzs commented May 29, 2025

Adds support for properly reregistering breakpoints across
a hot reload. Like with hot restart, leverages the kPausePostRequest
event in order to reregister breakpoints. DWDS does the initial
work to load the new sources in ("hotReloadStart"), and pauses and
sends the request. Upon disabling existing breakpoint, reregistering
and registering new breakpoints and resuming, DWDS will resume the
app and push the new sources into the runtime ("hotReloadEnd").

Also reinitializes some cached information in order to compute new
sources. Note that it's very conservative for now. A future change
should optimize the invalidation.

Adds tests for the following cases:

  • Editing a line with a breakpoint.
  • Adding a line before a breakpoint.
  • Removing a line before a breakpoint.
  • Adding a new file with a breakpoint in it.
  • Breakpoint in previously captured code is removed.
  • There's no pause when pause_isolates_on_start is false.

dart-lang/sdk#60186

srujzs added 5 commits May 22, 2025 17:26
… bundle format

pause_isolates_on_start tells DWDS and the client that during a
hot restart or a hot reload, the VM service will pause and is
actively waiting for the client to remove existing breakpoints,
reregister them, and then resume. It lets the client know by
sending a kPausePostRequest event.

In order to do this in DWDS, we need to defer the execution of
main until that resume. So, like we do with the require
restarter, we wait for a completer to finish before we call
main after a hot restart. This completer is only provided when
the flag is enabled.

Fixes existing code that marks the completer as completed before
running main. The previous code canceled the subscription in an
unawaited Future. This may result in us recalling main because
the event stream could still have a listener. An example is if
we hit a breakpoint immediately after main and call resume.

Also fixes an issue where metadata information isn't recomputed
on a hot restart. This is needed when new files are added.

Adds tests for:

- Modifying a line with a breakpoint and restarting.
- Adding a line before a breakpoint and restarting.
- Removing a line before a breakpoint and restarting.
- Adding a file and putting a breakpoint in it before restarting.
…ns of console logs after resume to use a future instead
@srujzs srujzs force-pushed the hotreloadbreakpoints branch from ba5551c to 1559e0e Compare May 30, 2025 21:16
srujzs added 6 commits May 30, 2025 17:48
Adds support for properly reregistering breakpoints across
a hot reload. Like with hot restart, leverages the kPausePostRequest
event in order to reregister breakpoints. DWDS does the initial
work to load the new sources in ("hotReloadStart"), and pauses and
sends the request. Upon disabling existing breakpoint, reregistering
and registering new breakpoints and resuming, DWDS will resume the
app and push the new sources into the runtime ("hotReloadEnd").

Also reinitializes some cached information in order to compute new
sources. Note that it's very conservative for now. A future change
should optimize the invalidation.

Adds tests for the following cases:
- Editing a line with a breakpoint.
- Adding a line before a breakpoint.
- Removing a line before a breakpoint.
- Adding a new file with a breakpoint in it.
- Breakpoint in previously captured code is removed.
- There's no pause when pause_isolates_on_start is false.
@srujzs srujzs force-pushed the hotreloadbreakpoints branch from c1ff8c9 to b9709a6 Compare May 31, 2025 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant