| 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 ASSERT(!func.HasOptimizedCode()); | 310 ASSERT(!func.HasOptimizedCode()); |
| 311 Code& code = Code::Handle(func.unoptimized_code()); | 311 Code& code = Code::Handle(func.unoptimized_code()); |
| 312 ASSERT(!code.IsNull()); // Function must be compiled. | 312 ASSERT(!code.IsNull()); // Function must be compiled. |
| 313 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); | 313 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); |
| 314 ASSERT(pc_desc_index < desc.Length()); | 314 ASSERT(pc_desc_index < desc.Length()); |
| 315 token_index_ = desc.TokenIndex(pc_desc_index); | 315 token_index_ = desc.TokenIndex(pc_desc_index); |
| 316 ASSERT(token_index_ >= 0); | 316 ASSERT(token_index_ >= 0); |
| 317 pc_ = desc.PC(pc_desc_index); | 317 pc_ = desc.PC(pc_desc_index); |
| 318 ASSERT(pc_ != 0); | 318 ASSERT(pc_ != 0); |
| 319 breakpoint_kind_ = desc.DescriptorKind(pc_desc_index); | 319 breakpoint_kind_ = desc.DescriptorKind(pc_desc_index); |
| 320 ASSERT((breakpoint_kind_ == PcDescriptors::kIcCall) || |
| 321 (breakpoint_kind_ == PcDescriptors::kFuncCall) || |
| 322 (breakpoint_kind_ == PcDescriptors::kReturn)); |
| 320 } | 323 } |
| 321 | 324 |
| 322 | 325 |
| 323 CodeBreakpoint::~CodeBreakpoint() { | 326 CodeBreakpoint::~CodeBreakpoint() { |
| 324 // Make sure we don't leave patched code behind. | 327 // Make sure we don't leave patched code behind. |
| 325 ASSERT(!IsEnabled()); | 328 ASSERT(!IsEnabled()); |
| 329 // Poison the data so we catch use after free errors. |
| 330 #ifdef DEBUG |
| 331 function_ = Function::null(); |
| 332 pc_ = 0ul; |
| 333 src_bpt_ = NULL; |
| 334 next_ = NULL; |
| 335 breakpoint_kind_ = PcDescriptors::kOther; |
| 336 #endif |
| 326 } | 337 } |
| 327 | 338 |
| 328 | 339 |
| 329 RawScript* CodeBreakpoint::SourceCode() { | 340 RawScript* CodeBreakpoint::SourceCode() { |
| 330 const Function& func = Function::Handle(function_); | 341 const Function& func = Function::Handle(function_); |
| 331 const Class& cls = Class::Handle(func.owner()); | 342 const Class& cls = Class::Handle(func.owner()); |
| 332 return cls.script(); | 343 return cls.script(); |
| 333 } | 344 } |
| 334 | 345 |
| 335 | 346 |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 | 884 |
| 874 if (resume_action_ == kContinue) { | 885 if (resume_action_ == kContinue) { |
| 875 RemoveInternalBreakpoints(); | 886 RemoveInternalBreakpoints(); |
| 876 } else if (resume_action_ == kStepOver) { | 887 } else if (resume_action_ == kStepOver) { |
| 877 Function& func = Function::Handle(bpt->function()); | 888 Function& func = Function::Handle(bpt->function()); |
| 878 if (bpt->breakpoint_kind_ == PcDescriptors::kReturn) { | 889 if (bpt->breakpoint_kind_ == PcDescriptors::kReturn) { |
| 879 // If we are at the function return, do a StepOut action. | 890 // If we are at the function return, do a StepOut action. |
| 880 if (stack_trace->Length() > 1) { | 891 if (stack_trace->Length() > 1) { |
| 881 ActivationFrame* caller = stack_trace->ActivationFrameAt(1); | 892 ActivationFrame* caller = stack_trace->ActivationFrameAt(1); |
| 882 func = caller->DartFunction().raw(); | 893 func = caller->DartFunction().raw(); |
| 883 RemoveInternalBreakpoints(); | |
| 884 } | 894 } |
| 885 } | 895 } |
| 896 RemoveInternalBreakpoints(); // *bpt is now invalid. |
| 886 InstrumentForStepping(func); | 897 InstrumentForStepping(func); |
| 887 } else if (resume_action_ == kStepInto) { | 898 } else if (resume_action_ == kStepInto) { |
| 888 RemoveInternalBreakpoints(); | |
| 889 if (bpt->breakpoint_kind_ == PcDescriptors::kIcCall) { | 899 if (bpt->breakpoint_kind_ == PcDescriptors::kIcCall) { |
| 890 int num_args, num_named_args; | 900 int num_args, num_named_args; |
| 891 uword target; | 901 uword target; |
| 892 CodePatcher::GetInstanceCallAt(bpt->pc_, NULL, | 902 CodePatcher::GetInstanceCallAt(bpt->pc_, NULL, |
| 893 &num_args, &num_named_args, &target); | 903 &num_args, &num_named_args, &target); |
| 904 RemoveInternalBreakpoints(); // *bpt is now invalid. |
| 894 ActivationFrame* top_frame = stack_trace->ActivationFrameAt(0); | 905 ActivationFrame* top_frame = stack_trace->ActivationFrameAt(0); |
| 895 Instance& receiver = Instance::Handle( | 906 Instance& receiver = Instance::Handle( |
| 896 top_frame->GetInstanceCallReceiver(num_args)); | 907 top_frame->GetInstanceCallReceiver(num_args)); |
| 897 Code& code = Code::Handle( | 908 Code& code = Code::Handle( |
| 898 ResolveCompileInstanceCallTarget(isolate_, receiver)); | 909 ResolveCompileInstanceCallTarget(isolate_, receiver)); |
| 899 if (!code.IsNull()) { | 910 if (!code.IsNull()) { |
| 900 Function& callee = Function::Handle(code.function()); | 911 Function& callee = Function::Handle(code.function()); |
| 901 InstrumentForStepping(callee); | 912 InstrumentForStepping(callee); |
| 902 } | 913 } |
| 903 } else if (bpt->breakpoint_kind_ == PcDescriptors::kFuncCall) { | 914 } else if (bpt->breakpoint_kind_ == PcDescriptors::kFuncCall) { |
| 904 Function& callee = Function::Handle(); | 915 Function& callee = Function::Handle(); |
| 905 uword target; | 916 uword target; |
| 906 CodePatcher::GetStaticCallAt(bpt->pc_, &callee, &target); | 917 CodePatcher::GetStaticCallAt(bpt->pc_, &callee, &target); |
| 918 RemoveInternalBreakpoints(); // *bpt is now invalid. |
| 907 InstrumentForStepping(callee); | 919 InstrumentForStepping(callee); |
| 908 } else { | 920 } else { |
| 909 ASSERT(bpt->breakpoint_kind_ == PcDescriptors::kReturn); | 921 ASSERT(bpt->breakpoint_kind_ == PcDescriptors::kReturn); |
| 922 RemoveInternalBreakpoints(); // *bpt is now invalid. |
| 910 // Treat like stepping out to caller. | 923 // Treat like stepping out to caller. |
| 911 if (stack_trace->Length() > 1) { | 924 if (stack_trace->Length() > 1) { |
| 912 ActivationFrame* caller = stack_trace->ActivationFrameAt(1); | 925 ActivationFrame* caller = stack_trace->ActivationFrameAt(1); |
| 913 InstrumentForStepping(caller->DartFunction()); | 926 InstrumentForStepping(caller->DartFunction()); |
| 914 } | 927 } |
| 915 } | 928 } |
| 916 } else { | 929 } else { |
| 917 ASSERT(resume_action_ == kStepOut); | 930 ASSERT(resume_action_ == kStepOut); |
| 931 RemoveInternalBreakpoints(); // *bpt is now invalid. |
| 918 // Set stepping breakpoints in the caller. | 932 // Set stepping breakpoints in the caller. |
| 919 RemoveInternalBreakpoints(); | |
| 920 if (stack_trace->Length() > 1) { | 933 if (stack_trace->Length() > 1) { |
| 921 ActivationFrame* caller = stack_trace->ActivationFrameAt(1); | 934 ActivationFrame* caller = stack_trace->ActivationFrameAt(1); |
| 922 InstrumentForStepping(caller->DartFunction()); | 935 InstrumentForStepping(caller->DartFunction()); |
| 923 } | 936 } |
| 924 } | 937 } |
| 925 } | 938 } |
| 926 | 939 |
| 927 | 940 |
| 928 void Debugger::Initialize(Isolate* isolate) { | 941 void Debugger::Initialize(Isolate* isolate) { |
| 929 if (initialized_) { | 942 if (initialized_) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 } | 1084 } |
| 1072 | 1085 |
| 1073 | 1086 |
| 1074 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { | 1087 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { |
| 1075 ASSERT(bpt->next() == NULL); | 1088 ASSERT(bpt->next() == NULL); |
| 1076 bpt->set_next(code_breakpoints_); | 1089 bpt->set_next(code_breakpoints_); |
| 1077 code_breakpoints_ = bpt; | 1090 code_breakpoints_ = bpt; |
| 1078 } | 1091 } |
| 1079 | 1092 |
| 1080 } // namespace dart | 1093 } // namespace dart |
| OLD | NEW |