Skip to content

Commit 8c814f9

Browse files
author
Anna Gringauze
authored
Fix issues discovered when using web server device in flutter tools (#1588)
* Fix breakpoints in web server * Updated version and built * Addressed CR comments * Addressed CR comments, added checks for assumptions and tests * Disable testing without DevTools and with debug extension on windows * Addressed CR comments
1 parent d9ca97a commit 8c814f9

File tree

12 files changed

+109
-83
lines changed

12 files changed

+109
-83
lines changed

dwds/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
## 13.1.1-dev
22
- Add column information to breakpoints to allow precise breakpoint placement.
33
- Split SDK validation methods to allow validation of separate components.
4+
- Remove dependency on `package:_fe_analyzer_shared`.
5+
Note: this removes current incomplete support for resolving `dart:` uris.
6+
- Fix issues discovered when using flutter tools with web server device:
7+
- Remove `dart:web_sql` from the list of SDK libraries as it is no longer
8+
used.
9+
- Fix crash when using flutter tools with web server device.
10+
- Remove clearing all scripts on page load for extension debugger.
411

512
## 13.1.0
613
- Update _fe_analyzer_shared to version ^38.0.0.

dwds/lib/src/debugging/debugger.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ class Debugger extends Domain {
471471
if (url == null) {
472472
logger.severe('Failed to create dart frame for ${frame.functionName}: '
473473
'cannot find location for script ${location.scriptId}');
474+
return null;
474475
}
475476

476477
// TODO(sdk/issues/37240) - ideally we look for an exact location instead
@@ -740,7 +741,7 @@ String breakpointIdFor(String scriptId, int line, int column) =>
740741

741742
/// Keeps track of the Dart and JS breakpoint Ids that correspond.
742743
class _Breakpoints extends Domain {
743-
final logger = Logger('Breakpoints');
744+
final _logger = Logger('Breakpoints');
744745
final _dartIdByJsId = <String, String>{};
745746
final _jsIdByDartId = <String, String>{};
746747

@@ -768,10 +769,9 @@ class _Breakpoints extends Domain {
768769
var location = await locations.locationForDart(dartUri, line, column);
769770
// TODO: Handle cases where a breakpoint can't be set exactly at that line.
770771
if (location == null) {
771-
logger
772-
.fine('Failed to set breakpoint at ${dartScript.uri}:$line:$column: '
773-
'Dart location not found for scriptId: $scriptId, '
774-
'server path: ${dartUri.serverPath}, root:$root');
772+
_logger.fine('Failed to set breakpoint $id '
773+
'(${dartUri.serverPath}:$line:$column): '
774+
'cannot find Dart location.');
775775
throw RPCError(
776776
'addBreakpoint',
777777
102,

dwds/lib/src/debugging/metadata/provider.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class MetadataProvider {
6565
'dart:svg',
6666
'dart:web_audio',
6767
'dart:web_gl',
68-
'dart:web_sql',
6968
'dart:ui',
7069
];
7170

dwds/lib/src/handlers/dev_handler.dart

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class DevHandler {
9393
this._launchDevToolsInNewWindow,
9494
this._sdkConfigurationProvider,
9595
) {
96+
_validateDevToolsOptions();
9697
_subs.add(buildResults.listen(_emitBuildResults));
9798
_listen();
9899
if (_extensionBackend != null) {
@@ -376,10 +377,12 @@ class DevHandler {
376377
debuggerStart: debuggerStart,
377378
devToolsStart: DateTime.now(),
378379
);
379-
await _launchDevTools(
380-
appServices.chromeProxyService.remoteDebugger,
381-
_constructDevToolsUri(appServices.debugService.uri,
382-
ideQueryParam: 'Dwds'));
380+
if (_serveDevTools) {
381+
await _launchDevTools(
382+
appServices.chromeProxyService.remoteDebugger,
383+
_constructDevToolsUri(appServices.debugService.uri,
384+
ideQueryParam: 'Dwds'));
385+
}
383386
}
384387

385388
Future<AppConnection> _handleConnectRequest(
@@ -533,29 +536,45 @@ class DevHandler {
533536
appServices.dwdsStats.updateLoadTime(
534537
debuggerStart: debuggerStart, devToolsStart: DateTime.now());
535538

536-
// If we only want the URI, this means we are embedding Dart DevTools in
537-
// Chrome DevTools. Therefore return early.
538-
if (devToolsRequest.uriOnly != null && devToolsRequest.uriOnly) {
539+
if (_serveDevTools) {
540+
// If we only want the URI, this means we are embedding Dart DevTools in
541+
// Chrome DevTools. Therefore return early.
542+
if (devToolsRequest.uriOnly != null && devToolsRequest.uriOnly) {
543+
final devToolsUri = _constructDevToolsUri(
544+
encodedUri,
545+
ideQueryParam: 'ChromeDevTools',
546+
);
547+
extensionDebugger.sendEvent('dwds.devtoolsUri', devToolsUri);
548+
return;
549+
}
539550
final devToolsUri = _constructDevToolsUri(
540551
encodedUri,
541-
ideQueryParam: 'ChromeDevTools',
552+
ideQueryParam: 'DebugExtension',
542553
);
543-
extensionDebugger.sendEvent('dwds.devtoolsUri', devToolsUri);
544-
return;
554+
await _launchDevTools(extensionDebugger, devToolsUri);
545555
}
546-
final devToolsUri = _constructDevToolsUri(
547-
encodedUri,
548-
ideQueryParam: 'DebugExtension',
549-
);
550-
await _launchDevTools(extensionDebugger, devToolsUri);
551556
});
552557
}
553558

559+
void _ensureServeDevtools() {
560+
if (!_serveDevTools) {
561+
_logger.severe('Expected _serveDevTools');
562+
throw StateError('Expected _serveDevTools');
563+
}
564+
}
565+
566+
void _validateDevToolsOptions() {
567+
if (_serveDevTools && _devTools == null) {
568+
_logger.severe('DevHandler: invalid DevTools options');
569+
throw StateError('DevHandler: invalid DevTools options');
570+
}
571+
}
572+
554573
Future<void> _launchDevTools(
555574
RemoteDebugger remoteDebugger, String devToolsUri) async {
575+
_ensureServeDevtools();
556576
// TODO(grouma) - We may want to log the debugServiceUri if we don't launch
557577
// DevTools so that users can manually connect.
558-
if (!_serveDevTools) return;
559578
emitEvent(DwdsEvent.devtoolsLaunch());
560579
await remoteDebugger.sendCommand('Target.createTarget', params: {
561580
'newWindow': _launchDevToolsInNewWindow,
@@ -567,6 +586,7 @@ class DevHandler {
567586
String debugServiceUri, {
568587
String ideQueryParam = '',
569588
}) {
589+
_ensureServeDevtools();
570590
return Uri(
571591
scheme: 'http',
572592
host: _devTools.hostname,

dwds/lib/src/injected/client.js

Lines changed: 9 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dwds/lib/src/servers/extension_debugger.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class ExtensionDebugger implements RemoteDebugger {
263263

264264
@override
265265
Stream<GlobalObjectClearedEvent> get onGlobalObjectCleared => eventStream(
266-
'Page.frameStartedLoading',
266+
'Debugger.globalObjectCleared',
267267
(WipEvent event) => GlobalObjectClearedEvent(event.json));
268268

269269
@override

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,17 @@ class ChromeProxyService implements VmServiceInterface {
337337
String isolateId, String scriptUri, int line,
338338
{int column}) async {
339339
await isInitialized;
340+
if (Uri.parse(scriptUri).scheme == 'dart') {
341+
_logger.finest('Cannot set breakpoint at $scriptUri:$line:$column: '
342+
'breakpoints in dart SDK locations are not supported yet.');
343+
// TODO(annagrin): Support setting breakpoints in dart SDK locations.
344+
// Issue: https://github.com/dart-lang/webdev/issues/1584
345+
throw RPCError(
346+
'addBreakpoint',
347+
102,
348+
'The VM is unable to add a breakpoint '
349+
'at the specified line or function');
350+
}
340351
var dartUri = DartUri(scriptUri, uri);
341352
var ref = await _inspector.scriptRefFor(dartUri.serverPath);
342353
return (await _debugger)

dwds/lib/src/utilities/dart_uri.dart

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
// @dart = 2.9
66

7-
import 'dart:io';
8-
9-
// ignore: implementation_imports
10-
import 'package:_fe_analyzer_shared/src/util/libraries_specification.dart';
117
import 'package:logging/logging.dart';
128
import 'package:package_config/package_config.dart';
139
import 'package:path/path.dart' as p;
@@ -41,6 +37,8 @@ class DartUri {
4137
factory DartUri(String uri, [String serverUri]) {
4238
var serverPath = globalLoadStrategy.serverPathForAppUri(uri);
4339
if (serverPath != null) return DartUri._(serverPath);
40+
// TODO(annagrin): Support creating DartUris from `dart:` uris.
41+
// Issue: https://github.com/dart-lang/webdev/issues/1584
4442
if (uri.startsWith('package:')) {
4543
return DartUri._fromPackageUri(uri, serverUri: serverUri);
4644
}
@@ -98,9 +96,6 @@ class DartUri {
9896
/// The way we resolve file: URLs into package: URLs
9997
static PackageConfig _packageConfig;
10098

101-
/// The way we resolve dart: URLs into org-dartland-sdk: URLs
102-
static TargetLibrariesSpecification _librariesSpec;
103-
10499
/// SDK installation directory.
105100
///
106101
/// Directory where the SDK client code built with is installed,
@@ -166,16 +161,12 @@ class DartUri {
166161
if (_sdkConfiguration.sdkDirectory != null) {
167162
_sdkConfiguration.validateSdkDir();
168163
}
169-
if (_sdkConfiguration.librariesUri != null) {
170-
await _loadLibrariesConfig(_sdkConfiguration.librariesUri);
171-
}
172164

173165
await _loadPackageConfig(packagesUri);
174166
}
175167

176168
/// Clear the uri resolution tables.
177169
static void clear() {
178-
_librariesSpec = null;
179170
_packageConfig = null;
180171
_resolvedUriToUri.clear();
181172
_uriToResolvedUri.clear();
@@ -199,20 +190,6 @@ class DartUri {
199190
});
200191
}
201192

202-
/// Load and parse libraries.json spec file.
203-
/// Used for resolving `dart:` libraries uris.
204-
static Future<void> _loadLibrariesConfig(Uri uri) async {
205-
try {
206-
var spec = await LibrariesSpecification.load(
207-
uri, (uri) => File.fromUri(uri).readAsString());
208-
_librariesSpec = spec.specificationFor('dartdevc');
209-
} on LibrariesSpecificationException catch (e) {
210-
_logger.warning('Cannot parse libraries spec: $uri', e);
211-
} on FileSystemException catch (e) {
212-
_logger.warning('Cannot read libraries spec: $uri', e);
213-
}
214-
}
215-
216193
/// Record the library represented by package: or org-dartlang-app: uris
217194
/// indexed by absolute file: URI.
218195
static void _recordAbsoluteUri(String libraryUri) {
@@ -225,12 +202,9 @@ class DartUri {
225202
String libraryPath;
226203
switch (uri.scheme) {
227204
case 'dart':
228-
var libSpec = _librariesSpec?.libraryInfoFor(uri.path);
229-
libraryPath = libSpec?.uri?.path;
230-
var sdkDir = _sdkConfiguration.sdkDirectoryUri;
231-
libraryPath =
232-
libraryPath?.replaceAll(sdkDir.path, 'org-dartlang-sdk:///sdk');
233-
break;
205+
// TODO(annagrin): Support resolving `dart:` uris.
206+
// Issue: https://github.com/dart-lang/webdev/issues/1584
207+
return;
234208
case 'org-dartlang-app':
235209
case 'google3':
236210
// Both currentDirectoryUri and the libraryUri path should have '/'
@@ -249,7 +223,7 @@ class DartUri {
249223
_uriToResolvedUri[libraryUri] = libraryPath;
250224
_resolvedUriToUri[libraryPath] = libraryUri;
251225
} else {
252-
_logger.warning('Unresolved uri: $uri');
226+
_logger.fine('Unresolved uri: $uri');
253227
}
254228
}
255229
}

dwds/pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ environment:
1010
sdk: ">=2.16.0 <3.0.0"
1111

1212
dependencies:
13-
_fe_analyzer_shared: ^38.0.0
1413
async: ^2.3.0
1514
built_collection: ^5.0.0
1615
built_value: '>=6.7.0 <9.0.0'

dwds/test/chrome_proxy_service_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ void main() {
13561356
'org-dartlang-sdk:///sdk/lib/html/dart2js/html_dart2js.dart',
13571357
'org-dartlang-sdk:///sdk/lib/async/async.dart',
13581358
]);
1359-
});
1359+
}, skip: 'https://github.com/dart-lang/webdev/issues/1584');
13601360

13611361
test('lookupPackageUris finds package and org-dartlang-app paths',
13621362
() async {
@@ -1404,7 +1404,7 @@ void main() {
14041404
'dart:html',
14051405
'dart:async',
14061406
]);
1407-
});
1407+
}, skip: 'https://github.com/dart-lang/webdev/issues/1584');
14081408

14091409
test('registerService', () async {
14101410
await expectLater(

0 commit comments

Comments
 (0)