| OLD | NEW |
| 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 "vm/code_generator.h" | 9 #include "vm/code_generator.h" |
| 10 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 void CodeBreakpoint::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 132 void CodeBreakpoint::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 133 visitor->VisitPointer(reinterpret_cast<RawObject**>(&function_)); | 133 visitor->VisitPointer(reinterpret_cast<RawObject**>(&function_)); |
| 134 } | 134 } |
| 135 | 135 |
| 136 | 136 |
| 137 ActivationFrame::ActivationFrame(uword pc, uword fp, uword sp, | 137 ActivationFrame::ActivationFrame(uword pc, uword fp, uword sp, |
| 138 const Context& ctx) | 138 const Context& ctx) |
| 139 : pc_(pc), fp_(fp), sp_(sp), | 139 : pc_(pc), fp_(fp), sp_(sp), |
| 140 ctx_(Context::ZoneHandle(ctx.raw())), | 140 ctx_(Context::ZoneHandle(ctx.raw())), |
| 141 function_(Function::ZoneHandle()), | 141 function_(Function::ZoneHandle()), |
| 142 code_(Code::ZoneHandle()), |
| 142 token_pos_(-1), | 143 token_pos_(-1), |
| 143 pc_desc_index_(-1), | 144 pc_desc_index_(-1), |
| 144 line_number_(-1), | 145 line_number_(-1), |
| 145 context_level_(-1), | 146 context_level_(-1), |
| 146 vars_initialized_(false), | 147 vars_initialized_(false), |
| 147 var_descriptors_(LocalVarDescriptors::ZoneHandle()), | 148 var_descriptors_(LocalVarDescriptors::ZoneHandle()), |
| 148 desc_indices_(8), | 149 desc_indices_(8), |
| 149 pc_desc_(PcDescriptors::ZoneHandle()) { | 150 pc_desc_(PcDescriptors::ZoneHandle()) { |
| 150 } | 151 } |
| 151 | 152 |
| 152 | 153 |
| 154 const Code& ActivationFrame::DartCode() { |
| 155 if (code_.IsNull()) { |
| 156 Isolate* isolate = Isolate::Current(); |
| 157 ASSERT(isolate != NULL); |
| 158 code_ = Code::LookupCode(pc_); |
| 159 } |
| 160 return code_; |
| 161 } |
| 162 |
| 163 |
| 153 const Function& ActivationFrame::DartFunction() { | 164 const Function& ActivationFrame::DartFunction() { |
| 154 if (function_.IsNull()) { | 165 if (function_.IsNull()) { |
| 155 Isolate* isolate = Isolate::Current(); | 166 function_ = DartCode().function(); |
| 156 ASSERT(isolate != NULL); | |
| 157 const Code& code = Code::Handle(Code::LookupCode(pc_)); | |
| 158 function_ = code.function(); | |
| 159 } | 167 } |
| 160 return function_; | 168 return function_; |
| 161 } | 169 } |
| 162 | 170 |
| 163 | 171 |
| 164 void Debugger::SignalIsolateEvent(EventType type) { | 172 void Debugger::SignalIsolateEvent(EventType type) { |
| 165 if (event_handler_ != NULL) { | 173 if (event_handler_ != NULL) { |
| 166 Debugger* debugger = Isolate::Current()->debugger(); | 174 Debugger* debugger = Isolate::Current()->debugger(); |
| 167 ASSERT(debugger != NULL); | 175 ASSERT(debugger != NULL); |
| 168 DebuggerEvent event; | 176 DebuggerEvent event; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 236 |
| 229 RawLibrary* ActivationFrame::Library() { | 237 RawLibrary* ActivationFrame::Library() { |
| 230 const Function& func = DartFunction(); | 238 const Function& func = DartFunction(); |
| 231 const Class& cls = Class::Handle(func.Owner()); | 239 const Class& cls = Class::Handle(func.Owner()); |
| 232 return cls.library(); | 240 return cls.library(); |
| 233 } | 241 } |
| 234 | 242 |
| 235 | 243 |
| 236 void ActivationFrame::GetPcDescriptors() { | 244 void ActivationFrame::GetPcDescriptors() { |
| 237 if (pc_desc_.IsNull()) { | 245 if (pc_desc_.IsNull()) { |
| 238 const Function& func = DartFunction(); | 246 const Code& code = DartCode(); |
| 239 ASSERT(!func.HasOptimizedCode()); | |
| 240 Code& code = Code::Handle(func.unoptimized_code()); | |
| 241 ASSERT(!code.IsNull()); | 247 ASSERT(!code.IsNull()); |
| 242 pc_desc_ = code.pc_descriptors(); | 248 pc_desc_ = code.pc_descriptors(); |
| 243 ASSERT(!pc_desc_.IsNull()); | 249 ASSERT(!pc_desc_.IsNull()); |
| 244 } | 250 } |
| 245 } | 251 } |
| 246 | 252 |
| 247 | 253 |
| 248 // Compute token_pos_ and pc_desc_index_. | 254 // Compute token_pos_ and pc_desc_index_. |
| 249 intptr_t ActivationFrame::TokenPos() { | 255 intptr_t ActivationFrame::TokenPos() { |
| 250 if (token_pos_ < 0) { | 256 if (token_pos_ < 0) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 276 if (line_number_ < 0) { | 282 if (line_number_ < 0) { |
| 277 const Script& script = Script::Handle(SourceScript()); | 283 const Script& script = Script::Handle(SourceScript()); |
| 278 intptr_t ignore_column; | 284 intptr_t ignore_column; |
| 279 script.GetTokenLocation(TokenPos(), &line_number_, &ignore_column); | 285 script.GetTokenLocation(TokenPos(), &line_number_, &ignore_column); |
| 280 } | 286 } |
| 281 return line_number_; | 287 return line_number_; |
| 282 } | 288 } |
| 283 | 289 |
| 284 | 290 |
| 285 void ActivationFrame::GetVarDescriptors() { | 291 void ActivationFrame::GetVarDescriptors() { |
| 286 if (!var_descriptors_.IsNull()) { | 292 if (var_descriptors_.IsNull()) { |
| 287 return; | 293 const Code& code = DartCode(); |
| 294 var_descriptors_ = code.var_descriptors(); |
| 295 ASSERT(!var_descriptors_.IsNull()); |
| 288 } | 296 } |
| 289 ASSERT(!DartFunction().HasOptimizedCode()); | |
| 290 const Code& code = Code::Handle(DartFunction().unoptimized_code()); | |
| 291 var_descriptors_ = code.var_descriptors(); | |
| 292 ASSERT(!var_descriptors_.IsNull()); | |
| 293 } | 297 } |
| 294 | 298 |
| 295 | 299 |
| 296 // Calculate the context level at the current token index of the frame. | 300 // Calculate the context level at the current token index of the frame. |
| 297 intptr_t ActivationFrame::ContextLevel() { | 301 intptr_t ActivationFrame::ContextLevel() { |
| 298 if (context_level_ < 0) { | 302 if (context_level_ < 0) { |
| 299 context_level_ = 0; | 303 context_level_ = 0; |
| 300 intptr_t pc_desc_idx = PcDescIndex(); | 304 intptr_t pc_desc_idx = PcDescIndex(); |
| 301 ASSERT(!pc_desc_.IsNull()); | 305 ASSERT(!pc_desc_.IsNull()); |
| 302 if (pc_desc_.DescriptorKind(pc_desc_idx) == PcDescriptors::kReturn) { | 306 if (pc_desc_.DescriptorKind(pc_desc_idx) == PcDescriptors::kReturn) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 // Caller uses same context chain. | 346 // Caller uses same context chain. |
| 343 return ctx_.raw(); | 347 return ctx_.raw(); |
| 344 } | 348 } |
| 345 | 349 |
| 346 | 350 |
| 347 void ActivationFrame::GetDescIndices() { | 351 void ActivationFrame::GetDescIndices() { |
| 348 if (vars_initialized_) { | 352 if (vars_initialized_) { |
| 349 return; | 353 return; |
| 350 } | 354 } |
| 351 GetVarDescriptors(); | 355 GetVarDescriptors(); |
| 352 // TODO(hausner): Consider replacing this GrowableArray. | 356 |
| 357 // We don't trust variable descriptors in optimized code. |
| 358 // Rather than potentially displaying incorrect values, we |
| 359 // pretend that there are no variables in the frame. |
| 360 // We should be more clever about this in the future. |
| 361 if (DartCode().is_optimized()) { |
| 362 vars_initialized_ = true; |
| 363 return; |
| 364 } |
| 365 |
| 353 GrowableArray<String*> var_names(8); | 366 GrowableArray<String*> var_names(8); |
| 354 intptr_t activation_token_pos = TokenPos(); | 367 intptr_t activation_token_pos = TokenPos(); |
| 355 intptr_t var_desc_len = var_descriptors_.Length(); | 368 intptr_t var_desc_len = var_descriptors_.Length(); |
| 356 for (int cur_idx = 0; cur_idx < var_desc_len; cur_idx++) { | 369 for (int cur_idx = 0; cur_idx < var_desc_len; cur_idx++) { |
| 357 ASSERT(var_names.length() == desc_indices_.length()); | 370 ASSERT(var_names.length() == desc_indices_.length()); |
| 358 RawLocalVarDescriptors::VarInfo var_info; | 371 RawLocalVarDescriptors::VarInfo var_info; |
| 359 var_descriptors_.GetInfo(cur_idx, &var_info); | 372 var_descriptors_.GetInfo(cur_idx, &var_info); |
| 360 if ((var_info.kind != RawLocalVarDescriptors::kStackVar) && | 373 if ((var_info.kind != RawLocalVarDescriptors::kStackVar) && |
| 361 (var_info.kind != RawLocalVarDescriptors::kContextVar)) { | 374 (var_info.kind != RawLocalVarDescriptors::kContextVar)) { |
| 362 continue; | 375 continue; |
| (...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1640 } | 1653 } |
| 1641 | 1654 |
| 1642 | 1655 |
| 1643 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { | 1656 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { |
| 1644 ASSERT(bpt->next() == NULL); | 1657 ASSERT(bpt->next() == NULL); |
| 1645 bpt->set_next(code_breakpoints_); | 1658 bpt->set_next(code_breakpoints_); |
| 1646 code_breakpoints_ = bpt; | 1659 code_breakpoints_ = bpt; |
| 1647 } | 1660 } |
| 1648 | 1661 |
| 1649 } // namespace dart | 1662 } // namespace dart |
| OLD | NEW |