| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/debug/debug.h" | 5 #include "src/debug/debug.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
| 9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| 11 #include "src/codegen.h" | 11 #include "src/codegen.h" |
| 12 #include "src/compilation-cache.h" | 12 #include "src/compilation-cache.h" |
| 13 #include "src/compiler.h" | 13 #include "src/compiler.h" |
| 14 #include "src/deoptimizer.h" | 14 #include "src/deoptimizer.h" |
| 15 #include "src/execution.h" | 15 #include "src/execution.h" |
| 16 #include "src/frames-inl.h" | 16 #include "src/frames-inl.h" |
| 17 #include "src/full-codegen/full-codegen.h" | 17 #include "src/full-codegen/full-codegen.h" |
| 18 #include "src/global-handles.h" | 18 #include "src/global-handles.h" |
| 19 #include "src/interpreter/bytecodes.h" | |
| 20 #include "src/interpreter/interpreter.h" | 19 #include "src/interpreter/interpreter.h" |
| 21 #include "src/isolate-inl.h" | 20 #include "src/isolate-inl.h" |
| 22 #include "src/list.h" | 21 #include "src/list.h" |
| 23 #include "src/log.h" | 22 #include "src/log.h" |
| 24 #include "src/messages.h" | 23 #include "src/messages.h" |
| 25 #include "src/snapshot/natives.h" | 24 #include "src/snapshot/natives.h" |
| 26 | 25 |
| 27 #include "include/v8-debug.h" | 26 #include "include/v8-debug.h" |
| 28 | 27 |
| 29 namespace v8 { | 28 namespace v8 { |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 // Threading support. | 466 // Threading support. |
| 468 void Debug::ThreadInit() { | 467 void Debug::ThreadInit() { |
| 469 thread_local_.break_count_ = 0; | 468 thread_local_.break_count_ = 0; |
| 470 thread_local_.break_id_ = 0; | 469 thread_local_.break_id_ = 0; |
| 471 thread_local_.break_frame_id_ = StackFrame::NO_ID; | 470 thread_local_.break_frame_id_ = StackFrame::NO_ID; |
| 472 thread_local_.last_step_action_ = StepNone; | 471 thread_local_.last_step_action_ = StepNone; |
| 473 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; | 472 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; |
| 474 thread_local_.last_fp_ = 0; | 473 thread_local_.last_fp_ = 0; |
| 475 thread_local_.target_fp_ = 0; | 474 thread_local_.target_fp_ = 0; |
| 476 thread_local_.step_in_enabled_ = false; | 475 thread_local_.step_in_enabled_ = false; |
| 476 thread_local_.return_value_ = Handle<Object>(); |
| 477 // TODO(isolates): frames_are_dropped_? | 477 // TODO(isolates): frames_are_dropped_? |
| 478 base::NoBarrier_Store(&thread_local_.current_debug_scope_, | 478 base::NoBarrier_Store(&thread_local_.current_debug_scope_, |
| 479 static_cast<base::AtomicWord>(0)); | 479 static_cast<base::AtomicWord>(0)); |
| 480 } | 480 } |
| 481 | 481 |
| 482 | 482 |
| 483 char* Debug::ArchiveDebug(char* storage) { | 483 char* Debug::ArchiveDebug(char* storage) { |
| 484 char* to = storage; | 484 char* to = storage; |
| 485 MemCopy(to, reinterpret_cast<char*>(&thread_local_), sizeof(ThreadLocal)); | 485 MemCopy(to, reinterpret_cast<char*>(&thread_local_), sizeof(ThreadLocal)); |
| 486 ThreadInit(); | 486 ThreadInit(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 if (!is_loaded()) return; | 556 if (!is_loaded()) return; |
| 557 | 557 |
| 558 // Clear debugger context global handle. | 558 // Clear debugger context global handle. |
| 559 GlobalHandles::Destroy(Handle<Object>::cast(debug_context_).location()); | 559 GlobalHandles::Destroy(Handle<Object>::cast(debug_context_).location()); |
| 560 debug_context_ = Handle<Context>(); | 560 debug_context_ = Handle<Context>(); |
| 561 } | 561 } |
| 562 | 562 |
| 563 | 563 |
| 564 void Debug::Break(Arguments args, JavaScriptFrame* frame) { | 564 void Debug::Break(Arguments args, JavaScriptFrame* frame) { |
| 565 HandleScope scope(isolate_); | 565 HandleScope scope(isolate_); |
| 566 DCHECK(args.length() == 0); | 566 DCHECK(args.length() == 1); |
| 567 | 567 |
| 568 // Initialize LiveEdit. | 568 // Initialize LiveEdit. |
| 569 LiveEdit::InitializeThreadLocal(this); | 569 LiveEdit::InitializeThreadLocal(this); |
| 570 | 570 |
| 571 // Just continue if breaks are disabled or debugger cannot be loaded. | 571 // Just continue if breaks are disabled or debugger cannot be loaded. |
| 572 if (break_disabled()) return; | 572 if (break_disabled()) return; |
| 573 | 573 |
| 574 // Enter the debugger. | 574 // Enter the debugger. |
| 575 DebugScope debug_scope(this); | 575 DebugScope debug_scope(this); |
| 576 if (debug_scope.failed()) return; | 576 if (debug_scope.failed()) return; |
| (...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1562 return; | 1562 return; |
| 1563 } | 1563 } |
| 1564 // Move to next in list. | 1564 // Move to next in list. |
| 1565 prev = current; | 1565 prev = current; |
| 1566 current = current->next(); | 1566 current = current->next(); |
| 1567 } | 1567 } |
| 1568 | 1568 |
| 1569 UNREACHABLE(); | 1569 UNREACHABLE(); |
| 1570 } | 1570 } |
| 1571 | 1571 |
| 1572 Object* Debug::SetAfterBreakTarget(JavaScriptFrame* frame) { | 1572 void Debug::SetAfterBreakTarget(JavaScriptFrame* frame) { |
| 1573 if (frame->is_interpreted()) { | 1573 after_break_target_ = NULL; |
| 1574 // Find the handler from the original bytecode array. | 1574 if (!LiveEdit::SetAfterBreakTarget(this)) { |
| 1575 InterpretedFrame* interpreted_frame = | 1575 // Continue just after the slot. |
| 1576 reinterpret_cast<InterpretedFrame*>(frame); | 1576 after_break_target_ = frame->pc(); |
| 1577 SharedFunctionInfo* shared = interpreted_frame->function()->shared(); | |
| 1578 BytecodeArray* bytecode_array = shared->bytecode_array(); | |
| 1579 int bytecode_offset = interpreted_frame->GetBytecodeOffset(); | |
| 1580 interpreter::Bytecode bytecode = | |
| 1581 interpreter::Bytecodes::FromByte(bytecode_array->get(bytecode_offset)); | |
| 1582 return isolate_->interpreter()->GetBytecodeHandler( | |
| 1583 bytecode, interpreter::OperandScale::kSingle); | |
| 1584 } else { | |
| 1585 after_break_target_ = NULL; | |
| 1586 if (!LiveEdit::SetAfterBreakTarget(this)) { | |
| 1587 // Continue just after the slot. | |
| 1588 after_break_target_ = frame->pc(); | |
| 1589 } | |
| 1590 return isolate_->heap()->undefined_value(); | |
| 1591 } | 1577 } |
| 1592 } | 1578 } |
| 1593 | 1579 |
| 1594 | 1580 |
| 1595 bool Debug::IsBreakAtReturn(JavaScriptFrame* frame) { | 1581 bool Debug::IsBreakAtReturn(JavaScriptFrame* frame) { |
| 1596 HandleScope scope(isolate_); | 1582 HandleScope scope(isolate_); |
| 1597 | 1583 |
| 1598 // Get the executing function in which the debug break occurred. | 1584 // Get the executing function in which the debug break occurred. |
| 1599 Handle<JSFunction> function(JSFunction::cast(frame->function())); | 1585 Handle<JSFunction> function(JSFunction::cast(frame->function())); |
| 1600 Handle<SharedFunctionInfo> shared(function->shared()); | 1586 Handle<SharedFunctionInfo> shared(function->shared()); |
| (...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2321 DebugScope::DebugScope(Debug* debug) | 2307 DebugScope::DebugScope(Debug* debug) |
| 2322 : debug_(debug), | 2308 : debug_(debug), |
| 2323 prev_(debug->debugger_entry()), | 2309 prev_(debug->debugger_entry()), |
| 2324 save_(debug_->isolate_), | 2310 save_(debug_->isolate_), |
| 2325 no_termination_exceptons_(debug_->isolate_, | 2311 no_termination_exceptons_(debug_->isolate_, |
| 2326 StackGuard::TERMINATE_EXECUTION) { | 2312 StackGuard::TERMINATE_EXECUTION) { |
| 2327 // Link recursive debugger entry. | 2313 // Link recursive debugger entry. |
| 2328 base::NoBarrier_Store(&debug_->thread_local_.current_debug_scope_, | 2314 base::NoBarrier_Store(&debug_->thread_local_.current_debug_scope_, |
| 2329 reinterpret_cast<base::AtomicWord>(this)); | 2315 reinterpret_cast<base::AtomicWord>(this)); |
| 2330 | 2316 |
| 2331 // Store the previous break id and frame id. | 2317 // Store the previous break id, frame id and return value. |
| 2332 break_id_ = debug_->break_id(); | 2318 break_id_ = debug_->break_id(); |
| 2333 break_frame_id_ = debug_->break_frame_id(); | 2319 break_frame_id_ = debug_->break_frame_id(); |
| 2320 return_value_ = debug_->get_return_value(); |
| 2334 | 2321 |
| 2335 // Create the new break info. If there is no JavaScript frames there is no | 2322 // Create the new break info. If there is no JavaScript frames there is no |
| 2336 // break frame id. | 2323 // break frame id. |
| 2337 JavaScriptFrameIterator it(isolate()); | 2324 JavaScriptFrameIterator it(isolate()); |
| 2338 bool has_js_frames = !it.done(); | 2325 bool has_js_frames = !it.done(); |
| 2339 debug_->thread_local_.break_frame_id_ = has_js_frames ? it.frame()->id() | 2326 debug_->thread_local_.break_frame_id_ = has_js_frames ? it.frame()->id() |
| 2340 : StackFrame::NO_ID; | 2327 : StackFrame::NO_ID; |
| 2341 debug_->SetNextBreakId(); | 2328 debug_->SetNextBreakId(); |
| 2342 | 2329 |
| 2343 debug_->UpdateState(); | 2330 debug_->UpdateState(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2361 if (debug_->has_commands()) isolate()->stack_guard()->RequestDebugCommand(); | 2348 if (debug_->has_commands()) isolate()->stack_guard()->RequestDebugCommand(); |
| 2362 } | 2349 } |
| 2363 | 2350 |
| 2364 // Leaving this debugger entry. | 2351 // Leaving this debugger entry. |
| 2365 base::NoBarrier_Store(&debug_->thread_local_.current_debug_scope_, | 2352 base::NoBarrier_Store(&debug_->thread_local_.current_debug_scope_, |
| 2366 reinterpret_cast<base::AtomicWord>(prev_)); | 2353 reinterpret_cast<base::AtomicWord>(prev_)); |
| 2367 | 2354 |
| 2368 // Restore to the previous break state. | 2355 // Restore to the previous break state. |
| 2369 debug_->thread_local_.break_frame_id_ = break_frame_id_; | 2356 debug_->thread_local_.break_frame_id_ = break_frame_id_; |
| 2370 debug_->thread_local_.break_id_ = break_id_; | 2357 debug_->thread_local_.break_id_ = break_id_; |
| 2358 debug_->thread_local_.return_value_ = return_value_; |
| 2371 | 2359 |
| 2372 debug_->UpdateState(); | 2360 debug_->UpdateState(); |
| 2373 } | 2361 } |
| 2374 | 2362 |
| 2375 | 2363 |
| 2376 MessageImpl MessageImpl::NewEvent(DebugEvent event, | 2364 MessageImpl MessageImpl::NewEvent(DebugEvent event, |
| 2377 bool running, | 2365 bool running, |
| 2378 Handle<JSObject> exec_state, | 2366 Handle<JSObject> exec_state, |
| 2379 Handle<JSObject> event_data) { | 2367 Handle<JSObject> event_data) { |
| 2380 MessageImpl message(true, event, running, | 2368 MessageImpl message(true, event, running, |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2621 } | 2609 } |
| 2622 | 2610 |
| 2623 | 2611 |
| 2624 void LockingCommandMessageQueue::Clear() { | 2612 void LockingCommandMessageQueue::Clear() { |
| 2625 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 2613 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
| 2626 queue_.Clear(); | 2614 queue_.Clear(); |
| 2627 } | 2615 } |
| 2628 | 2616 |
| 2629 } // namespace internal | 2617 } // namespace internal |
| 2630 } // namespace v8 | 2618 } // namespace v8 |
| OLD | NEW |