| 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_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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // Compute line number lazily since it causes scanning of the script. | 154 // Compute line number lazily since it causes scanning of the script. |
| 155 if (line_number_ < 0) { | 155 if (line_number_ < 0) { |
| 156 const Script& script = Script::Handle(SourceScript()); | 156 const Script& script = Script::Handle(SourceScript()); |
| 157 intptr_t ignore_column; | 157 intptr_t ignore_column; |
| 158 script.GetTokenLocation(TokenIndex(), &line_number_, &ignore_column); | 158 script.GetTokenLocation(TokenIndex(), &line_number_, &ignore_column); |
| 159 } | 159 } |
| 160 return line_number_; | 160 return line_number_; |
| 161 } | 161 } |
| 162 | 162 |
| 163 | 163 |
| 164 void ActivationFrame::GetLocalVariables() { | 164 void ActivationFrame::GetDescIndices() { |
| 165 if (var_descriptors_ == NULL) { | 165 if (var_descriptors_ == NULL) { |
| 166 const Code& code = Code::Handle(DartFunction().code()); | 166 const Code& code = Code::Handle(DartFunction().code()); |
| 167 var_descriptors_ = | 167 var_descriptors_ = |
| 168 &LocalVarDescriptors::ZoneHandle(code.var_descriptors()); | 168 &LocalVarDescriptors::ZoneHandle(code.var_descriptors()); |
| 169 GrowableArray<String*> var_names(8); |
| 169 intptr_t activation_token_pos = TokenIndex(); | 170 intptr_t activation_token_pos = TokenIndex(); |
| 170 intptr_t desc_len = var_descriptors_->Length(); | 171 intptr_t var_desc_len = var_descriptors_->Length(); |
| 171 for (int i = 0; i < desc_len; i++) { | 172 for (int cur_idx = 0; cur_idx < var_desc_len; cur_idx++) { |
| 173 ASSERT(var_names.length() == desc_indices_.length()); |
| 172 intptr_t scope_id, begin_pos, end_pos; | 174 intptr_t scope_id, begin_pos, end_pos; |
| 173 var_descriptors_->GetScopeInfo(i, &scope_id, &begin_pos, &end_pos); | 175 var_descriptors_->GetScopeInfo(cur_idx, &scope_id, &begin_pos, &end_pos); |
| 174 if ((begin_pos <= activation_token_pos) && | 176 if ((begin_pos <= activation_token_pos) && |
| 175 (activation_token_pos <= end_pos)) { | 177 (activation_token_pos <= end_pos)) { |
| 176 desc_indices_.Add(i); | 178 // The current variable is textually in scope. Now check whether |
| 179 // there is another local variable with the same name that shadows |
| 180 // or is shadowed by this variable. |
| 181 String& var_name = String::Handle(var_descriptors_->GetName(cur_idx)); |
| 182 intptr_t indices_len = desc_indices_.length(); |
| 183 bool name_match_found = false; |
| 184 for (int i = 0; i < indices_len; i++) { |
| 185 if (var_name.Equals(*var_names[i])) { |
| 186 // Found two local variables with the same name. Now determine |
| 187 // which one is shadowed. |
| 188 name_match_found = true; |
| 189 intptr_t i_begin_pos, ignore; |
| 190 var_descriptors_->GetScopeInfo( |
| 191 desc_indices_[i], &ignore, &i_begin_pos, &ignore); |
| 192 if (i_begin_pos < begin_pos) { |
| 193 // The variable we found earlier is in an outer scope |
| 194 // and is shadowed by the current variable. Replace the |
| 195 // descriptor index of the previously found variable |
| 196 // with the descriptor index of the current variable. |
| 197 desc_indices_[i] = cur_idx; |
| 198 } else { |
| 199 // The variable we found earlier is in an inner scope |
| 200 // and shadows the current variable. Skip the current |
| 201 // variable. (Nothing to do.) |
| 202 } |
| 203 break; // Stop looking for name matches. |
| 204 } |
| 205 } |
| 206 if (!name_match_found) { |
| 207 // No duplicate name found. Add the current descriptor index to the |
| 208 // list of visible variables. |
| 209 desc_indices_.Add(cur_idx); |
| 210 var_names.Add(&var_name); |
| 211 } |
| 177 } | 212 } |
| 178 } | 213 } |
| 179 } | 214 } |
| 180 } | 215 } |
| 181 | 216 |
| 182 | 217 |
| 183 intptr_t ActivationFrame::NumLocalVariables() { | 218 intptr_t ActivationFrame::NumLocalVariables() { |
| 184 GetLocalVariables(); | 219 GetDescIndices(); |
| 185 return desc_indices_.length(); | 220 return desc_indices_.length(); |
| 186 } | 221 } |
| 187 | 222 |
| 188 | 223 |
| 189 void ActivationFrame::VariableAt(intptr_t i, | 224 void ActivationFrame::VariableAt(intptr_t i, |
| 190 String* name, | 225 String* name, |
| 191 intptr_t* token_pos, | 226 intptr_t* token_pos, |
| 192 intptr_t* end_pos, | 227 intptr_t* end_pos, |
| 193 Instance* value) { | 228 Instance* value) { |
| 194 GetLocalVariables(); | 229 GetDescIndices(); |
| 195 ASSERT(i < desc_indices_.length()); | 230 ASSERT(i < desc_indices_.length()); |
| 196 ASSERT(name != NULL); | 231 ASSERT(name != NULL); |
| 197 intptr_t desc_index = desc_indices_[i]; | 232 intptr_t desc_index = desc_indices_[i]; |
| 198 *name ^= var_descriptors_->GetName(desc_index); | 233 *name ^= var_descriptors_->GetName(desc_index); |
| 199 intptr_t scope_id; | 234 intptr_t scope_id; |
| 200 var_descriptors_->GetScopeInfo(desc_index, &scope_id, token_pos, end_pos); | 235 var_descriptors_->GetScopeInfo(desc_index, &scope_id, token_pos, end_pos); |
| 201 ASSERT(value != NULL); | 236 ASSERT(value != NULL); |
| 202 *value = GetLocalVarValue(var_descriptors_->GetSlotIndex(desc_index)); | 237 *value = GetLocalVarValue(var_descriptors_->GetSlotIndex(desc_index)); |
| 203 } | 238 } |
| 204 | 239 |
| 205 | 240 |
| 241 RawArray* ActivationFrame::GetLocalVariables() { |
| 242 GetDescIndices(); |
| 243 intptr_t num_variables = desc_indices_.length(); |
| 244 String& var_name = String::Handle(); |
| 245 Instance& value = Instance::Handle(); |
| 246 const Array& list = Array::Handle(Array::New(2 * num_variables)); |
| 247 for (int i = 0; i < num_variables; i++) { |
| 248 var_name = var_descriptors_->GetName(i); |
| 249 list.SetAt(2 * i, var_name); |
| 250 value = GetLocalVarValue(var_descriptors_->GetSlotIndex(i)); |
| 251 list.SetAt((2 * i) + 1, value); |
| 252 } |
| 253 return list.raw(); |
| 254 } |
| 255 |
| 256 |
| 206 const char* ActivationFrame::ToCString() { | 257 const char* ActivationFrame::ToCString() { |
| 207 const char* kFormat = "Function: '%s' url: '%s' line: %d"; | 258 const char* kFormat = "Function: '%s' url: '%s' line: %d"; |
| 208 | 259 |
| 209 const Function& func = DartFunction(); | 260 const Function& func = DartFunction(); |
| 210 const String& url = String::Handle(SourceUrl()); | 261 const String& url = String::Handle(SourceUrl()); |
| 211 intptr_t line = LineNumber(); | 262 intptr_t line = LineNumber(); |
| 212 const char* func_name = Debugger::QualifiedFunctionName(func); | 263 const char* func_name = Debugger::QualifiedFunctionName(func); |
| 213 | 264 |
| 214 intptr_t len = | 265 intptr_t len = |
| 215 OS::SNPrint(NULL, 0, kFormat, func_name, url.ToCString(), line); | 266 OS::SNPrint(NULL, 0, kFormat, func_name, url.ToCString(), line); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 | 683 |
| 633 | 684 |
| 634 void Debugger::RegisterBreakpoint(Breakpoint* bpt) { | 685 void Debugger::RegisterBreakpoint(Breakpoint* bpt) { |
| 635 ASSERT(bpt->next() == NULL); | 686 ASSERT(bpt->next() == NULL); |
| 636 bpt->set_next(this->breakpoints_); | 687 bpt->set_next(this->breakpoints_); |
| 637 this->breakpoints_ = bpt; | 688 this->breakpoints_ = bpt; |
| 638 } | 689 } |
| 639 | 690 |
| 640 | 691 |
| 641 } // namespace dart | 692 } // namespace dart |
| OLD | NEW |