Chromium Code Reviews| Index: runtime/vm/debugger.cc |
| =================================================================== |
| --- runtime/vm/debugger.cc (revision 5473) |
| +++ runtime/vm/debugger.cc (working copy) |
| @@ -541,11 +541,26 @@ |
| Code& code = Code::Handle(func.unoptimized_code()); |
| ASSERT(!code.IsNull()); |
| PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); |
| + intptr_t best_fit_index = -1; |
| + intptr_t best_fit = INTPTR_MAX; |
| for (int i = 0; i < desc.Length(); i++) { |
| - if (desc.TokenIndex(i) < token_index) { |
| + intptr_t desc_token_index = desc.TokenIndex(i); |
| + 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
|
| continue; |
| } |
| - CodeBreakpoint* bpt = GetCodeBreakpoint(desc.PC(i)); |
| + PcDescriptors::Kind kind = desc.DescriptorKind(i); |
| + if ((kind == PcDescriptors::kIcCall) || |
| + (kind == PcDescriptors::kFuncCall) || |
| + (kind == PcDescriptors::kReturn)) { |
| + if ((desc_token_index - token_index) < best_fit) { |
| + best_fit = desc_token_index - token_index; |
| + ASSERT(best_fit >= 0); |
| + best_fit_index = i; |
| + } |
| + } |
| + } |
| + if (best_fit_index >= 0) { |
| + CodeBreakpoint* bpt = GetCodeBreakpoint(desc.PC(best_fit_index)); |
| // We should only ever have one code breakpoint at the same address. |
| // If we find an existing breakpoint, it must be an internal one which |
| // is used for stepping. |
| @@ -554,21 +569,16 @@ |
| return bpt; |
| } |
| - PcDescriptors::Kind kind = desc.DescriptorKind(i); |
| - if ((kind == PcDescriptors::kIcCall) || |
| - (kind == PcDescriptors::kFuncCall) || |
| - (kind == PcDescriptors::kReturn)) { |
| - bpt = new CodeBreakpoint(func, i); |
| - if (verbose) { |
| - OS::Print("Setting breakpoint in function '%s' (%s:%d) (PC %p)\n", |
| - String::Handle(func.name()).ToCString(), |
| - String::Handle(bpt->SourceUrl()).ToCString(), |
| - bpt->LineNumber(), |
| - bpt->pc()); |
| - } |
| - RegisterCodeBreakpoint(bpt); |
| - return bpt; |
| + bpt = new CodeBreakpoint(func, best_fit_index); |
| + if (verbose) { |
| + OS::Print("Setting breakpoint in function '%s' (%s:%d) (PC %p)\n", |
| + String::Handle(func.name()).ToCString(), |
| + String::Handle(bpt->SourceUrl()).ToCString(), |
| + bpt->LineNumber(), |
| + bpt->pc()); |
| } |
| + RegisterCodeBreakpoint(bpt); |
| + return bpt; |
| } |
| return NULL; |
| } |