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

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

Issue 9696020: Deoptimize functions before setting breakpoints (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
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 "vm/code_index_table.h" 7 #include "vm/code_index_table.h"
8 #include "vm/code_generator.h" 8 #include "vm/code_generator.h"
9 #include "vm/code_patcher.h" 9 #include "vm/code_patcher.h"
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
11 #include "vm/dart_entry.h" 11 #include "vm/dart_entry.h"
12 #include "vm/flags.h" 12 #include "vm/flags.h"
13 #include "vm/globals.h" 13 #include "vm/globals.h"
14 #include "vm/longjump.h" 14 #include "vm/longjump.h"
15 #include "vm/object.h" 15 #include "vm/object.h"
16 #include "vm/object_store.h" 16 #include "vm/object_store.h"
17 #include "vm/os.h" 17 #include "vm/os.h"
18 #include "vm/stack_frame.h" 18 #include "vm/stack_frame.h"
19 #include "vm/stub_code.h" 19 #include "vm/stub_code.h"
20 #include "vm/visitor.h" 20 #include "vm/visitor.h"
21 21
22 22
23 namespace dart { 23 namespace dart {
24 24
25 static const bool verbose = false; 25 static const bool verbose = false;
srdjan 2012/03/13 17:11:35 Why not add a debugger_verbose flag?
hausner 2012/03/13 20:45:03 Soon I'll give in and do so. So for I intend to re
26 26
27 27
28 SourceBreakpoint::SourceBreakpoint(const Function& func, intptr_t token_index) 28 SourceBreakpoint::SourceBreakpoint(const Function& func, intptr_t token_index)
29 : function_(func.raw()), 29 : function_(func.raw()),
30 token_index_(token_index), 30 token_index_(token_index),
31 line_number_(-1), 31 line_number_(-1),
32 is_enabled_(false), 32 is_enabled_(false),
33 next_(NULL) { 33 next_(NULL) {
34 ASSERT(!func.IsNull()); 34 ASSERT(!func.IsNull());
35 ASSERT((func.token_index() <= token_index_) && 35 ASSERT((func.token_index() <= token_index_) &&
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 if (!cls.IsNull()) { 478 if (!cls.IsNull()) {
479 function = cls.LookupStaticFunction(function_name); 479 function = cls.LookupStaticFunction(function_name);
480 if (function.IsNull()) { 480 if (function.IsNull()) {
481 function = cls.LookupDynamicFunction(function_name); 481 function = cls.LookupDynamicFunction(function_name);
482 } 482 }
483 } 483 }
484 return function.raw(); 484 return function.raw();
485 } 485 }
486 486
487 487
488 void Debugger::InstrumentForStepping(const Function &target_function) { 488 // Deoptimize function if necessary. Does not patch return addresses on the
489 // stack. If there are activation frames of this function on the stack,
490 // the optimized code will be executed when the callee returns.
491 void Debugger::EnsureFunctionIsDeoptimized(const Function& func) {
492 if (func.HasOptimizedCode()) {
493 if (verbose) {
494 printf("Deoptimizing function %s\n",
srdjan 2012/03/13 17:11:35 OS::Print
hausner 2012/03/13 20:45:03 Done.
495 String::Handle(func.name()).ToCString());
496 }
497 func.set_usage_counter(0);
498 func.set_deoptimization_counter(func.deoptimization_counter() + 1);
srdjan 2012/03/13 17:11:35 Don't increase the counter otherwise setting and c
hausner 2012/03/13 20:45:03 Done.
499 Compiler::CompileFunction(func);
500 ASSERT(!func.HasOptimizedCode());
501 }
502 }
503
504
505 void Debugger::InstrumentForStepping(const Function& target_function) {
489 if (!target_function.HasCode()) { 506 if (!target_function.HasCode()) {
490 Compiler::CompileFunction(target_function); 507 Compiler::CompileFunction(target_function);
491 // If there were any errors, ignore them silently and return without 508 // If there were any errors, ignore them silently and return without
492 // adding breakpoints to target. 509 // adding breakpoints to target.
493 if (!target_function.HasCode()) { 510 if (!target_function.HasCode()) {
494 return; 511 return;
495 } 512 }
513 } else {
514 EnsureFunctionIsDeoptimized(target_function);
srdjan 2012/03/13 17:11:35 I rather think positive: if (target.HasCode()) {
hausner 2012/03/13 20:45:03 The glass is now half full. On 2012/03/13 17:11:3
496 } 515 }
497 ASSERT(!target_function.HasOptimizedCode());
498 Code& code = Code::Handle(target_function.unoptimized_code()); 516 Code& code = Code::Handle(target_function.unoptimized_code());
499 ASSERT(!code.IsNull()); 517 ASSERT(!code.IsNull());
500 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); 518 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors());
501 for (int i = 0; i < desc.Length(); i++) { 519 for (int i = 0; i < desc.Length(); i++) {
502 CodeBreakpoint* bpt = GetCodeBreakpoint(desc.PC(i)); 520 CodeBreakpoint* bpt = GetCodeBreakpoint(desc.PC(i));
503 if (bpt != NULL) { 521 if (bpt != NULL) {
504 // There is already a breakpoint for this address. Leave it alone. 522 // There is already a breakpoint for this address. Leave it alone.
505 continue; 523 continue;
506 } 524 }
507 PcDescriptors::Kind kind = desc.DescriptorKind(i); 525 PcDescriptors::Kind kind = desc.DescriptorKind(i);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 } 574 }
557 575
558 576
559 SourceBreakpoint* Debugger::SetBreakpoint(const Function& target_function, 577 SourceBreakpoint* Debugger::SetBreakpoint(const Function& target_function,
560 intptr_t token_index) { 578 intptr_t token_index) {
561 if ((token_index < target_function.token_index()) || 579 if ((token_index < target_function.token_index()) ||
562 (target_function.end_token_index() <= token_index)) { 580 (target_function.end_token_index() <= token_index)) {
563 // The given token position is not within the target function. 581 // The given token position is not within the target function.
564 return NULL; 582 return NULL;
565 } 583 }
584 EnsureFunctionIsDeoptimized(target_function);
566 SourceBreakpoint* bpt = GetSourceBreakpoint(target_function, token_index); 585 SourceBreakpoint* bpt = GetSourceBreakpoint(target_function, token_index);
567 if (bpt != NULL) { 586 if (bpt != NULL) {
568 // A breakpoint for this location already exists, return it. 587 // A breakpoint for this location already exists, return it.
569 return bpt; 588 return bpt;
570 } 589 }
571 bpt = new SourceBreakpoint(target_function, token_index); 590 bpt = new SourceBreakpoint(target_function, token_index);
572 RegisterSourceBreakpoint(bpt); 591 RegisterSourceBreakpoint(bpt);
573 if (verbose && !target_function.HasCode()) { 592 if (verbose && !target_function.HasCode()) {
574 OS::Print("Registering breakpoint for uncompiled function '%s'" 593 OS::Print("Registering breakpoint for uncompiled function '%s'"
575 " (%s:%d)\n", 594 " (%s:%d)\n",
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 } 1040 }
1022 1041
1023 1042
1024 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { 1043 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) {
1025 ASSERT(bpt->next() == NULL); 1044 ASSERT(bpt->next() == NULL);
1026 bpt->set_next(code_breakpoints_); 1045 bpt->set_next(code_breakpoints_);
1027 code_breakpoints_ = bpt; 1046 code_breakpoints_ = bpt;
1028 } 1047 }
1029 1048
1030 } // namespace dart 1049 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698