[ VM / Service ] Fix 'dart:' scripts lookup

Bug: VM service `addBreakpointWithScriptUri` and `addBreakpoint` don't add valid breakpoints for code in `dart:` libraries. See #47204

This PR contains :
- a new test : 'service/break_on_dart_colon_test.dart', that checks several URIs to register breakpoints in `dart:` libs.
- a fix in `Debugger::SetBreakpointAtLineCol` to make it calls `Library::LookupScript'` with the right value for `useResolvedUri` parameter.

Fixes https://github.com/dart-lang/sdk/issues/47204

TEST=runtime/observatory/tests/service/break_on_dart_colon_test.dart

Change-Id: Id3d6722c278e3238202a9d84a0d34612b957035c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213766
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
This commit is contained in:
Bruno Leroux 2021-09-24 01:20:38 +00:00 committed by commit-bot@chromium.org
parent ec29dce8e0
commit 2481cf76f5
5 changed files with 99 additions and 1 deletions

View file

@ -0,0 +1,47 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--verbose_debug
import 'dart:developer';
import 'package:observatory/service_io.dart';
import 'service_test_common.dart';
import 'test_helper.dart';
// Line in core/print.dart
const int LINE_A = 10;
testMain() {
debugger();
print('1');
print('2');
print('3');
print('Done');
}
IsolateTest expectHitBreakpoint(String uri, int line) {
return (Isolate isolate) async {
final bpt = await isolate.addBreakpointByScriptUri(uri, line);
await resumeIsolate(isolate);
await hasStoppedAtBreakpoint(isolate);
await stoppedAtLine(line)(isolate);
await isolate.removeBreakpoint(bpt);
};
}
var tests = <IsolateTest>[
hasStoppedAtBreakpoint,
// Dart libraries are not debuggable by default
markDartColonLibrariesDebuggable,
expectHitBreakpoint('org-dartlang-sdk:///sdk/lib/core/print.dart', LINE_A),
expectHitBreakpoint('dart:core/print.dart', LINE_A),
expectHitBreakpoint('/core/print.dart', LINE_A),
resumeIsolate,
];
main(args) => runIsolateTests(args, tests, testeeConcurrent: testMain);

View file

@ -47,6 +47,7 @@ awaiter_async_stack_contents_test: SkipByDesign # Debugger is disabled in AOT mo
bad_reload_test: SkipByDesign # Hot reload is disabled in AOT mode.
break_on_activation_test: SkipByDesign # Debugger is disabled in AOT mode.
break_on_async_function_test: SkipByDesign # Debugger is disabled in AOT mode.
break_on_dart_colon_test: SkipByDesign # Debugger is disabled in AOT mode.
break_on_default_constructor_test: SkipByDesign # Debugger is disabled in AOT mode.
break_on_function_child_isolate_test: SkipByDesign # Debugger is disabled in AOT mode.
break_on_function_many_child_isolates_test: SkipByDesign # Debugger is disabled in AOT mode.

View file

@ -0,0 +1,47 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--verbose_debug
import 'dart:developer';
import 'package:observatory_2/service_io.dart';
import 'service_test_common.dart';
import 'test_helper.dart';
// Line in core/print.dart
const int LINE_A = 10;
testMain() {
debugger();
print('1');
print('2');
print('3');
print('Done');
}
IsolateTest expectHitBreakpoint(String uri, int line) {
return (Isolate isolate) async {
final bpt = await isolate.addBreakpointByScriptUri(uri, line);
await resumeIsolate(isolate);
await hasStoppedAtBreakpoint(isolate);
await stoppedAtLine(line)(isolate);
await isolate.removeBreakpoint(bpt);
};
}
var tests = <IsolateTest>[
hasStoppedAtBreakpoint,
// Dart libraries are not debuggable by default
markDartColonLibrariesDebuggable,
expectHitBreakpoint('org-dartlang-sdk:///sdk/lib/core/print.dart', LINE_A),
expectHitBreakpoint('dart:core/print.dart', LINE_A),
expectHitBreakpoint('/core/print.dart', LINE_A),
resumeIsolate,
];
main(args) => runIsolateTests(args, tests, testeeConcurrent: testMain);

View file

@ -47,6 +47,7 @@ awaiter_async_stack_contents_test: SkipByDesign # Debugger is disabled in AOT mo
bad_reload_test: SkipByDesign # Hot reload is disabled in AOT mode.
break_on_activation_test: SkipByDesign # Debugger is disabled in AOT mode.
break_on_async_function_test: SkipByDesign # Debugger is disabled in AOT mode.
break_on_dart_colon_test: SkipByDesign # Debugger is disabled in AOT mode.
break_on_default_constructor_test: SkipByDesign # Debugger is disabled in AOT mode.
break_on_function_child_isolate_test: SkipByDesign # Debugger is disabled in AOT mode.
break_on_function_many_child_isolates_test: SkipByDesign # Debugger is disabled in AOT mode.

View file

@ -3129,6 +3129,7 @@ BreakpointLocation* Debugger::BreakpointLocationAtLineCol(
const GrowableObjectArray& libs = GrowableObjectArray::Handle(
isolate_->group()->object_store()->libraries());
bool is_package = script_url.StartsWith(Symbols::PackageScheme());
bool is_dart_colon = script_url.StartsWith(Symbols::DartScheme());
Script& script_for_lib = Script::Handle(zone);
for (intptr_t i = 0; i < libs.Length(); i++) {
lib ^= libs.At(i);
@ -3136,7 +3137,8 @@ BreakpointLocation* Debugger::BreakpointLocationAtLineCol(
// are available for look up. When certain script only contains
// top level functions, scripts could still be loaded correctly.
lib.EnsureTopLevelClassIsFinalized();
script_for_lib = lib.LookupScript(script_url, !is_package);
bool useResolvedUri = !is_package && !is_dart_colon;
script_for_lib = lib.LookupScript(script_url, useResolvedUri);
if (!script_for_lib.IsNull()) {
scripts.Add(script_for_lib);
}