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 "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
| 9 #include "platform/address_sanitizer.h" |
| 10 |
9 #include "vm/code_generator.h" | 11 #include "vm/code_generator.h" |
10 #include "vm/code_patcher.h" | 12 #include "vm/code_patcher.h" |
11 #include "vm/compiler.h" | 13 #include "vm/compiler.h" |
12 #include "vm/dart_entry.h" | 14 #include "vm/dart_entry.h" |
13 #include "vm/deopt_instructions.h" | 15 #include "vm/deopt_instructions.h" |
14 #include "vm/flags.h" | 16 #include "vm/flags.h" |
15 #include "vm/globals.h" | 17 #include "vm/globals.h" |
16 #include "vm/longjump.h" | 18 #include "vm/longjump.h" |
17 #include "vm/json_stream.h" | 19 #include "vm/json_stream.h" |
18 #include "vm/message_handler.h" | 20 #include "vm/message_handler.h" |
(...skipping 16 matching lines...) Expand all Loading... |
35 namespace dart { | 37 namespace dart { |
36 | 38 |
37 DEFINE_FLAG(bool, | 39 DEFINE_FLAG(bool, |
38 show_invisible_frames, | 40 show_invisible_frames, |
39 false, | 41 false, |
40 "Show invisible frames in debugger stack traces"); | 42 "Show invisible frames in debugger stack traces"); |
41 DEFINE_FLAG(bool, | 43 DEFINE_FLAG(bool, |
42 trace_debugger_stacktrace, | 44 trace_debugger_stacktrace, |
43 false, | 45 false, |
44 "Trace debugger stacktrace collection"); | 46 "Trace debugger stacktrace collection"); |
| 47 DEFINE_FLAG(bool, trace_rewind, false, "Trace frame rewind"); |
45 DEFINE_FLAG(bool, verbose_debug, false, "Verbose debugger messages"); | 48 DEFINE_FLAG(bool, verbose_debug, false, "Verbose debugger messages"); |
46 DEFINE_FLAG(bool, | 49 DEFINE_FLAG(bool, |
47 steal_breakpoints, | 50 steal_breakpoints, |
48 false, | 51 false, |
49 "Intercept breakpoints and other pause events before they " | 52 "Intercept breakpoints and other pause events before they " |
50 "are sent to the embedder and use a generic VM breakpoint " | 53 "are sent to the embedder and use a generic VM breakpoint " |
51 "handler instead. This handler dispatches breakpoints to " | 54 "handler instead. This handler dispatches breakpoints to " |
52 "the VM service."); | 55 "the VM service."); |
53 | 56 |
54 DECLARE_FLAG(bool, warn_on_pause_with_no_debugger); | 57 DECLARE_FLAG(bool, warn_on_pause_with_no_debugger); |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 | 846 |
844 RawObject* ActivationFrame::GetStackVar(intptr_t slot_index) { | 847 RawObject* ActivationFrame::GetStackVar(intptr_t slot_index) { |
845 if (deopt_frame_.IsNull()) { | 848 if (deopt_frame_.IsNull()) { |
846 return GetVariableValue(LocalVarAddress(fp(), slot_index)); | 849 return GetVariableValue(LocalVarAddress(fp(), slot_index)); |
847 } else { | 850 } else { |
848 return deopt_frame_.At(LocalVarIndex(deopt_frame_offset_, slot_index)); | 851 return deopt_frame_.At(LocalVarIndex(deopt_frame_offset_, slot_index)); |
849 } | 852 } |
850 } | 853 } |
851 | 854 |
852 | 855 |
| 856 bool ActivationFrame::IsRewindable() const { |
| 857 if (deopt_frame_.IsNull()) { |
| 858 return true; |
| 859 } |
| 860 // TODO(turnidge): This is conservative. It looks at all values in |
| 861 // the deopt_frame_ even though some of them may correspond to other |
| 862 // inlined frames. |
| 863 Object& obj = Object::Handle(); |
| 864 for (int i = 0; i < deopt_frame_.Length(); i++) { |
| 865 obj = deopt_frame_.At(i); |
| 866 if (obj.raw() == Symbols::OptimizedOut().raw()) { |
| 867 return false; |
| 868 } |
| 869 } |
| 870 return true; |
| 871 } |
| 872 |
| 873 |
853 void ActivationFrame::PrintContextMismatchError(intptr_t ctx_slot, | 874 void ActivationFrame::PrintContextMismatchError(intptr_t ctx_slot, |
854 intptr_t frame_ctx_level, | 875 intptr_t frame_ctx_level, |
855 intptr_t var_ctx_level) { | 876 intptr_t var_ctx_level) { |
856 OS::PrintErr( | 877 OS::PrintErr( |
857 "-------------------------\n" | 878 "-------------------------\n" |
858 "Encountered context mismatch\n" | 879 "Encountered context mismatch\n" |
859 "\tctx_slot: %" Pd | 880 "\tctx_slot: %" Pd |
860 "\n" | 881 "\n" |
861 "\tframe_ctx_level: %" Pd | 882 "\tframe_ctx_level: %" Pd |
862 "\n" | 883 "\n" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 jsvar.AddProperty("declarationTokenPos", declaration_token_pos); | 1122 jsvar.AddProperty("declarationTokenPos", declaration_token_pos); |
1102 // When the variable becomes visible to the scope. | 1123 // When the variable becomes visible to the scope. |
1103 jsvar.AddProperty("scopeStartTokenPos", visible_start_token_pos); | 1124 jsvar.AddProperty("scopeStartTokenPos", visible_start_token_pos); |
1104 // When the variable stops being visible to the scope. | 1125 // When the variable stops being visible to the scope. |
1105 jsvar.AddProperty("scopeEndTokenPos", visible_end_token_pos); | 1126 jsvar.AddProperty("scopeEndTokenPos", visible_end_token_pos); |
1106 } | 1127 } |
1107 } | 1128 } |
1108 } | 1129 } |
1109 } | 1130 } |
1110 | 1131 |
| 1132 static bool IsFunctionVisible(const Function& function) { |
| 1133 return FLAG_show_invisible_frames || function.is_visible(); |
| 1134 } |
| 1135 |
1111 | 1136 |
1112 void DebuggerStackTrace::AddActivation(ActivationFrame* frame) { | 1137 void DebuggerStackTrace::AddActivation(ActivationFrame* frame) { |
1113 if (FLAG_show_invisible_frames || frame->function().is_visible()) { | 1138 if (IsFunctionVisible(frame->function())) { |
1114 trace_.Add(frame); | 1139 trace_.Add(frame); |
1115 } | 1140 } |
1116 } | 1141 } |
1117 | 1142 |
1118 | 1143 |
1119 const uint8_t kSafepointKind = RawPcDescriptors::kIcCall | | 1144 const uint8_t kSafepointKind = RawPcDescriptors::kIcCall | |
1120 RawPcDescriptors::kUnoptStaticCall | | 1145 RawPcDescriptors::kUnoptStaticCall | |
1121 RawPcDescriptors::kRuntimeCall; | 1146 RawPcDescriptors::kRuntimeCall; |
1122 | 1147 |
1123 | 1148 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 | 1255 |
1231 Debugger::Debugger() | 1256 Debugger::Debugger() |
1232 : isolate_(NULL), | 1257 : isolate_(NULL), |
1233 isolate_id_(ILLEGAL_ISOLATE_ID), | 1258 isolate_id_(ILLEGAL_ISOLATE_ID), |
1234 initialized_(false), | 1259 initialized_(false), |
1235 next_id_(1), | 1260 next_id_(1), |
1236 latent_locations_(NULL), | 1261 latent_locations_(NULL), |
1237 breakpoint_locations_(NULL), | 1262 breakpoint_locations_(NULL), |
1238 code_breakpoints_(NULL), | 1263 code_breakpoints_(NULL), |
1239 resume_action_(kContinue), | 1264 resume_action_(kContinue), |
| 1265 resume_frame_index_(-1), |
| 1266 post_deopt_frame_index_(-1), |
1240 ignore_breakpoints_(false), | 1267 ignore_breakpoints_(false), |
1241 pause_event_(NULL), | 1268 pause_event_(NULL), |
1242 obj_cache_(NULL), | 1269 obj_cache_(NULL), |
1243 stack_trace_(NULL), | 1270 stack_trace_(NULL), |
1244 stepping_fp_(0), | 1271 stepping_fp_(0), |
1245 skip_next_step_(false), | 1272 skip_next_step_(false), |
1246 synthetic_async_breakpoint_(NULL), | 1273 synthetic_async_breakpoint_(NULL), |
1247 exc_pause_info_(kNoPauseOnExceptions) {} | 1274 exc_pause_info_(kNoPauseOnExceptions) {} |
1248 | 1275 |
1249 | 1276 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 const String& fname) { | 1320 const String& fname) { |
1294 ASSERT(!library.IsNull()); | 1321 ASSERT(!library.IsNull()); |
1295 const Object& object = Object::Handle(library.ResolveName(fname)); | 1322 const Object& object = Object::Handle(library.ResolveName(fname)); |
1296 if (!object.IsNull() && object.IsFunction()) { | 1323 if (!object.IsNull() && object.IsFunction()) { |
1297 return Function::Cast(object).raw(); | 1324 return Function::Cast(object).raw(); |
1298 } | 1325 } |
1299 return Function::null(); | 1326 return Function::null(); |
1300 } | 1327 } |
1301 | 1328 |
1302 | 1329 |
1303 bool Debugger::SetupStepOverAsyncSuspension() { | 1330 bool Debugger::SetupStepOverAsyncSuspension(const char** error) { |
1304 ActivationFrame* top_frame = TopDartFrame(); | 1331 ActivationFrame* top_frame = TopDartFrame(); |
1305 if (!IsAtAsyncJump(top_frame)) { | 1332 if (!IsAtAsyncJump(top_frame)) { |
1306 // Not at an async operation. | 1333 // Not at an async operation. |
| 1334 if (error) { |
| 1335 *error = "Isolate must be paused at an async suspension point"; |
| 1336 } |
1307 return false; | 1337 return false; |
1308 } | 1338 } |
1309 Object& closure = Object::Handle(top_frame->GetAsyncOperation()); | 1339 Object& closure = Object::Handle(top_frame->GetAsyncOperation()); |
1310 ASSERT(!closure.IsNull()); | 1340 ASSERT(!closure.IsNull()); |
1311 ASSERT(closure.IsInstance()); | 1341 ASSERT(closure.IsInstance()); |
1312 ASSERT(Instance::Cast(closure).IsClosure()); | 1342 ASSERT(Instance::Cast(closure).IsClosure()); |
1313 Breakpoint* bpt = SetBreakpointAtActivation(Instance::Cast(closure), true); | 1343 Breakpoint* bpt = SetBreakpointAtActivation(Instance::Cast(closure), true); |
1314 if (bpt == NULL) { | 1344 if (bpt == NULL) { |
1315 // Unable to set the breakpoint. | 1345 // Unable to set the breakpoint. |
| 1346 if (error) { |
| 1347 *error = "Unable to set breakpoint at async suspension point"; |
| 1348 } |
1316 return false; | 1349 return false; |
1317 } | 1350 } |
1318 return true; | 1351 return true; |
1319 } | 1352 } |
1320 | 1353 |
1321 | 1354 |
1322 void Debugger::SetSingleStep() { | 1355 bool Debugger::SetResumeAction(ResumeAction action, |
1323 resume_action_ = kSingleStep; | 1356 intptr_t frame_index, |
| 1357 const char** error) { |
| 1358 if (error) { |
| 1359 *error = NULL; |
| 1360 } |
| 1361 resume_frame_index_ = -1; |
| 1362 switch (action) { |
| 1363 case kStepInto: |
| 1364 case kStepOver: |
| 1365 case kStepOut: |
| 1366 case kContinue: |
| 1367 resume_action_ = action; |
| 1368 return true; |
| 1369 case kStepRewind: |
| 1370 if (!CanRewindFrame(frame_index, error)) { |
| 1371 return false; |
| 1372 } |
| 1373 resume_action_ = kStepRewind; |
| 1374 resume_frame_index_ = frame_index; |
| 1375 return true; |
| 1376 case kStepOverAsyncSuspension: |
| 1377 return SetupStepOverAsyncSuspension(error); |
| 1378 default: |
| 1379 UNREACHABLE(); |
| 1380 return false; |
| 1381 } |
1324 } | 1382 } |
1325 | 1383 |
1326 | 1384 |
1327 void Debugger::SetStepOver() { | |
1328 resume_action_ = kStepOver; | |
1329 } | |
1330 | |
1331 | |
1332 void Debugger::SetStepOut() { | |
1333 resume_action_ = kStepOut; | |
1334 } | |
1335 | |
1336 | |
1337 RawFunction* Debugger::ResolveFunction(const Library& library, | 1385 RawFunction* Debugger::ResolveFunction(const Library& library, |
1338 const String& class_name, | 1386 const String& class_name, |
1339 const String& function_name) { | 1387 const String& function_name) { |
1340 ASSERT(!library.IsNull()); | 1388 ASSERT(!library.IsNull()); |
1341 ASSERT(!class_name.IsNull()); | 1389 ASSERT(!class_name.IsNull()); |
1342 ASSERT(!function_name.IsNull()); | 1390 ASSERT(!function_name.IsNull()); |
1343 if (class_name.Length() == 0) { | 1391 if (class_name.Length() == 0) { |
1344 return ResolveLibraryFunction(library, function_name); | 1392 return ResolveLibraryFunction(library, function_name); |
1345 } | 1393 } |
1346 const Class& cls = Class::Handle(library.LookupClass(class_name)); | 1394 const Class& cls = Class::Handle(library.LookupClass(class_name)); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1615 return; | 1663 return; |
1616 } | 1664 } |
1617 ServiceEvent event(isolate_, ServiceEvent::kPauseException); | 1665 ServiceEvent event(isolate_, ServiceEvent::kPauseException); |
1618 event.set_exception(&exc); | 1666 event.set_exception(&exc); |
1619 if (stack_trace->Length() > 0) { | 1667 if (stack_trace->Length() > 0) { |
1620 event.set_top_frame(stack_trace->FrameAt(0)); | 1668 event.set_top_frame(stack_trace->FrameAt(0)); |
1621 } | 1669 } |
1622 ASSERT(stack_trace_ == NULL); | 1670 ASSERT(stack_trace_ == NULL); |
1623 stack_trace_ = stack_trace; | 1671 stack_trace_ = stack_trace; |
1624 Pause(&event); | 1672 Pause(&event); |
| 1673 HandleSteppingRequest(stack_trace_); // we may get a rewind request |
1625 stack_trace_ = NULL; | 1674 stack_trace_ = NULL; |
1626 } | 1675 } |
1627 | 1676 |
1628 | 1677 |
1629 static TokenPosition LastTokenOnLine(Zone* zone, | 1678 static TokenPosition LastTokenOnLine(Zone* zone, |
1630 const TokenStream& tokens, | 1679 const TokenStream& tokens, |
1631 TokenPosition pos) { | 1680 TokenPosition pos) { |
1632 TokenStream::Iterator iter(zone, tokens, pos, | 1681 TokenStream::Iterator iter(zone, tokens, pos, |
1633 TokenStream::Iterator::kAllTokens); | 1682 TokenStream::Iterator::kAllTokens); |
1634 ASSERT(iter.IsValid()); | 1683 ASSERT(iter.IsValid()); |
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2540 void Debugger::EnterSingleStepMode() { | 2589 void Debugger::EnterSingleStepMode() { |
2541 stepping_fp_ = 0; | 2590 stepping_fp_ = 0; |
2542 DeoptimizeWorld(); | 2591 DeoptimizeWorld(); |
2543 isolate_->set_single_step(true); | 2592 isolate_->set_single_step(true); |
2544 } | 2593 } |
2545 | 2594 |
2546 | 2595 |
2547 void Debugger::HandleSteppingRequest(DebuggerStackTrace* stack_trace, | 2596 void Debugger::HandleSteppingRequest(DebuggerStackTrace* stack_trace, |
2548 bool skip_next_step) { | 2597 bool skip_next_step) { |
2549 stepping_fp_ = 0; | 2598 stepping_fp_ = 0; |
2550 if (resume_action_ == kSingleStep) { | 2599 if (resume_action_ == kStepInto) { |
2551 // When single stepping, we need to deoptimize because we might be | 2600 // When single stepping, we need to deoptimize because we might be |
2552 // stepping into optimized code. This happens in particular if | 2601 // stepping into optimized code. This happens in particular if |
2553 // the isolate has been interrupted, but can happen in other cases | 2602 // the isolate has been interrupted, but can happen in other cases |
2554 // as well. We need to deoptimize the world in case we are about | 2603 // as well. We need to deoptimize the world in case we are about |
2555 // to call an optimized function. | 2604 // to call an optimized function. |
2556 DeoptimizeWorld(); | 2605 DeoptimizeWorld(); |
2557 isolate_->set_single_step(true); | 2606 isolate_->set_single_step(true); |
2558 skip_next_step_ = skip_next_step; | 2607 skip_next_step_ = skip_next_step; |
2559 if (FLAG_verbose_debug) { | 2608 if (FLAG_verbose_debug) { |
2560 OS::Print("HandleSteppingRequest- kSingleStep\n"); | 2609 OS::Print("HandleSteppingRequest- kStepInto\n"); |
2561 } | 2610 } |
2562 } else if (resume_action_ == kStepOver) { | 2611 } else if (resume_action_ == kStepOver) { |
2563 DeoptimizeWorld(); | 2612 DeoptimizeWorld(); |
2564 isolate_->set_single_step(true); | 2613 isolate_->set_single_step(true); |
2565 skip_next_step_ = skip_next_step; | 2614 skip_next_step_ = skip_next_step; |
2566 ASSERT(stack_trace->Length() > 0); | 2615 ASSERT(stack_trace->Length() > 0); |
2567 stepping_fp_ = stack_trace->FrameAt(0)->fp(); | 2616 stepping_fp_ = stack_trace->FrameAt(0)->fp(); |
2568 if (FLAG_verbose_debug) { | 2617 if (FLAG_verbose_debug) { |
2569 OS::Print("HandleSteppingRequest- kStepOver %" Px "\n", stepping_fp_); | 2618 OS::Print("HandleSteppingRequest- kStepOver %" Px "\n", stepping_fp_); |
2570 } | 2619 } |
2571 } else if (resume_action_ == kStepOut) { | 2620 } else if (resume_action_ == kStepOut) { |
2572 DeoptimizeWorld(); | 2621 DeoptimizeWorld(); |
2573 isolate_->set_single_step(true); | 2622 isolate_->set_single_step(true); |
2574 // Find topmost caller that is debuggable. | 2623 // Find topmost caller that is debuggable. |
2575 for (intptr_t i = 1; i < stack_trace->Length(); i++) { | 2624 for (intptr_t i = 1; i < stack_trace->Length(); i++) { |
2576 ActivationFrame* frame = stack_trace->FrameAt(i); | 2625 ActivationFrame* frame = stack_trace->FrameAt(i); |
2577 if (frame->IsDebuggable()) { | 2626 if (frame->IsDebuggable()) { |
2578 stepping_fp_ = frame->fp(); | 2627 stepping_fp_ = frame->fp(); |
2579 break; | 2628 break; |
2580 } | 2629 } |
2581 } | 2630 } |
2582 if (FLAG_verbose_debug) { | 2631 if (FLAG_verbose_debug) { |
2583 OS::Print("HandleSteppingRequest- kStepOut %" Px "\n", stepping_fp_); | 2632 OS::Print("HandleSteppingRequest- kStepOut %" Px "\n", stepping_fp_); |
2584 } | 2633 } |
2585 } | 2634 } else if (resume_action_ == kStepRewind) { |
2586 } | 2635 if (FLAG_trace_rewind) { |
2587 | 2636 OS::PrintErr("Rewinding to frame %" Pd "\n", resume_frame_index_); |
| 2637 OS::PrintErr( |
| 2638 "-------------------------\n" |
| 2639 "All frames...\n\n"); |
| 2640 StackFrameIterator iterator(false); |
| 2641 StackFrame* frame = iterator.NextFrame(); |
| 2642 intptr_t num = 0; |
| 2643 while ((frame != NULL)) { |
| 2644 OS::PrintErr("#%04" Pd " %s\n", num++, frame->ToCString()); |
| 2645 frame = iterator.NextFrame(); |
| 2646 } |
| 2647 } |
| 2648 RewindToFrame(resume_frame_index_); |
| 2649 UNREACHABLE(); |
| 2650 } |
| 2651 } |
| 2652 |
| 2653 |
| 2654 static intptr_t FindNextRewindFrameIndex(DebuggerStackTrace* stack, |
| 2655 intptr_t frame_index) { |
| 2656 for (intptr_t i = frame_index + 1; i < stack->Length(); i++) { |
| 2657 ActivationFrame* frame = stack->FrameAt(i); |
| 2658 if (frame->IsRewindable()) { |
| 2659 return i; |
| 2660 } |
| 2661 } |
| 2662 return -1; |
| 2663 } |
| 2664 |
| 2665 |
| 2666 // Can the top frame be rewound? |
| 2667 bool Debugger::CanRewindFrame(intptr_t frame_index, const char** error) const { |
| 2668 // check rewind pc is found |
| 2669 DebuggerStackTrace* stack = Isolate::Current()->debugger()->StackTrace(); |
| 2670 intptr_t num_frames = stack->Length(); |
| 2671 if (frame_index < 1 || frame_index >= num_frames) { |
| 2672 if (error) { |
| 2673 *error = Thread::Current()->zone()->PrintToString( |
| 2674 "Frame must be in bounds [1..%" Pd |
| 2675 "]: " |
| 2676 "saw %" Pd "", |
| 2677 num_frames - 1, frame_index); |
| 2678 } |
| 2679 return false; |
| 2680 } |
| 2681 ActivationFrame* frame = stack->FrameAt(frame_index); |
| 2682 if (!frame->IsRewindable()) { |
| 2683 intptr_t next_index = FindNextRewindFrameIndex(stack, frame_index); |
| 2684 if (next_index > 0) { |
| 2685 *error = Thread::Current()->zone()->PrintToString( |
| 2686 "Cannot rewind to frame %" Pd |
| 2687 " due to conflicting compiler " |
| 2688 "optimizations. " |
| 2689 "Run the vm with --no-prune-dead-locals to disallow these " |
| 2690 "optimizations. " |
| 2691 "Next valid rewind frame is %" Pd ".", |
| 2692 frame_index, next_index); |
| 2693 } else { |
| 2694 *error = Thread::Current()->zone()->PrintToString( |
| 2695 "Cannot rewind to frame %" Pd |
| 2696 " due to conflicting compiler " |
| 2697 "optimizations. " |
| 2698 "Run the vm with --no-prune-dead-locals to disallow these " |
| 2699 "optimizations.", |
| 2700 frame_index); |
| 2701 } |
| 2702 return false; |
| 2703 } |
| 2704 return true; |
| 2705 } |
| 2706 |
| 2707 |
| 2708 // Given a return address pc, find the "rewind" pc, which is the pc |
| 2709 // before the corresponding call. |
| 2710 static uword LookupRewindPc(const Code& code, uword pc) { |
| 2711 ASSERT(!code.is_optimized()); |
| 2712 ASSERT(code.ContainsInstructionAt(pc)); |
| 2713 |
| 2714 uword pc_offset = pc - code.PayloadStart(); |
| 2715 const PcDescriptors& descriptors = |
| 2716 PcDescriptors::Handle(code.pc_descriptors()); |
| 2717 PcDescriptors::Iterator iter( |
| 2718 descriptors, RawPcDescriptors::kRewind | RawPcDescriptors::kIcCall | |
| 2719 RawPcDescriptors::kUnoptStaticCall); |
| 2720 intptr_t rewind_deopt_id = -1; |
| 2721 uword rewind_pc = 0; |
| 2722 while (iter.MoveNext()) { |
| 2723 if (iter.Kind() == RawPcDescriptors::kRewind) { |
| 2724 // Remember the last rewind so we don't need to iterator twice. |
| 2725 rewind_pc = code.PayloadStart() + iter.PcOffset(); |
| 2726 rewind_deopt_id = iter.DeoptId(); |
| 2727 } |
| 2728 if ((pc_offset == iter.PcOffset()) && (iter.DeoptId() == rewind_deopt_id)) { |
| 2729 return rewind_pc; |
| 2730 } |
| 2731 } |
| 2732 return 0; |
| 2733 } |
| 2734 |
| 2735 |
| 2736 void Debugger::RewindToFrame(intptr_t frame_index) { |
| 2737 Thread* thread = Thread::Current(); |
| 2738 Zone* zone = thread->zone(); |
| 2739 Code& code = Code::Handle(zone); |
| 2740 Function& function = Function::Handle(zone); |
| 2741 |
| 2742 // Find the requested frame. |
| 2743 StackFrameIterator iterator(false); |
| 2744 intptr_t current_frame = 0; |
| 2745 for (StackFrame* frame = iterator.NextFrame(); frame != NULL; |
| 2746 frame = iterator.NextFrame()) { |
| 2747 ASSERT(frame->IsValid()); |
| 2748 if (frame->IsDartFrame()) { |
| 2749 code = frame->LookupDartCode(); |
| 2750 function = code.function(); |
| 2751 if (!IsFunctionVisible(function)) { |
| 2752 continue; |
| 2753 } |
| 2754 if (code.is_optimized()) { |
| 2755 intptr_t sub_index = 0; |
| 2756 for (InlinedFunctionsIterator it(code, frame->pc()); !it.Done(); |
| 2757 it.Advance()) { |
| 2758 if (current_frame == frame_index) { |
| 2759 RewindToOptimizedFrame(frame, code, sub_index); |
| 2760 UNREACHABLE(); |
| 2761 } |
| 2762 current_frame++; |
| 2763 sub_index++; |
| 2764 } |
| 2765 } else { |
| 2766 if (current_frame == frame_index) { |
| 2767 // We are rewinding to an unoptimized frame. |
| 2768 RewindToUnoptimizedFrame(frame, code); |
| 2769 UNREACHABLE(); |
| 2770 } |
| 2771 current_frame++; |
| 2772 } |
| 2773 } |
| 2774 } |
| 2775 UNIMPLEMENTED(); |
| 2776 } |
| 2777 |
| 2778 |
| 2779 void Debugger::RewindToUnoptimizedFrame(StackFrame* frame, const Code& code) { |
| 2780 // We will be jumping out of the debugger rather than exiting this |
| 2781 // function, so prepare the debugger state. |
| 2782 stack_trace_ = NULL; |
| 2783 resume_action_ = kContinue; |
| 2784 resume_frame_index_ = -1; |
| 2785 EnterSingleStepMode(); |
| 2786 |
| 2787 uword rewind_pc = LookupRewindPc(code, frame->pc()); |
| 2788 if (FLAG_trace_rewind && rewind_pc == 0) { |
| 2789 OS::PrintErr("Unable to find rewind pc for pc(%" Px ")\n", frame->pc()); |
| 2790 } |
| 2791 ASSERT(rewind_pc != 0); |
| 2792 if (FLAG_trace_rewind) { |
| 2793 OS::PrintErr( |
| 2794 "===============================\n" |
| 2795 "Rewinding to unoptimized frame:\n" |
| 2796 " rewind_pc(0x%" Px ") sp(0x%" Px ") fp(0x%" Px |
| 2797 ")\n" |
| 2798 "===============================\n", |
| 2799 rewind_pc, frame->sp(), frame->fp()); |
| 2800 } |
| 2801 Exceptions::JumpToFrame(Thread::Current(), rewind_pc, frame->sp(), |
| 2802 frame->fp(), true /* clear lazy deopt at target */); |
| 2803 UNREACHABLE(); |
| 2804 } |
| 2805 |
| 2806 |
| 2807 void Debugger::RewindToOptimizedFrame(StackFrame* frame, |
| 2808 const Code& optimized_code, |
| 2809 intptr_t sub_index) { |
| 2810 post_deopt_frame_index_ = sub_index; |
| 2811 |
| 2812 // We will be jumping out of the debugger rather than exiting this |
| 2813 // function, so prepare the debugger state. |
| 2814 stack_trace_ = NULL; |
| 2815 resume_action_ = kContinue; |
| 2816 resume_frame_index_ = -1; |
| 2817 EnterSingleStepMode(); |
| 2818 |
| 2819 if (FLAG_trace_rewind) { |
| 2820 OS::PrintErr( |
| 2821 "===============================\n" |
| 2822 "Deoptimizing frame for rewind:\n" |
| 2823 " deopt_pc(0x%" Px ") sp(0x%" Px ") fp(0x%" Px |
| 2824 ")\n" |
| 2825 "===============================\n", |
| 2826 frame->pc(), frame->sp(), frame->fp()); |
| 2827 } |
| 2828 Thread* thread = Thread::Current(); |
| 2829 thread->set_resume_pc(frame->pc()); |
| 2830 uword deopt_stub_pc = StubCode::DeoptForRewind_entry()->EntryPoint(); |
| 2831 Exceptions::JumpToFrame(thread, deopt_stub_pc, frame->sp(), frame->fp(), |
| 2832 true /* clear lazy deopt at target */); |
| 2833 UNREACHABLE(); |
| 2834 } |
| 2835 |
| 2836 |
| 2837 void Debugger::RewindPostDeopt() { |
| 2838 intptr_t rewind_frame = post_deopt_frame_index_; |
| 2839 post_deopt_frame_index_ = -1; |
| 2840 if (FLAG_trace_rewind) { |
| 2841 OS::PrintErr("Post deopt, jumping to frame %" Pd "\n", rewind_frame); |
| 2842 OS::PrintErr( |
| 2843 "-------------------------\n" |
| 2844 "All frames...\n\n"); |
| 2845 StackFrameIterator iterator(false); |
| 2846 StackFrame* frame = iterator.NextFrame(); |
| 2847 intptr_t num = 0; |
| 2848 while ((frame != NULL)) { |
| 2849 OS::PrintErr("#%04" Pd " %s\n", num++, frame->ToCString()); |
| 2850 frame = iterator.NextFrame(); |
| 2851 } |
| 2852 } |
| 2853 |
| 2854 Thread* thread = Thread::Current(); |
| 2855 Zone* zone = thread->zone(); |
| 2856 Code& code = Code::Handle(zone); |
| 2857 |
| 2858 StackFrameIterator iterator(false); |
| 2859 intptr_t current_frame = 0; |
| 2860 for (StackFrame* frame = iterator.NextFrame(); frame != NULL; |
| 2861 frame = iterator.NextFrame()) { |
| 2862 ASSERT(frame->IsValid()); |
| 2863 if (frame->IsDartFrame()) { |
| 2864 code = frame->LookupDartCode(); |
| 2865 ASSERT(!code.is_optimized()); |
| 2866 if (current_frame == rewind_frame) { |
| 2867 RewindToUnoptimizedFrame(frame, code); |
| 2868 UNREACHABLE(); |
| 2869 } |
| 2870 current_frame++; |
| 2871 } |
| 2872 } |
| 2873 } |
| 2874 |
2588 | 2875 |
2589 // static | 2876 // static |
2590 bool Debugger::IsDebuggable(const Function& func) { | 2877 bool Debugger::IsDebuggable(const Function& func) { |
2591 if (!func.is_debuggable()) { | 2878 if (!func.is_debuggable()) { |
2592 return false; | 2879 return false; |
2593 } | 2880 } |
2594 const Class& cls = Class::Handle(func.Owner()); | 2881 const Class& cls = Class::Handle(func.Owner()); |
2595 const Library& lib = Library::Handle(cls.library()); | 2882 const Library& lib = Library::Handle(cls.library()); |
2596 return lib.IsDebuggable(); | 2883 return lib.IsDebuggable(); |
2597 } | 2884 } |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2786 cbpt->LineNumber(), cbpt->token_pos().ToCString(), | 3073 cbpt->LineNumber(), cbpt->token_pos().ToCString(), |
2787 top_frame->pc()); | 3074 top_frame->pc()); |
2788 } | 3075 } |
2789 | 3076 |
2790 ASSERT(synthetic_async_breakpoint_ == NULL); | 3077 ASSERT(synthetic_async_breakpoint_ == NULL); |
2791 synthetic_async_breakpoint_ = bpt_hit; | 3078 synthetic_async_breakpoint_ = bpt_hit; |
2792 bpt_hit = NULL; | 3079 bpt_hit = NULL; |
2793 | 3080 |
2794 // We are at the entry of an async function. | 3081 // We are at the entry of an async function. |
2795 // We issue a step over to resume at the point after the await statement. | 3082 // We issue a step over to resume at the point after the await statement. |
2796 SetStepOver(); | 3083 SetResumeAction(kStepOver); |
2797 // When we single step from a user breakpoint, our next stepping | 3084 // When we single step from a user breakpoint, our next stepping |
2798 // point will be at the exact same pc. Skip it. | 3085 // point will be at the exact same pc. Skip it. |
2799 HandleSteppingRequest(stack_trace_, true /* skip next step */); | 3086 HandleSteppingRequest(stack_trace_, true /* skip next step */); |
2800 stack_trace_ = NULL; | 3087 stack_trace_ = NULL; |
2801 return Error::null(); | 3088 return Error::null(); |
2802 } | 3089 } |
2803 | 3090 |
2804 if (FLAG_verbose_debug) { | 3091 if (FLAG_verbose_debug) { |
2805 OS::Print(">>> hit %s breakpoint at %s:%" Pd | 3092 OS::Print(">>> hit %s breakpoint at %s:%" Pd |
2806 " " | 3093 " " |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2839 DebuggerStackTrace* stack_trace = CollectStackTrace(); | 3126 DebuggerStackTrace* stack_trace = CollectStackTrace(); |
2840 ASSERT(stack_trace->Length() > 0); | 3127 ASSERT(stack_trace->Length() > 0); |
2841 ASSERT(stack_trace_ == NULL); | 3128 ASSERT(stack_trace_ == NULL); |
2842 stack_trace_ = stack_trace; | 3129 stack_trace_ = stack_trace; |
2843 | 3130 |
2844 // TODO(johnmccutchan): Send |msg| to Observatory. | 3131 // TODO(johnmccutchan): Send |msg| to Observatory. |
2845 | 3132 |
2846 // We are in the native call to Developer_debugger. the developer | 3133 // We are in the native call to Developer_debugger. the developer |
2847 // gets a better experience by not seeing this call. To accomplish | 3134 // gets a better experience by not seeing this call. To accomplish |
2848 // this, we continue execution until the call exits (step out). | 3135 // this, we continue execution until the call exits (step out). |
2849 SetStepOut(); | 3136 SetResumeAction(kStepOut); |
2850 HandleSteppingRequest(stack_trace_); | 3137 HandleSteppingRequest(stack_trace_); |
2851 | 3138 |
2852 stack_trace_ = NULL; | 3139 stack_trace_ = NULL; |
2853 } | 3140 } |
2854 | 3141 |
2855 | 3142 |
2856 void Debugger::Initialize(Isolate* isolate) { | 3143 void Debugger::Initialize(Isolate* isolate) { |
2857 if (initialized_) { | 3144 if (initialized_) { |
2858 return; | 3145 return; |
2859 } | 3146 } |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3292 | 3579 |
3293 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { | 3580 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { |
3294 ASSERT(bpt->next() == NULL); | 3581 ASSERT(bpt->next() == NULL); |
3295 bpt->set_next(code_breakpoints_); | 3582 bpt->set_next(code_breakpoints_); |
3296 code_breakpoints_ = bpt; | 3583 code_breakpoints_ = bpt; |
3297 } | 3584 } |
3298 | 3585 |
3299 #endif // !PRODUCT | 3586 #endif // !PRODUCT |
3300 | 3587 |
3301 } // namespace dart | 3588 } // namespace dart |
OLD | NEW |