| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 static const bool verbose = false; | 25 static const bool verbose = false; |
| 26 | 26 |
| 27 | 27 |
| 28 Breakpoint::Breakpoint(const Function& func, intptr_t pc_desc_index) | 28 Breakpoint::Breakpoint(const Function& func, intptr_t pc_desc_index) |
| 29 : function_(func.raw()), | 29 : function_(func.raw()), |
| 30 pc_desc_index_(pc_desc_index), | 30 pc_desc_index_(pc_desc_index), |
| 31 pc_(0), | 31 pc_(0), |
| 32 line_number_(-1), | 32 line_number_(-1), |
| 33 is_patched_(false), | 33 is_patched_(false), |
| 34 next_(NULL) { | 34 next_(NULL) { |
| 35 Code& code = Code::Handle(func.code()); | 35 ASSERT(!func.HasOptimizedCode()); |
| 36 Code& code = Code::Handle(func.unoptimized_code()); |
| 36 ASSERT(!code.IsNull()); // Function must be compiled. | 37 ASSERT(!code.IsNull()); // Function must be compiled. |
| 37 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); | 38 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); |
| 38 ASSERT(pc_desc_index < desc.Length()); | 39 ASSERT(pc_desc_index < desc.Length()); |
| 39 this->token_index_ = desc.TokenIndex(pc_desc_index); | 40 this->token_index_ = desc.TokenIndex(pc_desc_index); |
| 40 ASSERT(this->token_index_ > 0); | 41 ASSERT(this->token_index_ > 0); |
| 41 this->pc_ = desc.PC(pc_desc_index); | 42 this->pc_ = desc.PC(pc_desc_index); |
| 42 ASSERT(this->pc_ != 0); | 43 ASSERT(this->pc_ != 0); |
| 43 this->breakpoint_kind_ = desc.DescriptorKind(pc_desc_index); | 44 this->breakpoint_kind_ = desc.DescriptorKind(pc_desc_index); |
| 44 } | 45 } |
| 45 | 46 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 var_descriptors_(NULL), | 83 var_descriptors_(NULL), |
| 83 desc_indices_(8) { | 84 desc_indices_(8) { |
| 84 } | 85 } |
| 85 | 86 |
| 86 | 87 |
| 87 const Function& ActivationFrame::DartFunction() { | 88 const Function& ActivationFrame::DartFunction() { |
| 88 if (function_.IsNull()) { | 89 if (function_.IsNull()) { |
| 89 ASSERT(Isolate::Current() != NULL); | 90 ASSERT(Isolate::Current() != NULL); |
| 90 CodeIndexTable* code_index_table = Isolate::Current()->code_index_table(); | 91 CodeIndexTable* code_index_table = Isolate::Current()->code_index_table(); |
| 91 ASSERT(code_index_table != NULL); | 92 ASSERT(code_index_table != NULL); |
| 92 function_ = code_index_table->LookupFunction(pc_); | 93 const Code& code = Code::Handle(code_index_table->LookupCode(pc_)); |
| 94 function_ = code.function(); |
| 93 } | 95 } |
| 94 return function_; | 96 return function_; |
| 95 } | 97 } |
| 96 | 98 |
| 97 | 99 |
| 98 const char* Debugger::QualifiedFunctionName(const Function& func) { | 100 const char* Debugger::QualifiedFunctionName(const Function& func) { |
| 99 const String& func_name = String::Handle(func.name()); | 101 const String& func_name = String::Handle(func.name()); |
| 100 Class& func_class = Class::Handle(func.owner()); | 102 Class& func_class = Class::Handle(func.owner()); |
| 101 String& class_name = String::Handle(func_class.Name()); | 103 String& class_name = String::Handle(func_class.Name()); |
| 102 | 104 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 131 RawScript* ActivationFrame::SourceScript() { | 133 RawScript* ActivationFrame::SourceScript() { |
| 132 const Function& func = DartFunction(); | 134 const Function& func = DartFunction(); |
| 133 const Class& cls = Class::Handle(func.owner()); | 135 const Class& cls = Class::Handle(func.owner()); |
| 134 return cls.script(); | 136 return cls.script(); |
| 135 } | 137 } |
| 136 | 138 |
| 137 | 139 |
| 138 intptr_t ActivationFrame::TokenIndex() { | 140 intptr_t ActivationFrame::TokenIndex() { |
| 139 if (token_index_ < 0) { | 141 if (token_index_ < 0) { |
| 140 const Function& func = DartFunction(); | 142 const Function& func = DartFunction(); |
| 141 Code& code = Code::Handle(func.code()); | 143 ASSERT(!func.HasOptimizedCode()); |
| 144 Code& code = Code::Handle(func.unoptimized_code()); |
| 142 ASSERT(!code.IsNull()); | 145 ASSERT(!code.IsNull()); |
| 143 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); | 146 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); |
| 144 for (int i = 0; i < desc.Length(); i++) { | 147 for (int i = 0; i < desc.Length(); i++) { |
| 145 if (desc.PC(i) == pc_) { | 148 if (desc.PC(i) == pc_) { |
| 146 token_index_ = desc.TokenIndex(i); | 149 token_index_ = desc.TokenIndex(i); |
| 147 break; | 150 break; |
| 148 } | 151 } |
| 149 } | 152 } |
| 150 ASSERT(token_index_ >= 0); | 153 ASSERT(token_index_ >= 0); |
| 151 } | 154 } |
| 152 return token_index_; | 155 return token_index_; |
| 153 } | 156 } |
| 154 | 157 |
| 155 | 158 |
| 156 intptr_t ActivationFrame::LineNumber() { | 159 intptr_t ActivationFrame::LineNumber() { |
| 157 // Compute line number lazily since it causes scanning of the script. | 160 // Compute line number lazily since it causes scanning of the script. |
| 158 if (line_number_ < 0) { | 161 if (line_number_ < 0) { |
| 159 const Script& script = Script::Handle(SourceScript()); | 162 const Script& script = Script::Handle(SourceScript()); |
| 160 intptr_t ignore_column; | 163 intptr_t ignore_column; |
| 161 script.GetTokenLocation(TokenIndex(), &line_number_, &ignore_column); | 164 script.GetTokenLocation(TokenIndex(), &line_number_, &ignore_column); |
| 162 } | 165 } |
| 163 return line_number_; | 166 return line_number_; |
| 164 } | 167 } |
| 165 | 168 |
| 166 | 169 |
| 167 void ActivationFrame::GetDescIndices() { | 170 void ActivationFrame::GetDescIndices() { |
| 168 if (var_descriptors_ == NULL) { | 171 if (var_descriptors_ == NULL) { |
| 169 const Code& code = Code::Handle(DartFunction().code()); | 172 ASSERT(!DartFunction().HasOptimizedCode()); |
| 173 const Code& code = Code::Handle(DartFunction().unoptimized_code()); |
| 170 var_descriptors_ = | 174 var_descriptors_ = |
| 171 &LocalVarDescriptors::ZoneHandle(code.var_descriptors()); | 175 &LocalVarDescriptors::ZoneHandle(code.var_descriptors()); |
| 172 GrowableArray<String*> var_names(8); | 176 GrowableArray<String*> var_names(8); |
| 173 intptr_t activation_token_pos = TokenIndex(); | 177 intptr_t activation_token_pos = TokenIndex(); |
| 174 intptr_t var_desc_len = var_descriptors_->Length(); | 178 intptr_t var_desc_len = var_descriptors_->Length(); |
| 175 for (int cur_idx = 0; cur_idx < var_desc_len; cur_idx++) { | 179 for (int cur_idx = 0; cur_idx < var_desc_len; cur_idx++) { |
| 176 ASSERT(var_names.length() == desc_indices_.length()); | 180 ASSERT(var_names.length() == desc_indices_.length()); |
| 177 intptr_t scope_id, begin_pos, end_pos; | 181 intptr_t scope_id, begin_pos, end_pos; |
| 178 var_descriptors_->GetScopeInfo(cur_idx, &scope_id, &begin_pos, &end_pos); | 182 var_descriptors_->GetScopeInfo(cur_idx, &scope_id, &begin_pos, &end_pos); |
| 179 if ((begin_pos <= activation_token_pos) && | 183 if ((begin_pos <= activation_token_pos) && |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 | 417 |
| 414 void Debugger::InstrumentForStepping(const Function &target_function) { | 418 void Debugger::InstrumentForStepping(const Function &target_function) { |
| 415 if (!target_function.HasCode()) { | 419 if (!target_function.HasCode()) { |
| 416 Compiler::CompileFunction(target_function); | 420 Compiler::CompileFunction(target_function); |
| 417 // If there were any errors, ignore them silently and return without | 421 // If there were any errors, ignore them silently and return without |
| 418 // adding breakpoints to target. | 422 // adding breakpoints to target. |
| 419 if (!target_function.HasCode()) { | 423 if (!target_function.HasCode()) { |
| 420 return; | 424 return; |
| 421 } | 425 } |
| 422 } | 426 } |
| 423 Code& code = Code::Handle(target_function.code()); | 427 ASSERT(!target_function.HasOptimizedCode()); |
| 428 Code& code = Code::Handle(target_function.unoptimized_code()); |
| 424 ASSERT(!code.IsNull()); | 429 ASSERT(!code.IsNull()); |
| 425 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); | 430 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); |
| 426 for (int i = 0; i < desc.Length(); i++) { | 431 for (int i = 0; i < desc.Length(); i++) { |
| 427 Breakpoint* bpt = GetBreakpoint(desc.PC(i)); | 432 Breakpoint* bpt = GetBreakpoint(desc.PC(i)); |
| 428 if (bpt != NULL) { | 433 if (bpt != NULL) { |
| 429 // There is already a breakpoint for this address. Leave it alone. | 434 // There is already a breakpoint for this address. Leave it alone. |
| 430 continue; | 435 continue; |
| 431 } | 436 } |
| 432 PcDescriptors::Kind kind = desc.DescriptorKind(i); | 437 PcDescriptors::Kind kind = desc.DescriptorKind(i); |
| 433 if ((kind == PcDescriptors::kIcCall) || | 438 if ((kind == PcDescriptors::kIcCall) || |
| (...skipping 17 matching lines...) Expand all Loading... |
| 451 (target_function.end_token_index() <= token_index)) { | 456 (target_function.end_token_index() <= token_index)) { |
| 452 // The given token position is not within the target function. | 457 // The given token position is not within the target function. |
| 453 return NULL; | 458 return NULL; |
| 454 } | 459 } |
| 455 if (!target_function.HasCode()) { | 460 if (!target_function.HasCode()) { |
| 456 *error = Compiler::CompileFunction(target_function); | 461 *error = Compiler::CompileFunction(target_function); |
| 457 if (!error->IsNull()) { | 462 if (!error->IsNull()) { |
| 458 return NULL; | 463 return NULL; |
| 459 } | 464 } |
| 460 } | 465 } |
| 461 Code& code = Code::Handle(target_function.code()); | 466 ASSERT(!target_function.HasOptimizedCode()); |
| 467 Code& code = Code::Handle(target_function.unoptimized_code()); |
| 462 ASSERT(!code.IsNull()); | 468 ASSERT(!code.IsNull()); |
| 463 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); | 469 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); |
| 464 for (int i = 0; i < desc.Length(); i++) { | 470 for (int i = 0; i < desc.Length(); i++) { |
| 465 if (desc.TokenIndex(i) < token_index) { | 471 if (desc.TokenIndex(i) < token_index) { |
| 466 continue; | 472 continue; |
| 467 } | 473 } |
| 468 Breakpoint* bpt = GetBreakpoint(desc.PC(i)); | 474 Breakpoint* bpt = GetBreakpoint(desc.PC(i)); |
| 469 if (bpt != NULL) { | 475 if (bpt != NULL) { |
| 470 // Found existing breakpoint. | 476 // Found existing breakpoint. |
| 471 return bpt; | 477 return bpt; |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 | 838 |
| 833 | 839 |
| 834 void Debugger::RegisterBreakpoint(Breakpoint* bpt) { | 840 void Debugger::RegisterBreakpoint(Breakpoint* bpt) { |
| 835 ASSERT(bpt->next() == NULL); | 841 ASSERT(bpt->next() == NULL); |
| 836 bpt->set_next(this->breakpoints_); | 842 bpt->set_next(this->breakpoints_); |
| 837 this->breakpoints_ = bpt; | 843 this->breakpoints_ = bpt; |
| 838 } | 844 } |
| 839 | 845 |
| 840 | 846 |
| 841 } // namespace dart | 847 } // namespace dart |
| OLD | NEW |