Skip to content

Commit

Permalink
Can add breakpoints to a project using macros (#2403)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliette authored Apr 5, 2024
1 parent d715bcd commit 7d0d2d4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 21 deletions.
1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Implement `setFlag` when it is called with `pause_isolates_on_start`. - [#2373](https://github.com/dart-lang/webdev/pull/2373)
- Do not persist breakpoints across hot restarts or page reloads. - [#2371](https://github.com/dart-lang/webdev/pull/2371)
- 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)
- Fix bug where setting breakpoints in a project using macros would fail. - [#2403](https://github.com/dart-lang/webdev/pull/2403)

**Breaking changes**

Expand Down
68 changes: 47 additions & 21 deletions dwds/lib/src/debugging/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -343,28 +343,17 @@ class Locations {
// Create TokenPos for each entry in the source map.
for (var lineEntry in mapping.lines) {
for (var entry in lineEntry.entries) {
final index = entry.sourceUrlId;
if (index == null) continue;
// Source map URLS are relative to the script. They may have platform separators
// or they may use URL semantics. To be sure, we split and re-join them.
// This works on Windows because path treats both / and \ as separators.
// It will fail if the path has both separators in it.
final relativeSegments = p.split(mapping.urls[index]);
final path = p.url.normalize(
p.url.joinAll([scriptLocation, ...relativeSegments]),
);

final dartUri = DartUri(path, _root);

result.add(
Location.from(
modulePath,
lineEntry,
entry,
dartUri,
runtimeScriptId,
),
final location = _locationForSourceMapEntry(
lineEntry: lineEntry,
entry: entry,
modulePath: modulePath,
runtimeScriptId: runtimeScriptId,
sourceUrls: mapping.urls,
scriptLocation: scriptLocation,
);
if (location != null) {
result.add(location);
}
}
}
}
Expand All @@ -379,4 +368,41 @@ class Locations {
return _moduleToLocations[module] = result;
});
}

/// Creates a TokenPos [Location] for an entry in the source map.
Location? _locationForSourceMapEntry({
required TargetLineEntry lineEntry,
required TargetEntry entry,
required String modulePath,
required String? runtimeScriptId,
required List<String> sourceUrls,
required String scriptLocation,
}) {
final index = entry.sourceUrlId;
if (index == null) return null;
// Source map URLS are relative to the script. They may have platform separators
// or they may use URL semantics. To be sure, we split and re-join them.
// This works on Windows because path treats both / and \ as separators.
// It will fail if the path has both separators in it.
final relativeSegments = p.split(sourceUrls[index]);
final path = p.url.normalize(
p.url.joinAll([scriptLocation, ...relativeSegments]),
);

try {
final dartUri = DartUri(path, _root);
return Location.from(
modulePath,
lineEntry,
entry,
dartUri,
runtimeScriptId,
);
} catch (error) {
// DartUri throws if the path format is unrecognized. Log any errors and
// return null in that case.
_logger.warning('Error adding location for $path: $error');
return null;
}
}
}

0 comments on commit 7d0d2d4

Please sign in to comment.