Chromium Code Reviews| 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 "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 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 } | 534 } |
| 535 | 535 |
| 536 | 536 |
| 537 CodeBreakpoint* Debugger::MakeCodeBreakpoint(const Function& func, | 537 CodeBreakpoint* Debugger::MakeCodeBreakpoint(const Function& func, |
| 538 intptr_t token_index) { | 538 intptr_t token_index) { |
| 539 ASSERT(func.HasCode()); | 539 ASSERT(func.HasCode()); |
| 540 ASSERT(!func.HasOptimizedCode()); | 540 ASSERT(!func.HasOptimizedCode()); |
| 541 Code& code = Code::Handle(func.unoptimized_code()); | 541 Code& code = Code::Handle(func.unoptimized_code()); |
| 542 ASSERT(!code.IsNull()); | 542 ASSERT(!code.IsNull()); |
| 543 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); | 543 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); |
| 544 intptr_t best_fit_index = -1; | |
| 545 intptr_t best_fit = INTPTR_MAX; | |
| 544 for (int i = 0; i < desc.Length(); i++) { | 546 for (int i = 0; i < desc.Length(); i++) { |
| 545 if (desc.TokenIndex(i) < token_index) { | 547 intptr_t desc_token_index = desc.TokenIndex(i); |
| 548 if (desc_token_index < token_index) { | |
|
srdjan
2012/03/14 22:47:43
You are searching for closest token after 'token_i
hausner
2012/03/14 23:10:25
The token index just before the requested index lo
| |
| 546 continue; | 549 continue; |
| 547 } | 550 } |
| 548 CodeBreakpoint* bpt = GetCodeBreakpoint(desc.PC(i)); | 551 PcDescriptors::Kind kind = desc.DescriptorKind(i); |
| 552 if ((kind == PcDescriptors::kIcCall) || | |
| 553 (kind == PcDescriptors::kFuncCall) || | |
| 554 (kind == PcDescriptors::kReturn)) { | |
| 555 if ((desc_token_index - token_index) < best_fit) { | |
| 556 best_fit = desc_token_index - token_index; | |
| 557 ASSERT(best_fit >= 0); | |
| 558 best_fit_index = i; | |
| 559 } | |
| 560 } | |
| 561 } | |
| 562 if (best_fit_index >= 0) { | |
| 563 CodeBreakpoint* bpt = GetCodeBreakpoint(desc.PC(best_fit_index)); | |
| 549 // We should only ever have one code breakpoint at the same address. | 564 // We should only ever have one code breakpoint at the same address. |
| 550 // If we find an existing breakpoint, it must be an internal one which | 565 // If we find an existing breakpoint, it must be an internal one which |
| 551 // is used for stepping. | 566 // is used for stepping. |
| 552 if (bpt != NULL) { | 567 if (bpt != NULL) { |
| 553 ASSERT(bpt->src_bpt() == NULL); | 568 ASSERT(bpt->src_bpt() == NULL); |
| 554 return bpt; | 569 return bpt; |
| 555 } | 570 } |
| 556 | 571 |
| 557 PcDescriptors::Kind kind = desc.DescriptorKind(i); | 572 bpt = new CodeBreakpoint(func, best_fit_index); |
| 558 if ((kind == PcDescriptors::kIcCall) || | 573 if (verbose) { |
| 559 (kind == PcDescriptors::kFuncCall) || | 574 OS::Print("Setting breakpoint in function '%s' (%s:%d) (PC %p)\n", |
| 560 (kind == PcDescriptors::kReturn)) { | 575 String::Handle(func.name()).ToCString(), |
| 561 bpt = new CodeBreakpoint(func, i); | 576 String::Handle(bpt->SourceUrl()).ToCString(), |
| 562 if (verbose) { | 577 bpt->LineNumber(), |
| 563 OS::Print("Setting breakpoint in function '%s' (%s:%d) (PC %p)\n", | 578 bpt->pc()); |
| 564 String::Handle(func.name()).ToCString(), | |
| 565 String::Handle(bpt->SourceUrl()).ToCString(), | |
| 566 bpt->LineNumber(), | |
| 567 bpt->pc()); | |
| 568 } | |
| 569 RegisterCodeBreakpoint(bpt); | |
| 570 return bpt; | |
| 571 } | 579 } |
| 580 RegisterCodeBreakpoint(bpt); | |
| 581 return bpt; | |
| 572 } | 582 } |
| 573 return NULL; | 583 return NULL; |
| 574 } | 584 } |
| 575 | 585 |
| 576 | 586 |
| 577 SourceBreakpoint* Debugger::SetBreakpoint(const Function& target_function, | 587 SourceBreakpoint* Debugger::SetBreakpoint(const Function& target_function, |
| 578 intptr_t token_index) { | 588 intptr_t token_index) { |
| 579 if ((token_index < target_function.token_index()) || | 589 if ((token_index < target_function.token_index()) || |
| 580 (target_function.end_token_index() <= token_index)) { | 590 (target_function.end_token_index() <= token_index)) { |
| 581 // The given token position is not within the target function. | 591 // The given token position is not within the target function. |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1040 } | 1050 } |
| 1041 | 1051 |
| 1042 | 1052 |
| 1043 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { | 1053 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { |
| 1044 ASSERT(bpt->next() == NULL); | 1054 ASSERT(bpt->next() == NULL); |
| 1045 bpt->set_next(code_breakpoints_); | 1055 bpt->set_next(code_breakpoints_); |
| 1046 code_breakpoints_ = bpt; | 1056 code_breakpoints_ = bpt; |
| 1047 } | 1057 } |
| 1048 | 1058 |
| 1049 } // namespace dart | 1059 } // namespace dart |
| OLD | NEW |