Skip to content

Commit 1eaa3dd

Browse files
author
Siva Chandra
committed
Cleanup how a best fit function is found when setting a breakpoint.
1. Look for functions/closures only in the script where the breakpoint is being set. 2. If an inner most closure is found, return that as the best fit. 3. When going over a class' functions, return immediately when a fit is found as going over the other class functions will not yield a narrower fit. BUG= [email protected] Review-Url: https://codereview.chromium.org/2898153006 .
1 parent 20dc749 commit 1eaa3dd

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

runtime/vm/debugger.cc

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,37 +2649,46 @@ static void SelectBestFit(Function* best_fit, Function* func) {
26492649
}
26502650

26512651

2652+
static bool IsTokenPosWithinFunction(const Function& func, TokenPosition pos) {
2653+
return (func.token_pos() <= pos && pos <= func.end_token_pos());
2654+
}
2655+
2656+
26522657
RawFunction* Debugger::FindBestFit(const Script& script,
26532658
TokenPosition token_pos) {
26542659
Zone* zone = Thread::Current()->zone();
26552660
Class& cls = Class::Handle(zone);
26562661
Array& functions = Array::Handle(zone);
2657-
GrowableObjectArray& closures = GrowableObjectArray::Handle(zone);
2662+
const GrowableObjectArray& closures = GrowableObjectArray::Handle(
2663+
zone, isolate_->object_store()->closure_functions());
26582664
Function& function = Function::Handle(zone);
26592665
Function& best_fit = Function::Handle(zone);
26602666
Error& error = Error::Handle(zone);
26612667

2662-
closures = isolate_->object_store()->closure_functions();
26632668
const intptr_t num_closures = closures.Length();
26642669
for (intptr_t i = 0; i < num_closures; i++) {
26652670
function ^= closures.At(i);
2666-
if (FunctionContains(function, script, token_pos)) {
2671+
if (function.script() != script.raw()) {
2672+
continue;
2673+
}
2674+
if (IsTokenPosWithinFunction(function, token_pos)) {
2675+
// Select the inner most closure.
26672676
SelectBestFit(&best_fit, &function);
26682677
}
26692678
}
2679+
if (!best_fit.IsNull()) {
2680+
// The inner most closure found will be the best fit. Going
2681+
// over class functions below will not help in any further
2682+
// narrowing.
2683+
return best_fit.raw();
2684+
}
26702685

26712686
const ClassTable& class_table = *isolate_->class_table();
26722687
const intptr_t num_classes = class_table.NumCids();
26732688
for (intptr_t i = 1; i < num_classes; i++) {
26742689
if (class_table.HasValidClassAt(i)) {
26752690
cls = class_table.At(i);
2676-
// Note: if this class has been parsed and finalized already,
2677-
// we need to check the functions of this class even if
2678-
// it is defined in a different 'script'. There could
2679-
// be mixin functions from the given script in this class.
2680-
// However, if this class is not parsed yet (not finalized),
2681-
// we can ignore it and avoid the side effect of parsing it.
2682-
if ((cls.script() != script.raw()) && !cls.is_finalized()) {
2691+
if (cls.script() != script.raw()) {
26832692
continue;
26842693
}
26852694
// Parse class definition if not done yet.
@@ -2697,14 +2706,18 @@ RawFunction* Debugger::FindBestFit(const Script& script,
26972706
for (intptr_t pos = 0; pos < num_functions; pos++) {
26982707
function ^= functions.At(pos);
26992708
ASSERT(!function.IsNull());
2700-
if (FunctionContains(function, script, token_pos)) {
2701-
SelectBestFit(&best_fit, &function);
2709+
if (IsTokenPosWithinFunction(function, token_pos)) {
2710+
// Closures and inner functions within a class method are not
2711+
// present in the functions of a class. Hence, we can return
2712+
// right away as looking through other functions of a class
2713+
// will not narrow down to any inner function/closure.
2714+
return function.raw();
27022715
}
27032716
}
27042717
}
27052718
}
27062719
}
2707-
return best_fit.raw();
2720+
return Function::null();
27082721
}
27092722

27102723

0 commit comments

Comments
 (0)