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 "vm/code_generator.h" | 9 #include "vm/code_generator.h" |
10 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 } | 1171 } |
1172 } | 1172 } |
1173 } | 1173 } |
1174 | 1174 |
1175 | 1175 |
1176 void Debugger::SetInternalBreakpoints(const Function& target_function) { | 1176 void Debugger::SetInternalBreakpoints(const Function& target_function) { |
1177 if (target_function.is_native()) { | 1177 if (target_function.is_native()) { |
1178 // Can't instrument native functions. | 1178 // Can't instrument native functions. |
1179 return; | 1179 return; |
1180 } | 1180 } |
| 1181 Isolate* isolate = Isolate::Current(); |
1181 if (!target_function.HasCode()) { | 1182 if (!target_function.HasCode()) { |
1182 Compiler::CompileFunction(target_function); | 1183 Compiler::CompileFunction(isolate, target_function); |
1183 // If there were any errors, ignore them silently and return without | 1184 // If there were any errors, ignore them silently and return without |
1184 // adding breakpoints to target. | 1185 // adding breakpoints to target. |
1185 if (!target_function.HasCode()) { | 1186 if (!target_function.HasCode()) { |
1186 return; | 1187 return; |
1187 } | 1188 } |
1188 } | 1189 } |
1189 // Hang on to the code object before deoptimizing, in case deoptimization | 1190 // Hang on to the code object before deoptimizing, in case deoptimization |
1190 // might cause the GC to run. | 1191 // might cause the GC to run. |
1191 Code& code = Code::Handle(target_function.unoptimized_code()); | 1192 Code& code = Code::Handle(isolate, target_function.unoptimized_code()); |
1192 ASSERT(!code.IsNull()); | 1193 ASSERT(!code.IsNull()); |
1193 DeoptimizeWorld(); | 1194 DeoptimizeWorld(); |
1194 ASSERT(!target_function.HasOptimizedCode()); | 1195 ASSERT(!target_function.HasOptimizedCode()); |
1195 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); | 1196 PcDescriptors& desc = PcDescriptors::Handle(isolate, code.pc_descriptors()); |
1196 for (intptr_t i = 0; i < desc.Length(); i++) { | 1197 for (intptr_t i = 0; i < desc.Length(); i++) { |
1197 if (IsSafePoint(desc, i)) { | 1198 if (IsSafePoint(desc, i)) { |
1198 CodeBreakpoint* bpt = GetCodeBreakpoint(desc.PC(i)); | 1199 CodeBreakpoint* bpt = GetCodeBreakpoint(desc.PC(i)); |
1199 if (bpt != NULL) { | 1200 if (bpt != NULL) { |
1200 // There is already a breakpoint for this address. Make sure | 1201 // There is already a breakpoint for this address. Make sure |
1201 // it is enabled. | 1202 // it is enabled. |
1202 bpt->Enable(); | 1203 bpt->Enable(); |
1203 continue; | 1204 continue; |
1204 } | 1205 } |
1205 bpt = new CodeBreakpoint(code, i); | 1206 bpt = new CodeBreakpoint(code, i); |
(...skipping 28 matching lines...) Expand all Loading... |
1234 ActivationFrame* activation = | 1235 ActivationFrame* activation = |
1235 new ActivationFrame(pc, frame->fp(), frame->sp(), code, | 1236 new ActivationFrame(pc, frame->fp(), frame->sp(), code, |
1236 deopt_frame, deopt_frame_offset); | 1237 deopt_frame, deopt_frame_offset); |
1237 | 1238 |
1238 // Is there a closure call at the current PC? | 1239 // Is there a closure call at the current PC? |
1239 // | 1240 // |
1240 // We can't just check the callee_activation to see if it is a | 1241 // We can't just check the callee_activation to see if it is a |
1241 // closure function, because it may not be on the stack yet. | 1242 // closure function, because it may not be on the stack yet. |
1242 bool is_closure_call = false; | 1243 bool is_closure_call = false; |
1243 const PcDescriptors& pc_desc = | 1244 const PcDescriptors& pc_desc = |
1244 PcDescriptors::Handle(code.pc_descriptors()); | 1245 PcDescriptors::Handle(isolate, code.pc_descriptors()); |
1245 | 1246 |
1246 for (int i = 0; i < pc_desc.Length(); i++) { | 1247 for (int i = 0; i < pc_desc.Length(); i++) { |
1247 if (pc_desc.PC(i) == pc && | 1248 if (pc_desc.PC(i) == pc && |
1248 pc_desc.DescriptorKind(i) == PcDescriptors::kClosureCall) { | 1249 pc_desc.DescriptorKind(i) == PcDescriptors::kClosureCall) { |
1249 is_closure_call = true; | 1250 is_closure_call = true; |
1250 break; | 1251 break; |
1251 } | 1252 } |
1252 } | 1253 } |
1253 | 1254 |
1254 // Recover the context for this frame. | 1255 // Recover the context for this frame. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1300 | 1301 |
1301 // Create the DeoptContext for this deoptimization. | 1302 // Create the DeoptContext for this deoptimization. |
1302 DeoptContext* deopt_context = | 1303 DeoptContext* deopt_context = |
1303 new DeoptContext(frame, code, | 1304 new DeoptContext(frame, code, |
1304 DeoptContext::kDestIsAllocated, | 1305 DeoptContext::kDestIsAllocated, |
1305 NULL, NULL); | 1306 NULL, NULL); |
1306 isolate->set_deopt_context(deopt_context); | 1307 isolate->set_deopt_context(deopt_context); |
1307 | 1308 |
1308 deopt_context->FillDestFrame(); | 1309 deopt_context->FillDestFrame(); |
1309 deopt_context->MaterializeDeferredObjects(); | 1310 deopt_context->MaterializeDeferredObjects(); |
1310 const Array& dest_frame = Array::Handle(deopt_context->DestFrameAsArray()); | 1311 const Array& dest_frame = Array::Handle(isolate, |
| 1312 deopt_context->DestFrameAsArray()); |
1311 | 1313 |
1312 isolate->set_deopt_context(NULL); | 1314 isolate->set_deopt_context(NULL); |
1313 delete deopt_context; | 1315 delete deopt_context; |
1314 | 1316 |
1315 return dest_frame.raw(); | 1317 return dest_frame.raw(); |
1316 } | 1318 } |
1317 | 1319 |
1318 | 1320 |
1319 DebuggerStackTrace* Debugger::CollectStackTrace() { | 1321 DebuggerStackTrace* Debugger::CollectStackTrace() { |
1320 Isolate* isolate = Isolate::Current(); | 1322 Isolate* isolate = Isolate::Current(); |
1321 DebuggerStackTrace* stack_trace = new DebuggerStackTrace(8); | 1323 DebuggerStackTrace* stack_trace = new DebuggerStackTrace(8); |
1322 StackFrameIterator iterator(false); | 1324 StackFrameIterator iterator(false); |
1323 ActivationFrame* current_activation = NULL; | 1325 ActivationFrame* current_activation = NULL; |
1324 Context& entry_ctx = Context::Handle(isolate->top_context()); | 1326 Context& entry_ctx = Context::Handle(isolate, isolate->top_context()); |
1325 Code& code = Code::Handle(isolate); | 1327 Code& code = Code::Handle(isolate); |
1326 Code& inlined_code = Code::Handle(isolate); | 1328 Code& inlined_code = Code::Handle(isolate); |
1327 Array& deopt_frame = Array::Handle(isolate); | 1329 Array& deopt_frame = Array::Handle(isolate); |
1328 | 1330 |
1329 for (StackFrame* frame = iterator.NextFrame(); | 1331 for (StackFrame* frame = iterator.NextFrame(); |
1330 frame != NULL; | 1332 frame != NULL; |
1331 frame = iterator.NextFrame()) { | 1333 frame = iterator.NextFrame()) { |
1332 ASSERT(frame->IsValid()); | 1334 ASSERT(frame->IsValid()); |
1333 if (FLAG_trace_debugger_stacktrace) { | 1335 if (FLAG_trace_debugger_stacktrace) { |
1334 OS::PrintErr("CollectStackTrace: visiting frame:\n\t%s\n", | 1336 OS::PrintErr("CollectStackTrace: visiting frame:\n\t%s\n", |
(...skipping 10 matching lines...) Expand all Loading... |
1345 } else if (frame->IsDartFrame()) { | 1347 } else if (frame->IsDartFrame()) { |
1346 code = frame->LookupDartCode(); | 1348 code = frame->LookupDartCode(); |
1347 if (code.is_optimized()) { | 1349 if (code.is_optimized()) { |
1348 deopt_frame = DeoptimizeToArray(isolate, frame, code); | 1350 deopt_frame = DeoptimizeToArray(isolate, frame, code); |
1349 for (InlinedFunctionsIterator it(code, frame->pc()); | 1351 for (InlinedFunctionsIterator it(code, frame->pc()); |
1350 !it.Done(); | 1352 !it.Done(); |
1351 it.Advance()) { | 1353 it.Advance()) { |
1352 inlined_code = it.code(); | 1354 inlined_code = it.code(); |
1353 if (FLAG_trace_debugger_stacktrace) { | 1355 if (FLAG_trace_debugger_stacktrace) { |
1354 const Function& function = | 1356 const Function& function = |
1355 Function::Handle(inlined_code.function()); | 1357 Function::Handle(isolate, inlined_code.function()); |
1356 ASSERT(!function.IsNull()); | 1358 ASSERT(!function.IsNull()); |
1357 OS::PrintErr("CollectStackTrace: visiting inlined function: %s\n", | 1359 OS::PrintErr("CollectStackTrace: visiting inlined function: %s\n", |
1358 function.ToFullyQualifiedCString()); | 1360 function.ToFullyQualifiedCString()); |
1359 } | 1361 } |
1360 intptr_t deopt_frame_offset = it.GetDeoptFpOffset(); | 1362 intptr_t deopt_frame_offset = it.GetDeoptFpOffset(); |
1361 current_activation = CollectDartFrame(isolate, | 1363 current_activation = CollectDartFrame(isolate, |
1362 it.pc(), | 1364 it.pc(), |
1363 frame, | 1365 frame, |
1364 inlined_code, | 1366 inlined_code, |
1365 deopt_frame, | 1367 deopt_frame, |
(...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2560 } | 2562 } |
2561 | 2563 |
2562 | 2564 |
2563 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { | 2565 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { |
2564 ASSERT(bpt->next() == NULL); | 2566 ASSERT(bpt->next() == NULL); |
2565 bpt->set_next(code_breakpoints_); | 2567 bpt->set_next(code_breakpoints_); |
2566 code_breakpoints_ = bpt; | 2568 code_breakpoints_ = bpt; |
2567 } | 2569 } |
2568 | 2570 |
2569 } // namespace dart | 2571 } // namespace dart |
OLD | NEW |