Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: runtime/vm/debugger.cc

Issue 2898153006: Cleanup how a best fit function is found when setting a breakpoint. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/debugger.h" 5 #include "vm/debugger.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "platform/address_sanitizer.h" 9 #include "platform/address_sanitizer.h"
10 10
(...skipping 2631 matching lines...) Expand 10 before | Expand all | Expand 10 after
2642 *best_fit = func->raw(); 2642 *best_fit = func->raw();
2643 } else { 2643 } else {
2644 if ((func->token_pos() > best_fit->token_pos()) && 2644 if ((func->token_pos() > best_fit->token_pos()) &&
2645 ((func->end_token_pos() <= best_fit->end_token_pos()))) { 2645 ((func->end_token_pos() <= best_fit->end_token_pos()))) {
2646 *best_fit = func->raw(); 2646 *best_fit = func->raw();
2647 } 2647 }
2648 } 2648 }
2649 } 2649 }
2650 2650
2651 2651
2652 static bool IsTokenPosWithinFunction(const Function& func, TokenPosition pos) {
2653 return (func.token_pos() <= pos && pos <= func.end_token_pos());
2654 }
2655
2656
2652 RawFunction* Debugger::FindBestFit(const Script& script, 2657 RawFunction* Debugger::FindBestFit(const Script& script,
2653 TokenPosition token_pos) { 2658 TokenPosition token_pos) {
2654 Zone* zone = Thread::Current()->zone(); 2659 Zone* zone = Thread::Current()->zone();
2655 Class& cls = Class::Handle(zone); 2660 Class& cls = Class::Handle(zone);
2656 Array& functions = Array::Handle(zone); 2661 Array& functions = Array::Handle(zone);
2657 GrowableObjectArray& closures = GrowableObjectArray::Handle(zone); 2662 GrowableObjectArray& closures = GrowableObjectArray::Handle(zone);
siva 2017/05/25 01:26:25 Maybe this can be const GrowableObjectArray& clos
sivachandra 2017/05/25 04:48:18 Done.
2658 Function& function = Function::Handle(zone); 2663 Function& function = Function::Handle(zone);
2659 Function& best_fit = Function::Handle(zone); 2664 Function& best_fit = Function::Handle(zone);
2660 Error& error = Error::Handle(zone); 2665 Error& error = Error::Handle(zone);
2661 2666
2662 closures = isolate_->object_store()->closure_functions(); 2667 closures = isolate_->object_store()->closure_functions();
siva 2017/05/25 01:26:25 this line will not be needed if initialized in abo
sivachandra 2017/05/25 04:48:18 Done.
2663 const intptr_t num_closures = closures.Length(); 2668 const intptr_t num_closures = closures.Length();
2664 for (intptr_t i = 0; i < num_closures; i++) { 2669 for (intptr_t i = 0; i < num_closures; i++) {
2665 function ^= closures.At(i); 2670 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.
2667 SelectBestFit(&best_fit, &function); 2676 SelectBestFit(&best_fit, &function);
2668 } 2677 }
2669 } 2678 }
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 }
2670 2685
2671 const ClassTable& class_table = *isolate_->class_table(); 2686 const ClassTable& class_table = *isolate_->class_table();
2672 const intptr_t num_classes = class_table.NumCids(); 2687 const intptr_t num_classes = class_table.NumCids();
2673 for (intptr_t i = 1; i < num_classes; i++) { 2688 for (intptr_t i = 1; i < num_classes; i++) {
2674 if (class_table.HasValidClassAt(i)) { 2689 if (class_table.HasValidClassAt(i)) {
2675 cls = class_table.At(i); 2690 cls = class_table.At(i);
2676 // Note: if this class has been parsed and finalized already, 2691 ASSERT(!cls.IsNull());
2677 // we need to check the functions of this class even if 2692 if (cls.script() != script.raw()) {
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()) {
2683 continue; 2693 continue;
2684 } 2694 }
2685 // Parse class definition if not done yet. 2695 // Parse class definition if not done yet.
2686 error = cls.EnsureIsFinalized(Thread::Current()); 2696 error = cls.EnsureIsFinalized(Thread::Current());
2687 if (!error.IsNull()) { 2697 if (!error.IsNull()) {
2688 // Ignore functions in this class. 2698 // Ignore functions in this class.
2689 // TODO(hausner): Should we propagate this error? How? 2699 // TODO(hausner): Should we propagate this error? How?
2690 // EnsureIsFinalized only returns an error object if there 2700 // EnsureIsFinalized only returns an error object if there
2691 // is no longjump base on the stack. 2701 // is no longjump base on the stack.
2692 continue; 2702 continue;
2693 } 2703 }
2694 functions = cls.functions(); 2704 functions = cls.functions();
2695 if (!functions.IsNull()) { 2705 if (!functions.IsNull()) {
2696 const intptr_t num_functions = functions.Length(); 2706 const intptr_t num_functions = functions.Length();
2697 for (intptr_t pos = 0; pos < num_functions; pos++) { 2707 for (intptr_t pos = 0; pos < num_functions; pos++) {
2698 function ^= functions.At(pos); 2708 function ^= functions.At(pos);
2699 ASSERT(!function.IsNull()); 2709 ASSERT(!function.IsNull());
2700 if (FunctionContains(function, script, token_pos)) { 2710 if (IsTokenPosWithinFunction(function, token_pos)) {
2701 SelectBestFit(&best_fit, &function); 2711 // Closures and inner functions within a class method are not
2712 // present in the functions of a class. Hence, we can return
2713 // right away as looking through other functions of a class
2714 // will not narrow down to any inner function/closure.
2715 return function.raw();
2702 } 2716 }
2703 } 2717 }
2704 } 2718 }
2705 } 2719 }
2706 } 2720 }
2707 return best_fit.raw(); 2721 return best_fit.raw();
siva 2017/05/25 01:26:25 can this be return Function::null();
sivachandra 2017/05/25 04:48:18 Done.
2708 } 2722 }
2709 2723
2710 2724
2711 BreakpointLocation* Debugger::SetBreakpoint(const Script& script, 2725 BreakpointLocation* Debugger::SetBreakpoint(const Script& script,
2712 TokenPosition token_pos, 2726 TokenPosition token_pos,
2713 TokenPosition last_token_pos, 2727 TokenPosition last_token_pos,
2714 intptr_t requested_line, 2728 intptr_t requested_line,
2715 intptr_t requested_column) { 2729 intptr_t requested_column) {
2716 Function& func = Function::Handle(); 2730 Function& func = Function::Handle();
2717 func = FindBestFit(script, token_pos); 2731 func = FindBestFit(script, token_pos);
(...skipping 1710 matching lines...) Expand 10 before | Expand all | Expand 10 after
4428 4442
4429 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { 4443 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) {
4430 ASSERT(bpt->next() == NULL); 4444 ASSERT(bpt->next() == NULL);
4431 bpt->set_next(code_breakpoints_); 4445 bpt->set_next(code_breakpoints_);
4432 code_breakpoints_ = bpt; 4446 code_breakpoints_ = bpt;
4433 } 4447 }
4434 4448
4435 #endif // !PRODUCT 4449 #endif // !PRODUCT
4436 4450
4437 } // namespace dart 4451 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698