Skip to content

Commit 58882ff

Browse files
jensjohacommit-bot@chromium.org
authored andcommitted
VM reads import uri if kernel binary version >= 22
This CL also includes a service test for setting a breakpoint in a part file from a package. Fixes #35859. Change-Id: I0199006a87746dc1c27721ba0d51e502e76cb107 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97104 Reviewed-by: Siva Annamalai <[email protected]> Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent 3c2bfa5 commit 58882ff

File tree

11 files changed

+171
-4
lines changed

11 files changed

+171
-4
lines changed

.packages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ mockito:third_party/pkg/mockito/lib
6262
mustache:third_party/pkg/mustache/lib
6363
oauth2:third_party/pkg/oauth2/lib
6464
observatory:runtime/observatory/lib
65+
observatory_test_package:runtime/observatory/tests/service/observatory_test_package
6566
package_config:third_party/pkg_tested/package_config/lib
6667
package_resolver:third_party/pkg_tested/package_resolver/lib
6768
path:third_party/pkg/path/lib

runtime/observatory/.packages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ string_scanner:../../third_party/pkg/string_scanner/lib
3232
term_glyph:../../third_party/pkg/term_glyph/lib
3333
test:../../third_party/pkg/test/lib
3434
typed_data:../../third_party/pkg/typed_data/lib
35+
observatory_test_package:tests/service/observatory_test_package
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
library breakpoint_in_parts_class;
6+
7+
import 'package:observatory_test_package/has_part.dart' as hasPart;
8+
import 'test_helper.dart';
9+
import 'service_test_common.dart';
10+
11+
const int LINE = 87;
12+
const String breakpointFile = "package:observatory_test_package/the_part.dart";
13+
const String shortFile = "the_part.dart";
14+
15+
code() {
16+
hasPart.main();
17+
}
18+
19+
List<String> stops = [];
20+
21+
List<String> expected = [
22+
"$shortFile:${LINE + 0}:5", // on 'print'
23+
"$shortFile:${LINE + 1}:3" // on class ending '}'
24+
];
25+
26+
var tests = <IsolateTest>[
27+
hasPausedAtStart,
28+
setBreakpointAtUriAndLine(breakpointFile, LINE),
29+
runStepThroughProgramRecordingStops(stops),
30+
checkRecordedStops(stops, expected)
31+
];
32+
33+
main(args) {
34+
runIsolateTestsSynchronous(args, tests,
35+
testeeConcurrent: code, pause_on_start: true, pause_on_exit: true);
36+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
observatory_test_package:.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
library has_part;
6+
7+
part 'the_part.dart';
8+
9+
main() {
10+
Foo10 foo = new Foo10("Foo!");
11+
print(foo);
12+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
part of has_part;
6+
7+
void foo() {
8+
print("lalala");
9+
}
10+
11+
class Foo1 {
12+
final foo;
13+
14+
Foo1(this.foo) {
15+
print("hello from foo!");
16+
}
17+
}
18+
19+
class Foo2 {
20+
final foo;
21+
22+
Foo2(this.foo) {
23+
print("hello from foo!");
24+
}
25+
}
26+
27+
class Foo3 {
28+
final foo;
29+
30+
Foo3(this.foo) {
31+
print("hello from foo!");
32+
}
33+
}
34+
35+
class Foo4 {
36+
final foo;
37+
38+
Foo4(this.foo) {
39+
print("hello from foo!");
40+
}
41+
}
42+
43+
class Foo5 {
44+
final foo;
45+
46+
Foo5(this.foo) {
47+
print("hello from foo!");
48+
}
49+
}
50+
51+
class Foo6 {
52+
final foo;
53+
54+
Foo6(this.foo) {
55+
print("hello from foo!");
56+
}
57+
}
58+
59+
class Foo7 {
60+
final foo;
61+
62+
Foo7(this.foo) {
63+
print("hello from foo!");
64+
}
65+
}
66+
67+
class Foo8 {
68+
final foo;
69+
70+
Foo8(this.foo) {
71+
print("hello from foo!");
72+
}
73+
}
74+
75+
class Foo9 {
76+
final foo;
77+
78+
Foo9(this.foo) {
79+
print("hello from foo!");
80+
}
81+
}
82+
83+
class Foo10 {
84+
final foo;
85+
86+
Foo10(this.foo) {
87+
print("hello from foo!");
88+
}
89+
}
90+
91+
var foo2 = foo() as dynamic;

runtime/vm/compiler/frontend/kernel_translation_helper.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,6 +2617,26 @@ RawTypedData* KernelReaderHelper::GetLineStartsFor(intptr_t index) {
26172617
return line_starts_data.raw();
26182618
}
26192619

2620+
String& KernelReaderHelper::SourceTableImportUriFor(intptr_t index,
2621+
uint32_t binaryVersion) {
2622+
if (binaryVersion < 22) {
2623+
return SourceTableUriFor(index);
2624+
}
2625+
2626+
AlternativeReadingScope alt(&reader_);
2627+
SetOffset(GetOffsetForSourceInfo(index));
2628+
SkipBytes(ReadUInt()); // skip uri.
2629+
SkipBytes(ReadUInt()); // skip source.
2630+
const intptr_t line_start_count = ReadUInt(); // read number of line start
2631+
// entries.
2632+
for (intptr_t i = 0; i < line_start_count; ++i) {
2633+
ReadUInt();
2634+
}
2635+
2636+
intptr_t size = ReadUInt(); // read import uri List<byte> size.
2637+
return H.DartString(reader_.BufferAt(ReaderOffset()), size, Heap::kOld);
2638+
}
2639+
26202640
intptr_t ActiveClass::MemberTypeParameterCount(Zone* zone) {
26212641
ASSERT(member != NULL);
26222642
if (member->IsFactory()) {

runtime/vm/compiler/frontend/kernel_translation_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ class KernelReaderHelper {
10611061
String& SourceTableUriFor(intptr_t index);
10621062
const String& GetSourceFor(intptr_t index);
10631063
RawTypedData* GetLineStartsFor(intptr_t index);
1064+
String& SourceTableImportUriFor(intptr_t index, uint32_t binaryVersion);
10641065

10651066
Zone* zone_;
10661067
TranslationHelper& translation_helper_;

runtime/vm/kernel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class Program {
7373
const char** error = nullptr);
7474

7575
bool is_single_program() { return single_program_; }
76+
uint32_t binary_version() { return binary_version_; }
7677
NameIndex main_method() { return main_method_reference_; }
7778
intptr_t source_table_offset() const { return source_table_offset_; }
7879
intptr_t string_table_offset() const { return string_table_offset_; }
@@ -92,6 +93,7 @@ class Program {
9293
Program() : kernel_data_(NULL), kernel_data_size_(-1) {}
9394

9495
bool single_program_;
96+
uint32_t binary_version_;
9597
NameIndex main_method_reference_; // Procedure.
9698
intptr_t library_count_;
9799

runtime/vm/kernel_binary.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Program* Program::ReadFrom(Reader* reader, const char** error) {
7777
}
7878

7979
Program* program = new Program();
80+
program->binary_version_ = formatVersion;
8081
program->kernel_data_ = reader->buffer();
8182
program->kernel_data_size_ = reader->size();
8283

runtime/vm/kernel_loader.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,6 +1950,8 @@ const Object& KernelLoader::ClassForScriptAt(const Class& klass,
19501950

19511951
RawScript* KernelLoader::LoadScriptAt(intptr_t index) {
19521952
const String& uri_string = helper_.SourceTableUriFor(index);
1953+
const String& import_uri_string =
1954+
helper_.SourceTableImportUriFor(index, program_->binary_version());
19531955
const String& script_source = helper_.GetSourceFor(index);
19541956
String& sources = String::Handle(Z);
19551957
TypedData& line_starts =
@@ -1975,10 +1977,9 @@ RawScript* KernelLoader::LoadScriptAt(intptr_t index) {
19751977
sources = script_source.raw();
19761978
}
19771979

1978-
const Script& script = Script::Handle(
1979-
Z, Script::New(uri_string, sources, RawScript::kKernelTag));
1980-
String& script_url = String::Handle();
1981-
script_url = script.url();
1980+
const Script& script =
1981+
Script::Handle(Z, Script::New(import_uri_string, uri_string, sources,
1982+
RawScript::kKernelTag));
19821983
script.set_kernel_script_index(index);
19831984
script.set_kernel_program_info(kernel_program_info_);
19841985
script.set_line_starts(line_starts);

0 commit comments

Comments
 (0)