Skip to content

Commit f0ef900

Browse files
author
Siva Chandra
committed
Fix setting breakpoints in parts of a library.
This fixes the regression caused by 1eaa3dd and reported in #29988. When picking a class to set a breakpoint, instead of rejecting classes not defined in the script, we now reject classes which do not belong to the library to which the script belongs. [email protected] Review-Url: https://codereview.chromium.org/2965673004 .
1 parent b1fdd84 commit f0ef900

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

runtime/tests/vm/vm.status

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ cc/Debug_ScriptGetTokenInfo_MultiLineInterpolation: Fail
273273
cc/Debugger_PrintBreakpointsToJSONArray: Fail
274274
cc/Debugger_Rewind_Optimized: SkipSlow
275275
cc/Debugger_SetBreakpointInFunctionLiteralFieldInitializers: Crash
276+
cc/Debugger_SetBreakpointInPartOfLibrary: Crash
276277
cc/ErrorHandleBasics: Fail
277278
cc/EvalExpression: Crash
278279
cc/ExternalUint8ClampedArrayAccess: Fail

runtime/vm/debugger.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2710,6 +2710,8 @@ bool Debugger::FindBestFit(const Script& script,
27102710
Function* best_fit) {
27112711
Zone* zone = Thread::Current()->zone();
27122712
Class& cls = Class::Handle(zone);
2713+
Library& lib = Library::Handle(zone, script.FindLibrary());
2714+
ASSERT(!lib.IsNull());
27132715
const GrowableObjectArray& closures = GrowableObjectArray::Handle(
27142716
zone, isolate_->object_store()->closure_functions());
27152717
Array& functions = Array::Handle(zone);
@@ -2740,7 +2742,9 @@ bool Debugger::FindBestFit(const Script& script,
27402742
continue;
27412743
}
27422744
cls = class_table.At(i);
2743-
if (cls.script() != script.raw()) {
2745+
// This class is relevant to us only if it belongs to the
2746+
// library to which |script| belongs.
2747+
if (cls.library() != lib.raw()) {
27442748
continue;
27452749
}
27462750
// Parse class definition if not done yet.
@@ -2786,6 +2790,11 @@ bool Debugger::FindBestFit(const Script& script,
27862790
TokenPosition end;
27872791
field ^= fields.At(pos);
27882792
ASSERT(!field.IsNull());
2793+
if (field.Script() != script.raw()) {
2794+
// The field should be defined in the script we want to set
2795+
// the breakpoint in.
2796+
continue;
2797+
}
27892798
if (Parser::FieldHasFunctionLiteralInitializer(field, &start, &end)) {
27902799
if ((start <= token_pos && token_pos <= end) ||
27912800
(token_pos <= start && start <= last_token_pos)) {

runtime/vm/debugger_test.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,37 @@ static void PausedInClosuresHandler(Dart_IsolateId isolate_id,
8080
closure_hit_count++;
8181
}
8282

83+
TEST_CASE(Debugger_SetBreakpointInPartOfLibrary) {
84+
const char* kMainScript = "main() {}\n";
85+
const char* kLib = "library test_lib;\n";
86+
const char* kLibPart =
87+
"part of test_lib;\n"
88+
"void func(int a, int b) {\n"
89+
" return a + b;\n"
90+
"}\n";
91+
SetFlagScope<bool> sfs(&FLAG_remove_script_timestamps_for_test, true);
92+
Dart_Handle root_lib = TestCase::LoadTestScript(kMainScript, NULL);
93+
EXPECT_VALID(root_lib);
94+
95+
Dart_Handle url = NewString("test_lib_url");
96+
Dart_Handle lib_source = NewString(kLib);
97+
Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), lib_source, 0, 0);
98+
EXPECT_VALID(lib);
99+
EXPECT(Dart_IsLibrary(lib));
100+
101+
Dart_Handle part_url = NewString("part_url");
102+
Dart_Handle part_source = NewString(kLibPart);
103+
Dart_Handle result =
104+
Dart_LoadSource(lib, part_url, Dart_Null(), part_source, 0, 0);
105+
EXPECT_VALID(result);
106+
EXPECT(Dart_IsLibrary(result));
107+
EXPECT(Dart_IdentityEquals(lib, result));
108+
109+
result = Dart_SetBreakpoint(part_url, 3);
110+
EXPECT_VALID(result);
111+
EXPECT(Dart_IsInteger(result));
112+
}
113+
83114
TEST_CASE(Debugger_SetBreakpointInFunctionLiteralFieldInitializers) {
84115
const char* kScriptChars =
85116
"main() {\n"

0 commit comments

Comments
 (0)