From 39ebae2bab1b5a7507e91d750774a66a47dad41f Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Wed, 3 Apr 2019 21:14:37 -0700 Subject: [PATCH] [fuchsia] Fix isolate filter (#30458) --- .../lib/src/dart/dart_vm.dart | 12 +++--------- .../lib/src/fuchsia_remote_connection.dart | 9 +-------- .../test/src/dart/dart_vm_test.dart | 10 +++------- 3 files changed, 7 insertions(+), 24 deletions(-) diff --git a/packages/fuchsia_remote_debug_protocol/lib/src/dart/dart_vm.dart b/packages/fuchsia_remote_debug_protocol/lib/src/dart/dart_vm.dart index 5075e06e7a..f15bd0c1f4 100644 --- a/packages/fuchsia_remote_debug_protocol/lib/src/dart/dart_vm.dart +++ b/packages/fuchsia_remote_debug_protocol/lib/src/dart/dart_vm.dart @@ -128,24 +128,18 @@ class DartVm { /// Returns a [List] of [IsolateRef] objects whose name matches `pattern`. /// /// This is not limited to Isolates running Flutter, but to any Isolate on the - /// VM. - /// - /// `includeNonFlutterIsolates` makes sure to add non-flutter Dart isolates, - /// and defaults to `false`. + /// VM. Therefore, the [pattern] argument should be written to exclude + /// matching unintended isolates. Future> getMainIsolatesByPattern( Pattern pattern, { Duration timeout = _kRpcTimeout, - bool includeNonFlutterIsolates = false, }) async { final Map jsonVmRef = await invokeRpc('getVM', timeout: timeout); final List result = []; for (Map jsonIsolate in jsonVmRef['isolates']) { final String name = jsonIsolate['name']; - // `:main()` is included at the end of a flutter isolate, whereas the - // name of a dart Isolate is concluded as if the name were a function. - if (name.contains(pattern) && - (includeNonFlutterIsolates || name.contains(RegExp(r':main\(\)')))) { + if (pattern.matchAsPrefix(name) != null) { _log.fine('Found Isolate matching "$pattern": "$name"'); result.add(IsolateRef._fromJson(jsonIsolate, this)); } diff --git a/packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart b/packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart index 8af956194a..66cba359e8 100644 --- a/packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart +++ b/packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart @@ -289,14 +289,10 @@ class FuchsiaRemoteConnection { /// If there are no live Dart VM's or the Isolate cannot be found, waits until /// either `timeout` is reached, or a Dart VM starts up with a name that /// matches `pattern`. - /// - /// `includeNonFlutterIsolates` can be set to true to include all isolates - /// found instead of just Flutter Isolates. Future> getMainIsolatesByPattern( Pattern pattern, { Duration timeout = _kIsolateFindTimeout, Duration vmConnectionTimeout = _kDartVmConnectionTimeout, - bool includeNonFlutterIsolates = false, }) async { // If for some reason there are no Dart VM's that are alive, wait for one to // start with the Isolate in question. @@ -315,10 +311,7 @@ class FuchsiaRemoteConnection { if (vmService == null) { continue; } - isolates.add(vmService.getMainIsolatesByPattern( - pattern, - includeNonFlutterIsolates: includeNonFlutterIsolates, - )); + isolates.add(vmService.getMainIsolatesByPattern(pattern)); } final List result = await Future.wait>(isolates) diff --git a/packages/fuchsia_remote_debug_protocol/test/src/dart/dart_vm_test.dart b/packages/fuchsia_remote_debug_protocol/test/src/dart/dart_vm_test.dart index 979698854a..d18d9773be 100644 --- a/packages/fuchsia_remote_debug_protocol/test/src/dart/dart_vm_test.dart +++ b/packages/fuchsia_remote_debug_protocol/test/src/dart/dart_vm_test.dart @@ -241,7 +241,7 @@ void main() { 'type': '@Isolate', 'fixedId': 'true', 'id': 'isolates/3', - 'name': 'file://flutterBinary2:main()', + 'name': 'flutterBinary.cmx', 'number': '3', }, { @@ -268,13 +268,9 @@ void main() { await DartVm.connect(Uri.parse('http://whatever.com/ws')); expect(vm, isNot(null)); final List matchingFlutterIsolates = - await vm.getMainIsolatesByPattern('flutterBinary'); + await vm.getMainIsolatesByPattern('flutterBinary.cmx'); expect(matchingFlutterIsolates.length, 1); - final List allFlutterIsolates = - await vm.getMainIsolatesByPattern(''); - expect(allFlutterIsolates.length, 2); - final List allIsolates = await vm.getMainIsolatesByPattern('', - includeNonFlutterIsolates: true); + final List allIsolates = await vm.getMainIsolatesByPattern(''); expect(allIsolates.length, 4); });