Skip to content

Commit 500416f

Browse files
authored
Breakpoint with script uri (#494)
1 parent bcc481d commit 500416f

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

dwds/lib/src/debugging/debugger.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class Debugger extends Domain {
280280
// Chrome is 0 based. Account for this.
281281
var jsLocation = JsLocation.fromZeroBased(location['scriptId'] as String,
282282
location['lineNumber'] as int, location['columnNumber'] as int);
283-
var dartFrame = _frameFor(jsLocation);
283+
var dartFrame = await _frameFor(jsLocation);
284284
if (dartFrame != null) {
285285
dartFrame.code.name = functionName.isEmpty ? '<closure>' : functionName;
286286
dartFrame.index = index++;
@@ -331,7 +331,7 @@ class Debugger extends Domain {
331331
}
332332

333333
/// Returns a Dart [Frame] for a [JsLocation].
334-
Frame _frameFor(JsLocation jsLocation) {
334+
Future<Frame> _frameFor(JsLocation jsLocation) async {
335335
// TODO(sdk/issues/37240) - ideally we look for an exact location instead
336336
// of the closest location on a given line.
337337
Location bestLocation;
@@ -346,7 +346,7 @@ class Debugger extends Domain {
346346
}
347347
if (bestLocation == null) return null;
348348
var script =
349-
inspector?.scriptRefFor(bestLocation.dartLocation.uri.serverPath);
349+
await inspector?.scriptRefFor(bestLocation.dartLocation.uri.serverPath);
350350
return Frame()
351351
..code = (CodeRef()..kind = CodeKind.kDart)
352352
..location = (SourceLocation()

dwds/lib/src/debugging/inspector.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,13 @@ function($argsString) {
367367
}
368368

369369
/// Returns the [ScriptRef] for the provided Dart server path [uri].
370-
ScriptRef scriptRefFor(String uri) => _serverPathToScriptRef[uri];
370+
Future<ScriptRef> scriptRefFor(String uri) async {
371+
if (_serverPathToScriptRef.isEmpty) {
372+
// TODO(grouma) - populate the server path cache a better way.
373+
await getScripts(isolate.id);
374+
}
375+
return _serverPathToScriptRef[uri];
376+
}
371377

372378
Future<ScriptList> getScripts(String isolateId) async {
373379
var scripts = await scriptRefs(isolateId);

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:async';
66
import 'dart:convert';
77
import 'dart:io';
88

9+
import 'package:dwds/src/utilities/dart_uri.dart';
910
import 'package:pedantic/pedantic.dart';
1011
import 'package:pub_semver/pub_semver.dart' as semver;
1112
import 'package:vm_service_lib/vm_service_lib.dart';
@@ -187,8 +188,10 @@ class ChromeProxyService implements VmServiceInterface {
187188
@override
188189
Future<Breakpoint> addBreakpointWithScriptUri(
189190
String isolateId, String scriptUri, int line,
190-
{int column}) {
191-
throw UnimplementedError();
191+
{int column}) async {
192+
var dartUri = DartUri(scriptUri, uri);
193+
var ref = await _inspector.scriptRefFor(dartUri.serverPath);
194+
return _debugger.addBreakpoint(isolateId, ref.id, line, column: column);
192195
}
193196

194197
@override

dwds/test/chrome_proxy_service_test.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void main() {
4949
var bp = await service.addBreakpoint(isolate.id, mainScript.id, 23);
5050
// Remove breakpoint so it doesn't impact other tests.
5151
await service.removeBreakpoint(isolate.id, bp.id);
52-
expect(bp.id, '1');
52+
expect(bp.id, isNotNull);
5353
});
5454

5555
test('addBreakpoint on a part file', () async {
@@ -58,16 +58,20 @@ void main() {
5858
var bp = await service.addBreakpoint(isolate.id, partScript.id, 10);
5959
// Remove breakpoint so it doesn't impact other tests.
6060
await service.removeBreakpoint(isolate.id, bp.id);
61-
expect(bp.id, '2');
61+
expect(bp.id, isNotNull);
6262
});
6363

6464
test('addBreakpointAtEntry', () {
6565
expect(() => service.addBreakpointAtEntry(null, null),
6666
throwsUnimplementedError);
6767
});
68-
test('addBreakpointWithScriptUri', () {
69-
expect(() => service.addBreakpointWithScriptUri(null, null, null),
70-
throwsUnimplementedError);
68+
69+
test('addBreakpointWithScriptUri', () async {
70+
var bp = await service.addBreakpointWithScriptUri(
71+
isolate.id, mainScript.uri, 23);
72+
// Remove breakpoint so it doesn't impact other tests.
73+
await service.removeBreakpoint(isolate.id, bp.id);
74+
expect(bp.id, isNotNull);
7175
});
7276

7377
test('removeBreakpoint null arguments', () {
@@ -95,7 +99,7 @@ void main() {
9599
.lastWhere((each) => each.uri.contains('main.dart'));
96100
var bp = await service.addBreakpoint(isolate.id, refreshedMain.id, 23);
97101
expect(isolate.breakpoints, [bp]);
98-
expect(bp.id, '4');
102+
expect(bp.id, isNotNull);
99103
await service.removeBreakpoint(isolate.id, bp.id);
100104
expect(isolate.breakpoints, isEmpty);
101105
});

dwds/test/fixtures/fakes.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class FakeInspector extends Domain implements AppInspector {
5858
@override
5959
Future<InstanceRef> instanceRefFor(RemoteObject remoteObject) => null;
6060
@override
61-
ScriptRef scriptRefFor(String uri) => null;
61+
Future<ScriptRef> scriptRefFor(String uri) => null;
6262
@override
6363
Future<List<ScriptRef>> scriptRefs(String isolateId) => null;
6464
@override

0 commit comments

Comments
 (0)