Skip to content
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: 3 additions & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.5.5
- Properly set the `pauseEvent` on the `Isolate`.

## 0.5.4

- Fix issue where certain required fields of VM service protocol objects were
Expand Down
14 changes: 14 additions & 0 deletions dwds/lib/data/run_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@ abstract class RunRequest implements Built<RunRequest, RunRequestBuilder> {

RunRequest._();
}

abstract class RunResponse implements Built<RunResponse, RunResponseBuilder> {
static Serializer<RunResponse> get serializer => _$runResponseSerializer;

factory RunResponse([Function(RunResponseBuilder) updates]) = _$RunResponse;

RunResponse._();

/// Identifies a given application, across tabs/windows.
String get appId;

/// Identifies a given instance of an application, unique per tab/window.
String get instanceId;
}
139 changes: 139 additions & 0 deletions dwds/lib/data/run_request.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dwds/lib/data/serializers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ part 'serializers.g.dart';
DevToolsResponse,
ConnectRequest,
RunRequest,
RunResponse,
DefaultBuildResult,
IsolateExit,
IsolateStart,
Expand Down
3 changes: 2 additions & 1 deletion dwds/lib/data/serializers.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 28 additions & 14 deletions dwds/lib/src/debugging/debugger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,17 @@ class Debugger extends Domain {
handleErrorIfPresent(await _remoteDebugger?.enable() as WipResponse);
}

/// Resumes the Isolate from start.
///
/// The JS VM is technically not paused at the start of the Isolate so there
/// will not be a corresponding [DebuggerResumedEvent].
Future<void> resumeFromStart() => _resumeHandler(null);

/// Notify the debugger the [Isolate] is paused at the application start.
void notifyPausedAtStart() async {
_pausedStack = Stack(frames: [], messages: []);
}

/// Add a breakpoint at the given position.
///
/// Note that line and column are Dart source locations and one-based.
Expand Down Expand Up @@ -206,8 +217,9 @@ class Debugger extends Domain {
..tokenPos = location.tokenPos);
_streamNotify(
'Debug',
Event()
..kind = EventKind.kBreakpointAdded
Event(
kind: EventKind.kBreakpointAdded,
timestamp: DateTime.now().millisecondsSinceEpoch)
Copy link
Contributor

Choose a reason for hiding this comment

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

We do a lot of these. If we've got our own Event subclass, maybe it could just set the timestamp and the isolate automatically?

Copy link
Member Author

Choose a reason for hiding this comment

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

A couple locations we share the timestamp with other events so I'm going to keep it as is for now.

..isolate = inspector.isolateRef
..breakpoint = breakpoint);
return breakpoint;
Expand All @@ -228,8 +240,9 @@ class Debugger extends Domain {
}
_streamNotify(
'Debug',
Event()
..kind = EventKind.kBreakpointRemoved
Event(
kind: EventKind.kBreakpointRemoved,
timestamp: DateTime.now().millisecondsSinceEpoch)
..isolate = inspector.isolateRef
..breakpoint = bp);
await _removeBreakpoint(jsId);
Expand Down Expand Up @@ -389,43 +402,44 @@ class Debugger extends Domain {
Future<void> _pauseHandler(DebuggerPausedEvent e) async {
var isolate = inspector.isolate;
if (isolate == null) return;
var event = Event()..isolate = inspector.isolateRef;
Event event;
var timestamp = DateTime.now().millisecondsSinceEpoch;
var params = e.params;
var breakpoints = params['hitBreakpoints'] as List;
if (breakpoints.isNotEmpty) {
event.kind = EventKind.kPauseBreakpoint;
event = Event(kind: EventKind.kPauseBreakpoint, timestamp: timestamp);
} else if (e.reason == 'exception' || e.reason == 'assert') {
event.kind = EventKind.kPauseException;
event = Event(kind: EventKind.kPauseException, timestamp: timestamp);
} else {
// If we don't have source location continue stepping.
if (_isStepping && _sourceLocation(e) == null) {
await _remoteDebugger.sendCommand('Debugger.stepInto');
return;
}
event.kind = EventKind.kPauseInterrupted;
event = Event(kind: EventKind.kPauseInterrupted, timestamp: timestamp);
}
event.isolate = inspector.isolateRef;
var jsFrames =
(e.params['callFrames'] as List).cast<Map<String, dynamic>>();
var frames = await dartFramesFor(jsFrames);
_pausedStack = Stack()
..frames = frames
..messages = [];
_pausedStack = Stack(frames: frames, messages: []);
_pausedJsStack = jsFrames;
if (frames.isNotEmpty) event.topFrame = frames.first;
isolate.pauseEvent = event;
_streamNotify('Debug', event);
}

/// Handles resume events coming from the Chrome connection.
Future<void> _resumeHandler(DebuggerResumedEvent e) async {
Future<void> _resumeHandler(DebuggerResumedEvent _) async {
// We can receive a resume event in the middle of a reload which will
// result in a null isolate.
var isolate = inspector?.isolate;
if (isolate == null) return;
_pausedStack = null;
_pausedJsStack = null;
var event = Event()
..kind = EventKind.kResume
var event = Event(
kind: EventKind.kResume,
timestamp: DateTime.now().millisecondsSinceEpoch)
..isolate = inspector.isolateRef;
isolate.pauseEvent = event;
_streamNotify('Debug', event);
Expand Down
10 changes: 4 additions & 6 deletions dwds/lib/src/debugging/inspector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ class AppInspector extends Domain {
isolate.rootLib = isolate.libraries[isolate.libraries.length - 2];

isolate.extensionRPCs.addAll(await _getExtensionRpcs());

isolate.pauseEvent = Event()
..kind = EventKind.kResume
..isolate = isolateRef;
}

static IsolateRef _toIsolateRef(Isolate isolate) =>
Expand All @@ -92,19 +88,21 @@ class AppInspector extends Domain {
String root,
) async {
var id = createId();
var time = DateTime.now().millisecondsSinceEpoch;
var isolate = Isolate(
id: id,
number: id,
name: '$root:main()',
startTime: DateTime.now().millisecondsSinceEpoch,
startTime: time,
runnable: true,
pauseOnExit: false,
pauseEvent: null,
pauseEvent: Event(kind: EventKind.kPauseStart, timestamp: time),
livePorts: 0,
libraries: [],
breakpoints: [],
exceptionPauseMode: debugger.pauseState)
..extensionRPCs = [];
debugger.notifyPausedAtStart();
var inspector =
AppInspector._(isolate, assetHandler, debugger, root, remoteDebugger);
await inspector._initialize();
Expand Down
10 changes: 10 additions & 0 deletions dwds/lib/src/handlers/dev_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:convert';

import 'package:build_daemon/data/build_status.dart';
import 'package:build_daemon/data/serializers.dart' as build_daemon;
import 'package:dwds/data/run_request.dart';
import 'package:dwds/src/debugging/remote_debugger.dart';
import 'package:dwds/src/debugging/webkit_debugger.dart';
import 'package:dwds/src/servers/extension_backend.dart';
Expand Down Expand Up @@ -256,6 +257,15 @@ class DevHandler {
await (await loadAppServices(message.appId, message.instanceId))
?.chromeProxyService
?.createIsolate();
// IsolateStart events are the result of Hot Restarts which immediately
// resume execution.
await (await loadAppServices(message.appId, message.instanceId))
?.chromeProxyService
?.resumeFromStart();
} else if (message is RunResponse) {
await (await loadAppServices(message.appId, message.instanceId))
?.chromeProxyService
?.resumeFromStart();
}
});

Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/handlers/injected_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ String _injectedClientJs(
window.\$dartRunMain = $mainFunction;
window.\$dartReloadConfiguration = "$configuration";
window.\$dartLoader.forceLoadModule('$_clientScript');
window.\$loadModuleConfig = "$loadModule";
window.\$loadModuleConfig = $loadModule;
''';
if (extensionPort != null && extensionHostname != null) {
injectedBody += '''
Expand Down
Loading