From 82b49f83b9f0779a7749446ae21e8c64058a59b9 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Thu, 4 Apr 2024 09:31:04 -0700 Subject: [PATCH 1/2] Can debug project with macros --- dwds/lib/src/debugging/location.dart | 68 +++++++++++++++++++--------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/dwds/lib/src/debugging/location.dart b/dwds/lib/src/debugging/location.dart index c055dee69..cd5fb4113 100644 --- a/dwds/lib/src/debugging/location.dart +++ b/dwds/lib/src/debugging/location.dart @@ -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); + } } } } @@ -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 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; + } + } } From 1eb3ca706244f3d336306dbeee06d56ffd572094 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Thu, 4 Apr 2024 10:05:40 -0700 Subject: [PATCH 2/2] Update changelog --- dwds/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index ac3f75750..80a5c0623 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -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**