Skip to content

Commit

Permalink
[vm/compiler] Strip org-dartlang-sdk URI prefix to resolve DWARF paths.
Browse files Browse the repository at this point in the history
Before, we only stripped `org-dartlang-sdk:///` as a prefix when it was
followed by `sdk/...`, which happens for code compiled with the Dart
SDK. However, the same prefix can show up in Flutter code (e.g.,
`org-dartlang-sdk:///third_party/dart/sdk/...`).  Thus, except for one
case, just strip the prefix at all times when `--resolve-dwarf-paths`
is set, leaving a relative path.

The one case is `org-dartlang-sdk:///flutter/`, which appears in the
resolved version of `dart:ui` (`org-dartlang-sdk:///flutter/lib/ui`),
where the `flutter` isn't part of the actual filesystem path. In this
case, we strip off the `flutter/` as well.

TEST=vm/dart{,_2}/use_resolve_dwarf_paths_flag

Bug: #44325
Change-Id: Ia9abca877e41657089a438d4723ff08a2e16fe69
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-dwarf-linux-product-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try,vm-kernel-precomp-nnbd-win-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/268762
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
  • Loading branch information
sstrickl authored and Commit Queue committed Nov 10, 2022
1 parent f910f23 commit c1afa7f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions runtime/vm/dwarf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,10 @@ void Dwarf::WriteLineNumberProgramFromCodeSourceMaps(

static constexpr char kResolvedFileRoot[] = "file:///";
static constexpr intptr_t kResolvedFileRootLen = sizeof(kResolvedFileRoot) - 1;
static constexpr char kResolvedSdkRoot[] = "org-dartlang-sdk:///sdk/";
static constexpr char kResolvedFlutterRoot[] = "org-dartlang-sdk:///flutter/";
static constexpr intptr_t kResolvedFlutterRootLen =
sizeof(kResolvedFlutterRoot) - 1;
static constexpr char kResolvedSdkRoot[] = "org-dartlang-sdk:///";
static constexpr intptr_t kResolvedSdkRootLen = sizeof(kResolvedSdkRoot) - 1;
static constexpr char kResolvedGoogle3Root[] = "google3:///";
static constexpr intptr_t kResolvedGoogle3RootLen =
Expand All @@ -830,10 +833,15 @@ static const char* ConvertResolvedURI(const char* str) {
return str + kResolvedFileRootLen - 1; // Leave a '/' on the front.
#endif
}
// Must do kResolvedFlutterRoot before kResolvedSdkRoot, since the latter is
// a prefix of the former.
if (len > kResolvedFlutterRootLen &&
strncmp(str, kResolvedFlutterRoot, kResolvedFlutterRootLen) == 0) {
return str + kResolvedFlutterRootLen; // Strip off the entire prefix.
}
if (len > kResolvedSdkRootLen &&
strncmp(str, kResolvedSdkRoot, kResolvedSdkRootLen) == 0) {
// Leave "sdk/" as a prefix in the returned path.
return str + (kResolvedSdkRootLen - 4);
return str + kResolvedSdkRootLen; // Strip off the entire prefix.
}
if (len > kResolvedGoogle3RootLen &&
strncmp(str, kResolvedGoogle3Root, kResolvedGoogle3RootLen) == 0) {
Expand Down

0 comments on commit c1afa7f

Please sign in to comment.