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

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

Issue 9475031: Cleaned up usage of Function::code, since it may be misunderstood that it points to the only Code o… (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) 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_patcher.h" 8 #include "vm/code_patcher.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 13 matching lines...) Expand all
24 static const bool verbose = false; 24 static const bool verbose = false;
25 25
26 26
27 Breakpoint::Breakpoint(const Function& func, intptr_t pc_desc_index) 27 Breakpoint::Breakpoint(const Function& func, intptr_t pc_desc_index)
28 : function_(func.raw()), 28 : function_(func.raw()),
29 pc_desc_index_(pc_desc_index), 29 pc_desc_index_(pc_desc_index),
30 pc_(0), 30 pc_(0),
31 saved_bytes_(0), 31 saved_bytes_(0),
32 line_number_(-1), 32 line_number_(-1),
33 next_(NULL) { 33 next_(NULL) {
34 Code& code = Code::Handle(func.code()); 34 ASSERT(!func.HasOptimizedCode());
35 Code& code = Code::Handle(func.unoptimized_code());
35 ASSERT(!code.IsNull()); // Function must be compiled. 36 ASSERT(!code.IsNull()); // Function must be compiled.
36 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); 37 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors());
37 ASSERT(pc_desc_index < desc.Length()); 38 ASSERT(pc_desc_index < desc.Length());
38 this->token_index_ = desc.TokenIndex(pc_desc_index); 39 this->token_index_ = desc.TokenIndex(pc_desc_index);
39 ASSERT(this->token_index_ > 0); 40 ASSERT(this->token_index_ > 0);
40 this->pc_ = desc.PC(pc_desc_index); 41 this->pc_ = desc.PC(pc_desc_index);
41 ASSERT(this->pc_ != 0); 42 ASSERT(this->pc_ != 0);
42 } 43 }
43 44
44 45
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 var_descriptors_(NULL), 81 var_descriptors_(NULL),
81 desc_indices_(8) { 82 desc_indices_(8) {
82 } 83 }
83 84
84 85
85 const Function& ActivationFrame::DartFunction() { 86 const Function& ActivationFrame::DartFunction() {
86 if (function_.IsNull()) { 87 if (function_.IsNull()) {
87 ASSERT(Isolate::Current() != NULL); 88 ASSERT(Isolate::Current() != NULL);
88 CodeIndexTable* code_index_table = Isolate::Current()->code_index_table(); 89 CodeIndexTable* code_index_table = Isolate::Current()->code_index_table();
89 ASSERT(code_index_table != NULL); 90 ASSERT(code_index_table != NULL);
90 function_ = code_index_table->LookupFunction(pc_); 91 const Code& code = Code::Handle(code_index_table->LookupCode(pc_));
92 function_ = code.function();
91 } 93 }
92 return function_; 94 return function_;
93 } 95 }
94 96
95 97
96 const char* Debugger::QualifiedFunctionName(const Function& func) { 98 const char* Debugger::QualifiedFunctionName(const Function& func) {
97 const String& func_name = String::Handle(func.name()); 99 const String& func_name = String::Handle(func.name());
98 Class& func_class = Class::Handle(func.owner()); 100 Class& func_class = Class::Handle(func.owner());
99 String& class_name = String::Handle(func_class.Name()); 101 String& class_name = String::Handle(func_class.Name());
100 102
(...skipping 28 matching lines...) Expand all
129 RawScript* ActivationFrame::SourceScript() { 131 RawScript* ActivationFrame::SourceScript() {
130 const Function& func = DartFunction(); 132 const Function& func = DartFunction();
131 const Class& cls = Class::Handle(func.owner()); 133 const Class& cls = Class::Handle(func.owner());
132 return cls.script(); 134 return cls.script();
133 } 135 }
134 136
135 137
136 intptr_t ActivationFrame::TokenIndex() { 138 intptr_t ActivationFrame::TokenIndex() {
137 if (token_index_ < 0) { 139 if (token_index_ < 0) {
138 const Function& func = DartFunction(); 140 const Function& func = DartFunction();
139 Code& code = Code::Handle(func.code()); 141 ASSERT(!func.HasOptimizedCode());
142 Code& code = Code::Handle(func.unoptimized_code());
140 ASSERT(!code.IsNull()); 143 ASSERT(!code.IsNull());
141 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); 144 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors());
142 for (int i = 0; i < desc.Length(); i++) { 145 for (int i = 0; i < desc.Length(); i++) {
143 if (desc.PC(i) == pc_) { 146 if (desc.PC(i) == pc_) {
144 token_index_ = desc.TokenIndex(i); 147 token_index_ = desc.TokenIndex(i);
145 break; 148 break;
146 } 149 }
147 } 150 }
148 ASSERT(token_index_ >= 0); 151 ASSERT(token_index_ >= 0);
149 } 152 }
150 return token_index_; 153 return token_index_;
151 } 154 }
152 155
153 156
154 intptr_t ActivationFrame::LineNumber() { 157 intptr_t ActivationFrame::LineNumber() {
155 // Compute line number lazily since it causes scanning of the script. 158 // Compute line number lazily since it causes scanning of the script.
156 if (line_number_ < 0) { 159 if (line_number_ < 0) {
157 const Script& script = Script::Handle(SourceScript()); 160 const Script& script = Script::Handle(SourceScript());
158 intptr_t ignore_column; 161 intptr_t ignore_column;
159 script.GetTokenLocation(TokenIndex(), &line_number_, &ignore_column); 162 script.GetTokenLocation(TokenIndex(), &line_number_, &ignore_column);
160 } 163 }
161 return line_number_; 164 return line_number_;
162 } 165 }
163 166
164 167
165 void ActivationFrame::GetDescIndices() { 168 void ActivationFrame::GetDescIndices() {
166 if (var_descriptors_ == NULL) { 169 if (var_descriptors_ == NULL) {
167 const Code& code = Code::Handle(DartFunction().code()); 170 ASSERT(!DartFunction().HasOptimizedCode());
171 const Code& code = Code::Handle(DartFunction().unoptimized_code());
168 var_descriptors_ = 172 var_descriptors_ =
169 &LocalVarDescriptors::ZoneHandle(code.var_descriptors()); 173 &LocalVarDescriptors::ZoneHandle(code.var_descriptors());
170 GrowableArray<String*> var_names(8); 174 GrowableArray<String*> var_names(8);
171 intptr_t activation_token_pos = TokenIndex(); 175 intptr_t activation_token_pos = TokenIndex();
172 intptr_t var_desc_len = var_descriptors_->Length(); 176 intptr_t var_desc_len = var_descriptors_->Length();
173 for (int cur_idx = 0; cur_idx < var_desc_len; cur_idx++) { 177 for (int cur_idx = 0; cur_idx < var_desc_len; cur_idx++) {
174 ASSERT(var_names.length() == desc_indices_.length()); 178 ASSERT(var_names.length() == desc_indices_.length());
175 intptr_t scope_id, begin_pos, end_pos; 179 intptr_t scope_id, begin_pos, end_pos;
176 var_descriptors_->GetScopeInfo(cur_idx, &scope_id, &begin_pos, &end_pos); 180 var_descriptors_->GetScopeInfo(cur_idx, &scope_id, &begin_pos, &end_pos);
177 if ((begin_pos <= activation_token_pos) && 181 if ((begin_pos <= activation_token_pos) &&
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 (target_function.end_token_index() <= token_index)) { 358 (target_function.end_token_index() <= token_index)) {
355 // The given token position is not within the target function. 359 // The given token position is not within the target function.
356 return NULL; 360 return NULL;
357 } 361 }
358 if (!target_function.HasCode()) { 362 if (!target_function.HasCode()) {
359 *error = Compiler::CompileFunction(target_function); 363 *error = Compiler::CompileFunction(target_function);
360 if (!error->IsNull()) { 364 if (!error->IsNull()) {
361 return NULL; 365 return NULL;
362 } 366 }
363 } 367 }
364 Code& code = Code::Handle(target_function.code()); 368 ASSERT(!target_function.HasOptimizedCode());
369 Code& code = Code::Handle(target_function.unoptimized_code());
365 ASSERT(!code.IsNull()); 370 ASSERT(!code.IsNull());
366 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); 371 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors());
367 for (int i = 0; i < desc.Length(); i++) { 372 for (int i = 0; i < desc.Length(); i++) {
368 if (desc.TokenIndex(i) < token_index) { 373 if (desc.TokenIndex(i) < token_index) {
369 continue; 374 continue;
370 } 375 }
371 PcDescriptors::Kind kind = desc.DescriptorKind(i); 376 PcDescriptors::Kind kind = desc.DescriptorKind(i);
372 Breakpoint* bpt = NULL; 377 Breakpoint* bpt = NULL;
373 if (kind == PcDescriptors::kIcCall) { 378 if (kind == PcDescriptors::kIcCall) {
374 bpt = GetBreakpoint(desc.PC(i)); 379 bpt = GetBreakpoint(desc.PC(i));
(...skipping 13 matching lines...) Expand all
388 if ((desc.TokenIndex(i) > 0) && CodePatcher::IsDartCall(desc.PC(i))) { 393 if ((desc.TokenIndex(i) > 0) && CodePatcher::IsDartCall(desc.PC(i))) {
389 bpt = GetBreakpoint(desc.PC(i)); 394 bpt = GetBreakpoint(desc.PC(i));
390 if (bpt != NULL) { 395 if (bpt != NULL) {
391 // There is an existing breakpoint at this token position. 396 // There is an existing breakpoint at this token position.
392 break; 397 break;
393 } 398 }
394 bpt = new Breakpoint(target_function, i); 399 bpt = new Breakpoint(target_function, i);
395 Function& func = Function::Handle(); 400 Function& func = Function::Handle();
396 CodePatcher::GetStaticCallAt(desc.PC(i), &func, &bpt->saved_bytes_); 401 CodePatcher::GetStaticCallAt(desc.PC(i), &func, &bpt->saved_bytes_);
397 CodePatcher::PatchStaticCallAt( 402 CodePatcher::PatchStaticCallAt(
398 desc.PC(i), StubCode::BreakpointStaticEntryPoint()); 403 desc.PC(i), StubCode::BreakpointStaticEntryPoint());
399 RegisterBreakpoint(bpt); 404 RegisterBreakpoint(bpt);
400 } 405 }
401 } 406 }
402 if (bpt != NULL) { 407 if (bpt != NULL) {
403 if (verbose) { 408 if (verbose) {
404 OS::Print("Setting breakpoint at '%s' line %d (PC %p)\n", 409 OS::Print("Setting breakpoint at '%s' line %d (PC %p)\n",
405 String::Handle(bpt->SourceUrl()).ToCString(), 410 String::Handle(bpt->SourceUrl()).ToCString(),
406 bpt->LineNumber(), 411 bpt->LineNumber(),
407 bpt->pc()); 412 bpt->pc());
408 } 413 }
409 return bpt; 414 return bpt;
410 } 415 }
411 } 416 }
412 return NULL; 417 return NULL;
413 } 418 }
414 419
415 420
416 void Debugger::UnsetBreakpoint(Breakpoint* bpt) { 421 void Debugger::UnsetBreakpoint(Breakpoint* bpt) {
417 const Function& func = Function::Handle(bpt->function()); 422 const Function& func = Function::Handle(bpt->function());
418 const Code& code = Code::Handle(func.code()); 423 ASSERT(!func.HasOptimizedCode());
424 const Code& code = Code::Handle(func.unoptimized_code());
419 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); 425 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors());
420 intptr_t desc_index = bpt->pc_desc_index(); 426 intptr_t desc_index = bpt->pc_desc_index();
421 ASSERT(desc_index < desc.Length()); 427 ASSERT(desc_index < desc.Length());
422 ASSERT(bpt->pc() == desc.PC(desc_index)); 428 ASSERT(bpt->pc() == desc.PC(desc_index));
423 PcDescriptors::Kind kind = desc.DescriptorKind(desc_index); 429 PcDescriptors::Kind kind = desc.DescriptorKind(desc_index);
424 if (kind == PcDescriptors::kIcCall) { 430 if (kind == PcDescriptors::kIcCall) {
425 CodePatcher::PatchInstanceCallAt(desc.PC(desc_index), bpt->saved_bytes_); 431 CodePatcher::PatchInstanceCallAt(desc.PC(desc_index), bpt->saved_bytes_);
426 } else { 432 } else {
427 CodePatcher::PatchStaticCallAt(desc.PC(desc_index), bpt->saved_bytes_); 433 CodePatcher::PatchStaticCallAt(desc.PC(desc_index), bpt->saved_bytes_);
428 } 434 }
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 696
691 697
692 void Debugger::RegisterBreakpoint(Breakpoint* bpt) { 698 void Debugger::RegisterBreakpoint(Breakpoint* bpt) {
693 ASSERT(bpt->next() == NULL); 699 ASSERT(bpt->next() == NULL);
694 bpt->set_next(this->breakpoints_); 700 bpt->set_next(this->breakpoints_);
695 this->breakpoints_ = bpt; 701 this->breakpoints_ = bpt;
696 } 702 }
697 703
698 704
699 } // namespace dart 705 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698