@@ -48,6 +48,7 @@ class Debugger extends Domain {
4848 final AssetReader _assetReader;
4949 final Modules _modules;
5050 final Locations _locations;
51+ final String _root;
5152
5253 Debugger ._(
5354 this ._remoteDebugger,
@@ -56,12 +57,12 @@ class Debugger extends Domain {
5657 this ._assetReader,
5758 this ._modules,
5859 this ._locations,
59- String root ,
60+ this ._root ,
6061 ) : _breakpoints = _Breakpoints (
6162 locations: _locations,
6263 provider: provider,
6364 remoteDebugger: _remoteDebugger,
64- root: root ),
65+ root: _root ),
6566 super (provider);
6667
6768 /// The breakpoints we have set so far, indexable by either
@@ -269,18 +270,52 @@ class Debugger extends Domain {
269270 int column,
270271 }) async {
271272 checkIsolate ('addBreakpoint' , isolateId);
272-
273273 final breakpoint = await _breakpoints.add (scriptId, line);
274+ _notifyBreakpoint (breakpoint);
275+ return breakpoint;
276+ }
274277
278+ Future <ScriptRef > _updatedScriptRefFor (Breakpoint breakpoint) async {
279+ var oldRef = (breakpoint.location as SourceLocation ).script;
280+ var dartUri = DartUri (oldRef.uri, _root);
281+ return await inspector.scriptRefFor (dartUri.serverPath);
282+ }
283+
284+ Future <void > reestablishBreakpoints (
285+ Set <Breakpoint > previousBreakpoints,
286+ Set <Breakpoint > disabledBreakpoints,
287+ ) async {
288+ // Previous breakpoints were never removed from Chrome since we use
289+ // `setBreakpointByUrl`. We simply need to update the references.
290+ for (var breakpoint in previousBreakpoints) {
291+ var scriptRef = await _updatedScriptRefFor (breakpoint);
292+ var updatedLocation = await _locations.locationForDart (
293+ DartUri (scriptRef.uri, _root), _lineNumberFor (breakpoint));
294+ var updatedBreakpoint = _breakpoints._dartBreakpoint (
295+ scriptRef, updatedLocation, breakpoint.id);
296+ _breakpoints._note (
297+ bp: updatedBreakpoint,
298+ jsId: _breakpoints._jsIdByDartId[updatedBreakpoint.id]);
299+ _notifyBreakpoint (updatedBreakpoint);
300+ }
301+ // Disabled breakpoints were actually removed from Chrome so simply add
302+ // them back.
303+ for (var breakpoint in disabledBreakpoints) {
304+ await addBreakpoint (
305+ inspector.isolate.id,
306+ (await _updatedScriptRefFor (breakpoint)).id,
307+ _lineNumberFor (breakpoint));
308+ }
309+ }
310+
311+ void _notifyBreakpoint (Breakpoint breakpoint) {
275312 final event = Event (
276313 kind: EventKind .kBreakpointAdded,
277314 timestamp: DateTime .now ().millisecondsSinceEpoch,
278315 isolate: inspector.isolateRef,
279316 );
280317 event.breakpoint = breakpoint;
281318 _streamNotify ('Debug' , event);
282-
283- return breakpoint;
284319 }
285320
286321 /// Remove a Dart breakpoint.
@@ -624,7 +659,7 @@ class Debugger extends Domain {
624659}
625660
626661/// Returns the Dart line number for the provided breakpoint.
627- int lineNumberFor (Breakpoint breakpoint) =>
662+ int _lineNumberFor (Breakpoint breakpoint) =>
628663 int .parse (breakpoint.id.split ('#' ).last);
629664
630665/// Returns the breakpoint ID for the provided Dart script ID and Dart line
@@ -699,12 +734,13 @@ class _Breakpoints extends Domain {
699734 Future <String > _setJsBreakpoint (Location location) async {
700735 // Location is 0 based according to:
701736 // https://chromedevtools.github.io/devtools-protocol/tot/Debugger#type-Location
702- var response =
703- await remoteDebugger.sendCommand ('Debugger.setBreakpoint' , params: {
704- 'location' : {
705- 'scriptId' : location.jsLocation.scriptId,
706- 'lineNumber' : location.jsLocation.line - 1 ,
707- }
737+
738+ // The module can be loaded from a nested path and contain an ETAG suffix.
739+ var urlRegex = '.*${location .modulePath }.*' ;
740+ var response = await remoteDebugger
741+ .sendCommand ('Debugger.setBreakpointByUrl' , params: {
742+ 'urlRegex' : urlRegex,
743+ 'lineNumber' : location.jsLocation.line - 1 ,
708744 });
709745 return response.result['breakpointId' ] as String ;
710746 }
@@ -729,8 +765,6 @@ class _Breakpoints extends Domain {
729765 return _bpByDartId.remove (dartId);
730766 }
731767
732- String dartId (String jsId) => _dartIdByJsId[jsId];
733-
734768 String jsId (String dartId) => _jsIdByDartId[dartId];
735769}
736770
0 commit comments