| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/debug/debug.h" | 7 #include "src/debug/debug.h" |
| 8 | 8 |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 } | 423 } |
| 424 | 424 |
| 425 | 425 |
| 426 DebugInfoListNode::~DebugInfoListNode() { | 426 DebugInfoListNode::~DebugInfoListNode() { |
| 427 if (debug_info_ == nullptr) return; | 427 if (debug_info_ == nullptr) return; |
| 428 GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_info_)); | 428 GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_info_)); |
| 429 debug_info_ = nullptr; | 429 debug_info_ = nullptr; |
| 430 } | 430 } |
| 431 | 431 |
| 432 | 432 |
| 433 bool Debug::CompileDebuggerScript(Isolate* isolate, int index) { | |
| 434 Factory* factory = isolate->factory(); | |
| 435 HandleScope scope(isolate); | |
| 436 | |
| 437 // Bail out if the index is invalid. | |
| 438 if (index == -1) return false; | |
| 439 | |
| 440 // Find source and name for the requested script. | |
| 441 Handle<String> source_code = | |
| 442 isolate->bootstrapper()->SourceLookup<Natives>(index); | |
| 443 Vector<const char> name = Natives::GetScriptName(index); | |
| 444 Handle<String> script_name = | |
| 445 factory->NewStringFromAscii(name).ToHandleChecked(); | |
| 446 Handle<Context> context = isolate->native_context(); | |
| 447 | |
| 448 // Compile the script. | |
| 449 Handle<SharedFunctionInfo> function_info; | |
| 450 function_info = Compiler::CompileScript( | |
| 451 source_code, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(), | |
| 452 context, NULL, NULL, ScriptCompiler::kNoCompileOptions, NATIVES_CODE, | |
| 453 false); | |
| 454 if (function_info.is_null()) return false; | |
| 455 | |
| 456 // Execute the shared function in the debugger context. | |
| 457 Handle<JSFunction> function = | |
| 458 factory->NewFunctionFromSharedFunctionInfo(function_info, context); | |
| 459 | |
| 460 MaybeHandle<Object> maybe_exception; | |
| 461 MaybeHandle<Object> result = Execution::TryCall( | |
| 462 function, handle(context->global_proxy()), 0, NULL, &maybe_exception); | |
| 463 | |
| 464 // Check for caught exceptions. | |
| 465 if (result.is_null()) { | |
| 466 DCHECK(!isolate->has_pending_exception()); | |
| 467 MessageLocation computed_location; | |
| 468 isolate->ComputeLocation(&computed_location); | |
| 469 Handle<JSMessageObject> message = MessageHandler::MakeMessageObject( | |
| 470 isolate, MessageTemplate::kDebuggerLoading, &computed_location, | |
| 471 isolate->factory()->undefined_value(), Handle<JSArray>()); | |
| 472 DCHECK(!isolate->has_pending_exception()); | |
| 473 Handle<Object> exception; | |
| 474 if (maybe_exception.ToHandle(&exception)) { | |
| 475 isolate->set_pending_exception(*exception); | |
| 476 MessageHandler::ReportMessage(isolate, NULL, message); | |
| 477 } | |
| 478 DCHECK(!maybe_exception.is_null()); | |
| 479 return false; | |
| 480 } | |
| 481 | |
| 482 // Mark this script as native and return successfully. | |
| 483 Handle<Script> script(Script::cast(function->shared()->script())); | |
| 484 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); | |
| 485 return true; | |
| 486 } | |
| 487 | |
| 488 | |
| 489 bool Debug::Load() { | 433 bool Debug::Load() { |
| 490 // Return if debugger is already loaded. | 434 // Return if debugger is already loaded. |
| 491 if (is_loaded()) return true; | 435 if (is_loaded()) return true; |
| 492 | 436 |
| 493 // Bail out if we're already in the process of compiling the native | 437 // Bail out if we're already in the process of compiling the native |
| 494 // JavaScript source code for the debugger. | 438 // JavaScript source code for the debugger. |
| 495 if (is_suppressed_) return false; | 439 if (is_suppressed_) return false; |
| 496 SuppressDebug while_loading(this); | 440 SuppressDebug while_loading(this); |
| 497 | 441 |
| 498 // Disable breakpoints and interrupts while compiling and running the | 442 // Disable breakpoints and interrupts while compiling and running the |
| 499 // debugger scripts including the context creation code. | 443 // debugger scripts including the context creation code. |
| 500 DisableBreak disable(this, true); | 444 DisableBreak disable(this, true); |
| 501 PostponeInterruptsScope postpone(isolate_); | 445 PostponeInterruptsScope postpone(isolate_); |
| 502 | 446 |
| 503 // Create the debugger context. | 447 // Create the debugger context. |
| 504 HandleScope scope(isolate_); | 448 HandleScope scope(isolate_); |
| 505 ExtensionConfiguration no_extensions; | 449 ExtensionConfiguration no_extensions; |
| 506 Handle<Context> context = isolate_->bootstrapper()->CreateEnvironment( | 450 Handle<Context> context = isolate_->bootstrapper()->CreateEnvironment( |
| 507 MaybeHandle<JSGlobalProxy>(), v8::Local<ObjectTemplate>(), | 451 MaybeHandle<JSGlobalProxy>(), v8::Local<ObjectTemplate>(), &no_extensions, |
| 508 &no_extensions); | 452 DEBUG_CONTEXT); |
| 509 | 453 |
| 510 // Fail if no context could be created. | 454 // Fail if no context could be created. |
| 511 if (context.is_null()) return false; | 455 if (context.is_null()) return false; |
| 512 | 456 |
| 513 // Use the debugger context. | |
| 514 SaveContext save(isolate_); | |
| 515 isolate_->set_context(*context); | |
| 516 | |
| 517 // Expose the builtins object in the debugger context. | |
| 518 Handle<String> key = isolate_->factory()->InternalizeOneByteString( | |
| 519 STATIC_CHAR_VECTOR("builtins")); | |
| 520 Handle<GlobalObject> global = | |
| 521 Handle<GlobalObject>(context->global_object(), isolate_); | |
| 522 Handle<JSBuiltinsObject> builtin = | |
| 523 Handle<JSBuiltinsObject>(global->builtins(), isolate_); | |
| 524 RETURN_ON_EXCEPTION_VALUE( | |
| 525 isolate_, Object::SetProperty(global, key, builtin, SLOPPY), false); | |
| 526 | |
| 527 // Compile the JavaScript for the debugger in the debugger context. | |
| 528 bool caught_exception = | |
| 529 !CompileDebuggerScript(isolate_, Natives::GetIndex("mirrors")) || | |
| 530 !CompileDebuggerScript(isolate_, Natives::GetIndex("debug")); | |
| 531 | |
| 532 if (FLAG_enable_liveedit) { | |
| 533 caught_exception = caught_exception || | |
| 534 !CompileDebuggerScript(isolate_, Natives::GetIndex("liveedit")); | |
| 535 } | |
| 536 // Check for caught exceptions. | |
| 537 if (caught_exception) return false; | |
| 538 | |
| 539 debug_context_ = Handle<Context>::cast( | 457 debug_context_ = Handle<Context>::cast( |
| 540 isolate_->global_handles()->Create(*context)); | 458 isolate_->global_handles()->Create(*context)); |
| 541 return true; | 459 return true; |
| 542 } | 460 } |
| 543 | 461 |
| 544 | 462 |
| 545 void Debug::Unload() { | 463 void Debug::Unload() { |
| 546 ClearAllBreakPoints(); | 464 ClearAllBreakPoints(); |
| 547 ClearStepping(); | 465 ClearStepping(); |
| 548 | 466 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 HandleScope scope(isolate_); | 635 HandleScope scope(isolate_); |
| 718 | 636 |
| 719 // Ignore check if break point object is not a JSObject. | 637 // Ignore check if break point object is not a JSObject. |
| 720 if (!break_point_object->IsJSObject()) return true; | 638 if (!break_point_object->IsJSObject()) return true; |
| 721 | 639 |
| 722 // Get the function IsBreakPointTriggered (defined in debug.js). | 640 // Get the function IsBreakPointTriggered (defined in debug.js). |
| 723 Handle<String> is_break_point_triggered_string = | 641 Handle<String> is_break_point_triggered_string = |
| 724 factory->InternalizeOneByteString( | 642 factory->InternalizeOneByteString( |
| 725 STATIC_CHAR_VECTOR("IsBreakPointTriggered")); | 643 STATIC_CHAR_VECTOR("IsBreakPointTriggered")); |
| 726 Handle<GlobalObject> debug_global(debug_context()->global_object()); | 644 Handle<GlobalObject> debug_global(debug_context()->global_object()); |
| 727 Handle<JSFunction> check_break_point = | 645 Handle<JSFunction> check_break_point = Handle<JSFunction>::cast( |
| 728 Handle<JSFunction>::cast(Object::GetProperty( | 646 Object::GetProperty(debug_utils(), is_break_point_triggered_string) |
| 729 debug_global, is_break_point_triggered_string).ToHandleChecked()); | 647 .ToHandleChecked()); |
| 730 | 648 |
| 731 // Get the break id as an object. | 649 // Get the break id as an object. |
| 732 Handle<Object> break_id = factory->NewNumberFromInt(Debug::break_id()); | 650 Handle<Object> break_id = factory->NewNumberFromInt(Debug::break_id()); |
| 733 | 651 |
| 734 // Call HandleBreakPointx. | 652 // Call HandleBreakPointx. |
| 735 Handle<Object> argv[] = { break_id, break_point_object }; | 653 Handle<Object> argv[] = { break_id, break_point_object }; |
| 736 Handle<Object> result; | 654 Handle<Object> result; |
| 737 if (!Execution::TryCall(check_break_point, | 655 if (!Execution::TryCall(check_break_point, |
| 738 isolate_->js_builtins_object(), | 656 isolate_->js_builtins_object(), |
| 739 arraysize(argv), | 657 arraysize(argv), |
| (...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1740 | 1658 |
| 1741 bool Debug::IsDebugGlobal(GlobalObject* global) { | 1659 bool Debug::IsDebugGlobal(GlobalObject* global) { |
| 1742 return is_loaded() && global == debug_context()->global_object(); | 1660 return is_loaded() && global == debug_context()->global_object(); |
| 1743 } | 1661 } |
| 1744 | 1662 |
| 1745 | 1663 |
| 1746 void Debug::ClearMirrorCache() { | 1664 void Debug::ClearMirrorCache() { |
| 1747 PostponeInterruptsScope postpone(isolate_); | 1665 PostponeInterruptsScope postpone(isolate_); |
| 1748 HandleScope scope(isolate_); | 1666 HandleScope scope(isolate_); |
| 1749 AssertDebugContext(); | 1667 AssertDebugContext(); |
| 1750 Factory* factory = isolate_->factory(); | 1668 |
| 1751 Handle<GlobalObject> global(isolate_->global_object()); | 1669 Handle<Object> fun = |
| 1752 JSObject::SetProperty(global, | 1670 Object::GetProperty(isolate_, debug_utils(), "ClearMirrorCache") |
| 1753 factory->NewStringFromAsciiChecked("next_handle_"), | 1671 .ToHandleChecked(); |
| 1754 handle(Smi::FromInt(0), isolate_), SLOPPY).Check(); | 1672 Handle<Object> undefined = isolate_->factory()->undefined_value(); |
| 1755 JSObject::SetProperty(global, | 1673 Execution::TryCall(Handle<JSFunction>::cast(fun), undefined, 0, NULL); |
| 1756 factory->NewStringFromAsciiChecked("mirror_cache_"), | |
| 1757 factory->NewJSArray(0, FAST_ELEMENTS), SLOPPY).Check(); | |
| 1758 } | 1674 } |
| 1759 | 1675 |
| 1760 | 1676 |
| 1761 Handle<FixedArray> Debug::GetLoadedScripts() { | 1677 Handle<FixedArray> Debug::GetLoadedScripts() { |
| 1762 // Create and fill the script cache when the loaded scripts is requested for | 1678 // Create and fill the script cache when the loaded scripts is requested for |
| 1763 // the first time. | 1679 // the first time. |
| 1764 if (script_cache_ == NULL) script_cache_ = new ScriptCache(isolate_); | 1680 if (script_cache_ == NULL) script_cache_ = new ScriptCache(isolate_); |
| 1765 | 1681 |
| 1766 // Perform GC to get unreferenced scripts evicted from the cache before | 1682 // Perform GC to get unreferenced scripts evicted from the cache before |
| 1767 // returning the content. | 1683 // returning the content. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1824 script->set_eval_from_instructions_offset(Smi::FromInt(offset)); | 1740 script->set_eval_from_instructions_offset(Smi::FromInt(offset)); |
| 1825 } | 1741 } |
| 1826 } | 1742 } |
| 1827 | 1743 |
| 1828 | 1744 |
| 1829 MaybeHandle<Object> Debug::MakeJSObject(const char* constructor_name, | 1745 MaybeHandle<Object> Debug::MakeJSObject(const char* constructor_name, |
| 1830 int argc, | 1746 int argc, |
| 1831 Handle<Object> argv[]) { | 1747 Handle<Object> argv[]) { |
| 1832 AssertDebugContext(); | 1748 AssertDebugContext(); |
| 1833 // Create the execution state object. | 1749 // Create the execution state object. |
| 1834 Handle<GlobalObject> global(isolate_->global_object()); | 1750 Handle<Object> constructor = |
| 1835 Handle<Object> constructor = Object::GetProperty( | 1751 Object::GetProperty(isolate_, debug_utils(), constructor_name) |
| 1836 isolate_, global, constructor_name).ToHandleChecked(); | 1752 .ToHandleChecked(); |
| 1837 DCHECK(constructor->IsJSFunction()); | 1753 DCHECK(constructor->IsJSFunction()); |
| 1838 if (!constructor->IsJSFunction()) return MaybeHandle<Object>(); | 1754 if (!constructor->IsJSFunction()) return MaybeHandle<Object>(); |
| 1839 // We do not handle interrupts here. In particular, termination interrupts. | 1755 // We do not handle interrupts here. In particular, termination interrupts. |
| 1840 PostponeInterruptsScope no_interrupts(isolate_); | 1756 PostponeInterruptsScope no_interrupts(isolate_); |
| 1841 return Execution::TryCall(Handle<JSFunction>::cast(constructor), | 1757 return Execution::TryCall(Handle<JSFunction>::cast(constructor), |
| 1842 handle(debug_context()->global_proxy()), | 1758 handle(debug_context()->global_proxy()), |
| 1843 argc, | 1759 argc, |
| 1844 argv); | 1760 argv); |
| 1845 } | 1761 } |
| 1846 | 1762 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2054 } | 1970 } |
| 2055 | 1971 |
| 2056 HandleScope scope(isolate_); | 1972 HandleScope scope(isolate_); |
| 2057 DebugScope debug_scope(this); | 1973 DebugScope debug_scope(this); |
| 2058 if (debug_scope.failed()) return; | 1974 if (debug_scope.failed()) return; |
| 2059 | 1975 |
| 2060 // If debugging there might be script break points registered for this | 1976 // If debugging there might be script break points registered for this |
| 2061 // script. Make sure that these break points are set. | 1977 // script. Make sure that these break points are set. |
| 2062 | 1978 |
| 2063 // Get the function UpdateScriptBreakPoints (defined in debug.js). | 1979 // Get the function UpdateScriptBreakPoints (defined in debug.js). |
| 2064 Handle<String> update_script_break_points_string = | |
| 2065 isolate_->factory()->InternalizeOneByteString( | |
| 2066 STATIC_CHAR_VECTOR("UpdateScriptBreakPoints")); | |
| 2067 Handle<GlobalObject> debug_global(debug_context()->global_object()); | |
| 2068 Handle<Object> update_script_break_points = | 1980 Handle<Object> update_script_break_points = |
| 2069 Object::GetProperty( | 1981 Object::GetProperty(isolate_, debug_utils(), "UpdateScriptBreakPoints") |
| 2070 debug_global, update_script_break_points_string).ToHandleChecked(); | 1982 .ToHandleChecked(); |
| 2071 if (!update_script_break_points->IsJSFunction()) { | 1983 if (!update_script_break_points->IsJSFunction()) { |
| 2072 return; | 1984 return; |
| 2073 } | 1985 } |
| 2074 DCHECK(update_script_break_points->IsJSFunction()); | 1986 DCHECK(update_script_break_points->IsJSFunction()); |
| 2075 | 1987 |
| 2076 // Wrap the script object in a proper JS object before passing it | 1988 // Wrap the script object in a proper JS object before passing it |
| 2077 // to JavaScript. | 1989 // to JavaScript. |
| 2078 Handle<Object> wrapper = Script::GetWrapper(script); | 1990 Handle<Object> wrapper = Script::GetWrapper(script); |
| 2079 | 1991 |
| 2080 // Call UpdateScriptBreakPoints expect no exceptions. | 1992 // Call UpdateScriptBreakPoints expect no exceptions. |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2803 } | 2715 } |
| 2804 | 2716 |
| 2805 | 2717 |
| 2806 void LockingCommandMessageQueue::Clear() { | 2718 void LockingCommandMessageQueue::Clear() { |
| 2807 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 2719 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
| 2808 queue_.Clear(); | 2720 queue_.Clear(); |
| 2809 } | 2721 } |
| 2810 | 2722 |
| 2811 } // namespace internal | 2723 } // namespace internal |
| 2812 } // namespace v8 | 2724 } // namespace v8 |
| OLD | NEW |