Chromium Code Reviews| 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/flags.h" | 10 #include "vm/flags.h" |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 if (!cls.IsNull()) { | 267 if (!cls.IsNull()) { |
| 268 function = cls.LookupStaticFunction(function_name); | 268 function = cls.LookupStaticFunction(function_name); |
| 269 if (function.IsNull()) { | 269 if (function.IsNull()) { |
| 270 function = cls.LookupDynamicFunction(function_name); | 270 function = cls.LookupDynamicFunction(function_name); |
| 271 } | 271 } |
| 272 } | 272 } |
| 273 return function.raw(); | 273 return function.raw(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 | 276 |
| 277 Breakpoint* Debugger::SetBreakpointAtEntry(const Function& target_function) { | 277 Breakpoint* Debugger::SetBreakpoint(const Function& target_function, |
| 278 ASSERT(!target_function.IsNull()); | 278 intptr_t token_index) { |
| 279 if ((token_index < target_function.token_index()) || | |
| 280 (target_function.end_token_index() <= token_index)) { | |
| 281 // The given token position is not within the target function. | |
| 282 return NULL; | |
| 283 } | |
|
siva
2012/01/18 01:32:03
Shouldn't we check in the breakpoint list that you
hausner
2012/01/18 23:26:38
Done
| |
| 279 if (!target_function.HasCode()) { | 284 if (!target_function.HasCode()) { |
| 280 Compiler::CompileFunction(target_function); | 285 Compiler::CompileFunction(target_function); |
| 281 } | 286 } |
| 282 Code& code = Code::Handle(target_function.code()); | 287 Code& code = Code::Handle(target_function.code()); |
| 283 ASSERT(!code.IsNull()); | 288 ASSERT(!code.IsNull()); |
| 284 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); | 289 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); |
| 285 for (int i = 0; i < desc.Length(); i++) { | 290 for (int i = 0; i < desc.Length(); i++) { |
| 291 if (desc.TokenIndex(i) < token_index) { | |
| 292 continue; | |
| 293 } | |
|
siva
2012/01/18 01:32:03
If 'i' happens to be the last descriptor in this f
hausner
2012/01/18 23:26:38
We return NULL if there is no possible PC location
| |
| 286 PcDescriptors::Kind kind = desc.DescriptorKind(i); | 294 PcDescriptors::Kind kind = desc.DescriptorKind(i); |
| 287 Breakpoint* bpt = NULL; | 295 Breakpoint* bpt = NULL; |
| 288 if (kind == PcDescriptors::kIcCall) { | 296 if (kind == PcDescriptors::kIcCall) { |
| 289 CodePatcher::PatchInstanceCallAt( | 297 CodePatcher::PatchInstanceCallAt( |
| 290 desc.PC(i), StubCode::BreakpointDynamicEntryPoint()); | 298 desc.PC(i), StubCode::BreakpointDynamicEntryPoint()); |
| 291 bpt = new Breakpoint(target_function, i); | 299 bpt = new Breakpoint(target_function, i); |
| 292 } else if (kind == PcDescriptors::kOther) { | 300 } else if (kind == PcDescriptors::kOther) { |
| 293 if ((desc.TokenIndex(i) > 0) && CodePatcher::IsDartCall(desc.PC(i))) { | 301 if ((desc.TokenIndex(i) > 0) && CodePatcher::IsDartCall(desc.PC(i))) { |
| 294 CodePatcher::PatchStaticCallAt( | 302 CodePatcher::PatchStaticCallAt( |
| 295 desc.PC(i), StubCode::BreakpointStaticEntryPoint()); | 303 desc.PC(i), StubCode::BreakpointStaticEntryPoint()); |
| 296 bpt = new Breakpoint(target_function, i); | 304 bpt = new Breakpoint(target_function, i); |
| 297 } | 305 } |
| 298 } | 306 } |
| 299 if (bpt != NULL) { | 307 if (bpt != NULL) { |
| 300 if (verbose) { | 308 if (verbose) { |
| 301 OS::Print("Setting breakpoint at '%s' line %d (PC %p)\n", | 309 OS::Print("Setting breakpoint at '%s' line %d (PC %p)\n", |
| 302 String::Handle(bpt->SourceUrl()).ToCString(), | 310 String::Handle(bpt->SourceUrl()).ToCString(), |
| 303 bpt->LineNumber(), | 311 bpt->LineNumber(), |
| 304 bpt->pc()); | 312 bpt->pc()); |
| 305 } | 313 } |
| 306 AddBreakpoint(bpt); | 314 AddBreakpoint(bpt); |
| 307 return bpt; | 315 return bpt; |
| 308 } | 316 } |
| 309 } | 317 } |
|
siva
2012/01/18 01:32:03
why did you drop "return NULL"; ?
hausner
2012/01/18 23:26:38
Accident. I need automated test cases sooner than
| |
| 310 return NULL; | 318 } |
| 319 | |
| 320 | |
| 321 Breakpoint* Debugger::SetBreakpointAtEntry(const Function& target_function) { | |
| 322 ASSERT(!target_function.IsNull()); | |
| 323 return SetBreakpoint(target_function, target_function.token_index()); | |
| 324 } | |
| 325 | |
| 326 | |
| 327 Breakpoint* Debugger::SetBreakpointAtLine(const String& script_url, | |
| 328 intptr_t line_number) { | |
| 329 Library& lib = Library::Handle(); | |
| 330 Script& script = Script::Handle(); | |
| 331 Isolate* isolate = Isolate::Current(); | |
| 332 ASSERT(isolate != NULL); | |
| 333 lib = isolate->object_store()->registered_libraries(); | |
| 334 while (!lib.IsNull()) { | |
| 335 script = lib.LookupScript(script_url); | |
| 336 if (!script.IsNull()) { | |
| 337 break; | |
| 338 } | |
| 339 lib = lib.next_registered(); | |
| 340 } | |
| 341 if (script.IsNull()) { | |
| 342 return NULL; | |
| 343 } | |
| 344 intptr_t token_index_at_line = script.TokenIndexAtLine(line_number); | |
| 345 if (token_index_at_line < 0) { | |
| 346 // Script does not contain the given line number. | |
| 347 return NULL; | |
| 348 } | |
| 349 const Function& func = | |
| 350 Function::Handle(lib.LookupFunctionInScript(script, token_index_at_line)); | |
| 351 if (func.IsNull()) { | |
| 352 return NULL; | |
| 353 } | |
| 354 return SetBreakpoint(func, token_index_at_line); | |
| 311 } | 355 } |
| 312 | 356 |
| 313 | 357 |
| 314 void Debugger::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 358 void Debugger::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 315 ASSERT(visitor != NULL); | 359 ASSERT(visitor != NULL); |
| 316 Breakpoint* bpt = this->breakpoints_; | 360 Breakpoint* bpt = this->breakpoints_; |
| 317 while (bpt != NULL) { | 361 while (bpt != NULL) { |
| 318 bpt->VisitObjectPointers(visitor); | 362 bpt->VisitObjectPointers(visitor); |
| 319 bpt = bpt->next(); | 363 bpt = bpt->next(); |
| 320 } | 364 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 | 442 |
| 399 | 443 |
| 400 void Debugger::AddBreakpoint(Breakpoint* bpt) { | 444 void Debugger::AddBreakpoint(Breakpoint* bpt) { |
| 401 ASSERT(bpt->next() == NULL); | 445 ASSERT(bpt->next() == NULL); |
| 402 bpt->set_next(this->breakpoints_); | 446 bpt->set_next(this->breakpoints_); |
| 403 this->breakpoints_ = bpt; | 447 this->breakpoints_ = bpt; |
| 404 } | 448 } |
| 405 | 449 |
| 406 | 450 |
| 407 } // namespace dart | 451 } // namespace dart |
| OLD | NEW |