Skip to content

Commit 7d0d2d4

Browse files
authored
Can add breakpoints to a project using macros (#2403)
1 parent d715bcd commit 7d0d2d4

File tree

2 files changed

+48
-21
lines changed

2 files changed

+48
-21
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Implement `setFlag` when it is called with `pause_isolates_on_start`. - [#2373](https://github.com/dart-lang/webdev/pull/2373)
44
- Do not persist breakpoints across hot restarts or page reloads. - [#2371](https://github.com/dart-lang/webdev/pull/2371)
55
- If `pause_isolates_on_start` is `true`, wait for `resume` to run the app's `main` method. - [#2378](https://github.com/dart-lang/webdev/pull/2378)
6+
- Fix bug where setting breakpoints in a project using macros would fail. - [#2403](https://github.com/dart-lang/webdev/pull/2403)
67

78
**Breaking changes**
89

dwds/lib/src/debugging/location.dart

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -343,28 +343,17 @@ class Locations {
343343
// Create TokenPos for each entry in the source map.
344344
for (var lineEntry in mapping.lines) {
345345
for (var entry in lineEntry.entries) {
346-
final index = entry.sourceUrlId;
347-
if (index == null) continue;
348-
// Source map URLS are relative to the script. They may have platform separators
349-
// or they may use URL semantics. To be sure, we split and re-join them.
350-
// This works on Windows because path treats both / and \ as separators.
351-
// It will fail if the path has both separators in it.
352-
final relativeSegments = p.split(mapping.urls[index]);
353-
final path = p.url.normalize(
354-
p.url.joinAll([scriptLocation, ...relativeSegments]),
355-
);
356-
357-
final dartUri = DartUri(path, _root);
358-
359-
result.add(
360-
Location.from(
361-
modulePath,
362-
lineEntry,
363-
entry,
364-
dartUri,
365-
runtimeScriptId,
366-
),
346+
final location = _locationForSourceMapEntry(
347+
lineEntry: lineEntry,
348+
entry: entry,
349+
modulePath: modulePath,
350+
runtimeScriptId: runtimeScriptId,
351+
sourceUrls: mapping.urls,
352+
scriptLocation: scriptLocation,
367353
);
354+
if (location != null) {
355+
result.add(location);
356+
}
368357
}
369358
}
370359
}
@@ -379,4 +368,41 @@ class Locations {
379368
return _moduleToLocations[module] = result;
380369
});
381370
}
371+
372+
/// Creates a TokenPos [Location] for an entry in the source map.
373+
Location? _locationForSourceMapEntry({
374+
required TargetLineEntry lineEntry,
375+
required TargetEntry entry,
376+
required String modulePath,
377+
required String? runtimeScriptId,
378+
required List<String> sourceUrls,
379+
required String scriptLocation,
380+
}) {
381+
final index = entry.sourceUrlId;
382+
if (index == null) return null;
383+
// Source map URLS are relative to the script. They may have platform separators
384+
// or they may use URL semantics. To be sure, we split and re-join them.
385+
// This works on Windows because path treats both / and \ as separators.
386+
// It will fail if the path has both separators in it.
387+
final relativeSegments = p.split(sourceUrls[index]);
388+
final path = p.url.normalize(
389+
p.url.joinAll([scriptLocation, ...relativeSegments]),
390+
);
391+
392+
try {
393+
final dartUri = DartUri(path, _root);
394+
return Location.from(
395+
modulePath,
396+
lineEntry,
397+
entry,
398+
dartUri,
399+
runtimeScriptId,
400+
);
401+
} catch (error) {
402+
// DartUri throws if the path format is unrecognized. Log any errors and
403+
// return null in that case.
404+
_logger.warning('Error adding location for $path: $error');
405+
return null;
406+
}
407+
}
382408
}

0 commit comments

Comments
 (0)