OLD | NEW |
---|---|
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 #ifdef DEBUG | 418 #ifdef DEBUG |
419 ASSERT(reloc_iterator_->done() == reloc_iterator_original_->done()); | 419 ASSERT(reloc_iterator_->done() == reloc_iterator_original_->done()); |
420 if (!reloc_iterator_->done()) { | 420 if (!reloc_iterator_->done()) { |
421 ASSERT(rmode() == original_rmode()); | 421 ASSERT(rmode() == original_rmode()); |
422 } | 422 } |
423 #endif | 423 #endif |
424 } | 424 } |
425 | 425 |
426 | 426 |
427 bool Debug::has_break_points_ = false; | 427 bool Debug::has_break_points_ = false; |
428 ScriptCache* Debug::script_cache_ = NULL; | |
428 DebugInfoListNode* Debug::debug_info_list_ = NULL; | 429 DebugInfoListNode* Debug::debug_info_list_ = NULL; |
429 | 430 |
430 | 431 |
431 // Threading support. | 432 // Threading support. |
432 void Debug::ThreadInit() { | 433 void Debug::ThreadInit() { |
433 thread_local_.break_count_ = 0; | 434 thread_local_.break_count_ = 0; |
434 thread_local_.break_id_ = 0; | 435 thread_local_.break_id_ = 0; |
435 thread_local_.break_frame_id_ = StackFrame::NO_ID; | 436 thread_local_.break_frame_id_ = StackFrame::NO_ID; |
436 thread_local_.last_step_action_ = StepNone; | 437 thread_local_.last_step_action_ = StepNone; |
437 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; | 438 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 | 480 |
480 // Default call debugger on uncaught exception. | 481 // Default call debugger on uncaught exception. |
481 bool Debug::break_on_exception_ = false; | 482 bool Debug::break_on_exception_ = false; |
482 bool Debug::break_on_uncaught_exception_ = true; | 483 bool Debug::break_on_uncaught_exception_ = true; |
483 | 484 |
484 Handle<Context> Debug::debug_context_ = Handle<Context>(); | 485 Handle<Context> Debug::debug_context_ = Handle<Context>(); |
485 Code* Debug::debug_break_return_entry_ = NULL; | 486 Code* Debug::debug_break_return_entry_ = NULL; |
486 Code* Debug::debug_break_return_ = NULL; | 487 Code* Debug::debug_break_return_ = NULL; |
487 | 488 |
488 | 489 |
490 void ScriptCache::Add(Handle<Script> script) { | |
491 // Create an entry in the hash map for the script. | |
492 int id = Smi::cast(script->id())->value(); | |
493 HashMap::Entry* entry = | |
494 HashMap::Lookup(reinterpret_cast<void*>(id), Hash(id), true); | |
495 if (entry->value != NULL) { | |
496 ASSERT(*script == *reinterpret_cast<Script**>(entry->value)); | |
497 return; | |
498 } | |
499 | |
500 // Globalize the script object, make it weak and use the location of the | |
501 // global handle as the value in the hash map. | |
502 Handle<Script> script_ = | |
503 Handle<Script>::cast((GlobalHandles::Create(*script))); | |
504 GlobalHandles::MakeWeak(reinterpret_cast<Object**>(script_.location()), | |
505 this, ScriptCache::HandleWeakScript); | |
506 entry->value = script_.location(); | |
507 } | |
508 | |
509 | |
510 Handle<FixedArray> ScriptCache::GetScripts() { | |
511 Handle<FixedArray> instances = Factory::NewFixedArray(occupancy()); | |
512 int count = 0; | |
513 for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) { | |
514 ASSERT(entry->value != NULL); | |
515 if (entry->value != NULL) { | |
516 instances->set(count, *reinterpret_cast<Script**>(entry->value)); | |
517 count++; | |
518 } | |
519 } | |
520 return instances; | |
521 } | |
522 | |
523 | |
524 void ScriptCache::ProcessCollectedScripts() { | |
525 for (int i = 0; i < collected_scripts_.length(); i++) { | |
526 Debugger::OnScriptCollected(collected_scripts_[i]); | |
527 } | |
528 collected_scripts_.Clear(); | |
529 } | |
530 | |
531 | |
532 void ScriptCache::Clear() { | |
533 // Iterate the script cache to get rid of all the weak handles. | |
534 for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) { | |
535 ASSERT(entry != NULL); | |
536 Object** location = reinterpret_cast<Object**>(entry->value); | |
537 ASSERT((*location)->IsScript()); | |
538 GlobalHandles::ClearWeakness(location); | |
539 GlobalHandles::Destroy(location); | |
540 } | |
541 // Clear the content of the hash map. | |
542 HashMap::Clear(); | |
543 } | |
544 | |
545 | |
546 void ScriptCache::HandleWeakScript(v8::Persistent<v8::Value> obj, void* data) { | |
547 ScriptCache* script_cache = reinterpret_cast<ScriptCache*>(data); | |
548 // Find the location of the global handle. | |
549 Script** location = | |
550 reinterpret_cast<Script**>(Utils::OpenHandle(*obj).location()); | |
551 ASSERT((*location)->IsScript()); | |
552 | |
553 HandleScope scope; | |
Mads Ager (chromium)
2009/05/18 12:57:00
Why do you need to create this handle to the scrip
Søren Thygesen Gjesse
2009/05/18 13:13:17
I don't - unused code.
| |
554 Handle<Script> script(location); | |
555 | |
556 // Remove the entry from the cache. | |
557 int id = Smi::cast((*location)->id())->value(); | |
558 script_cache->Remove(reinterpret_cast<void*>(id), Hash(id)); | |
559 script_cache->collected_scripts_.Add(id); | |
560 | |
561 // Clear the weak handle. | |
562 obj.Dispose(); | |
563 obj.Clear(); | |
564 } | |
565 | |
566 | |
567 void Debug::Setup(bool create_heap_objects) { | |
568 ThreadInit(); | |
569 if (create_heap_objects) { | |
570 // Get code to handle entry to debug break on return. | |
571 debug_break_return_entry_ = | |
572 Builtins::builtin(Builtins::Return_DebugBreakEntry); | |
573 ASSERT(debug_break_return_entry_->IsCode()); | |
574 | |
575 // Get code to handle debug break on return. | |
576 debug_break_return_ = | |
577 Builtins::builtin(Builtins::Return_DebugBreak); | |
578 ASSERT(debug_break_return_->IsCode()); | |
579 } | |
580 } | |
581 | |
582 | |
489 void Debug::HandleWeakDebugInfo(v8::Persistent<v8::Value> obj, void* data) { | 583 void Debug::HandleWeakDebugInfo(v8::Persistent<v8::Value> obj, void* data) { |
490 DebugInfoListNode* node = reinterpret_cast<DebugInfoListNode*>(data); | 584 DebugInfoListNode* node = reinterpret_cast<DebugInfoListNode*>(data); |
491 RemoveDebugInfo(node->debug_info()); | 585 RemoveDebugInfo(node->debug_info()); |
492 #ifdef DEBUG | 586 #ifdef DEBUG |
493 node = Debug::debug_info_list_; | 587 node = Debug::debug_info_list_; |
494 while (node != NULL) { | 588 while (node != NULL) { |
495 ASSERT(node != reinterpret_cast<DebugInfoListNode*>(data)); | 589 ASSERT(node != reinterpret_cast<DebugInfoListNode*>(data)); |
496 node = node->next(); | 590 node = node->next(); |
497 } | 591 } |
498 #endif | 592 #endif |
499 } | 593 } |
500 | 594 |
501 | 595 |
502 DebugInfoListNode::DebugInfoListNode(DebugInfo* debug_info): next_(NULL) { | 596 DebugInfoListNode::DebugInfoListNode(DebugInfo* debug_info): next_(NULL) { |
503 // Globalize the request debug info object and make it weak. | 597 // Globalize the request debug info object and make it weak. |
504 debug_info_ = Handle<DebugInfo>::cast((GlobalHandles::Create(debug_info))); | 598 debug_info_ = Handle<DebugInfo>::cast((GlobalHandles::Create(debug_info))); |
505 GlobalHandles::MakeWeak(reinterpret_cast<Object**>(debug_info_.location()), | 599 GlobalHandles::MakeWeak(reinterpret_cast<Object**>(debug_info_.location()), |
506 this, Debug::HandleWeakDebugInfo); | 600 this, Debug::HandleWeakDebugInfo); |
507 } | 601 } |
508 | 602 |
509 | 603 |
510 DebugInfoListNode::~DebugInfoListNode() { | 604 DebugInfoListNode::~DebugInfoListNode() { |
511 GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_info_.location())); | 605 GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_info_.location())); |
512 } | 606 } |
513 | 607 |
514 | 608 |
515 void Debug::Setup(bool create_heap_objects) { | |
516 ThreadInit(); | |
517 if (create_heap_objects) { | |
518 // Get code to handle entry to debug break on return. | |
519 debug_break_return_entry_ = | |
520 Builtins::builtin(Builtins::Return_DebugBreakEntry); | |
521 ASSERT(debug_break_return_entry_->IsCode()); | |
522 | |
523 // Get code to handle debug break on return. | |
524 debug_break_return_ = | |
525 Builtins::builtin(Builtins::Return_DebugBreak); | |
526 ASSERT(debug_break_return_->IsCode()); | |
527 } | |
528 } | |
529 | |
530 | |
531 bool Debug::CompileDebuggerScript(int index) { | 609 bool Debug::CompileDebuggerScript(int index) { |
532 HandleScope scope; | 610 HandleScope scope; |
533 | 611 |
534 // Bail out if the index is invalid. | 612 // Bail out if the index is invalid. |
535 if (index == -1) { | 613 if (index == -1) { |
536 return false; | 614 return false; |
537 } | 615 } |
538 | 616 |
539 // Find source and name for the requested script. | 617 // Find source and name for the requested script. |
540 Handle<String> source_code = Bootstrapper::NativesSourceLookup(index); | 618 Handle<String> source_code = Bootstrapper::NativesSourceLookup(index); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
620 | 698 |
621 // Make sure we mark the debugger as not loading before we might | 699 // Make sure we mark the debugger as not loading before we might |
622 // return. | 700 // return. |
623 Debugger::set_loading_debugger(false); | 701 Debugger::set_loading_debugger(false); |
624 | 702 |
625 // Check for caught exceptions. | 703 // Check for caught exceptions. |
626 if (caught_exception) return false; | 704 if (caught_exception) return false; |
627 | 705 |
628 // Debugger loaded. | 706 // Debugger loaded. |
629 debug_context_ = Handle<Context>::cast(GlobalHandles::Create(*context)); | 707 debug_context_ = Handle<Context>::cast(GlobalHandles::Create(*context)); |
708 | |
630 return true; | 709 return true; |
631 } | 710 } |
632 | 711 |
633 | 712 |
634 void Debug::Unload() { | 713 void Debug::Unload() { |
635 // Return debugger is not loaded. | 714 // Return debugger is not loaded. |
636 if (!IsLoaded()) { | 715 if (!IsLoaded()) { |
637 return; | 716 return; |
638 } | 717 } |
639 | 718 |
719 // Clear the script cache. | |
720 DestroyScriptCache(); | |
721 | |
640 // Clear debugger context global handle. | 722 // Clear debugger context global handle. |
641 GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_context_.location())); | 723 GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_context_.location())); |
642 debug_context_ = Handle<Context>(); | 724 debug_context_ = Handle<Context>(); |
643 } | 725 } |
644 | 726 |
645 | 727 |
646 // Set the flag indicating that preemption happened during debugging. | 728 // Set the flag indicating that preemption happened during debugging. |
647 void Debug::PreemptionWhileInDebugger() { | 729 void Debug::PreemptionWhileInDebugger() { |
648 ASSERT(InDebugger()); | 730 ASSERT(InDebugger()); |
649 Debug::set_preemption_pending(true); | 731 Debug::set_preemption_pending(true); |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1407 Handle<Object> fun(Top::global()->GetProperty(*function_name)); | 1489 Handle<Object> fun(Top::global()->GetProperty(*function_name)); |
1408 ASSERT(fun->IsJSFunction()); | 1490 ASSERT(fun->IsJSFunction()); |
1409 bool caught_exception; | 1491 bool caught_exception; |
1410 Handle<Object> js_object = Execution::TryCall( | 1492 Handle<Object> js_object = Execution::TryCall( |
1411 Handle<JSFunction>::cast(fun), | 1493 Handle<JSFunction>::cast(fun), |
1412 Handle<JSObject>(Debug::debug_context()->global()), | 1494 Handle<JSObject>(Debug::debug_context()->global()), |
1413 0, NULL, &caught_exception); | 1495 0, NULL, &caught_exception); |
1414 } | 1496 } |
1415 | 1497 |
1416 | 1498 |
1499 // If an object given is an external string, check that the underlying | |
1500 // resource is accessible. For other kinds of objects, always return true. | |
1501 static bool IsExternalStringValid(Object* str) { | |
1502 if (!str->IsString() || !StringShape(String::cast(str)).IsExternal()) { | |
1503 return true; | |
1504 } | |
1505 if (String::cast(str)->IsAsciiRepresentation()) { | |
1506 return ExternalAsciiString::cast(str)->resource() != NULL; | |
1507 } else if (String::cast(str)->IsTwoByteRepresentation()) { | |
1508 return ExternalTwoByteString::cast(str)->resource() != NULL; | |
1509 } else { | |
1510 return true; | |
1511 } | |
1512 } | |
1513 | |
1514 | |
1515 void Debug::CreateScriptCache() { | |
1516 HandleScope scope; | |
1517 | |
1518 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets | |
1519 // rid of all the cached script wrappers and the second gets rid of the | |
1520 // scripts which is no longer referenced. | |
1521 Heap::CollectAllGarbage(); | |
1522 Heap::CollectAllGarbage(); | |
1523 | |
1524 ASSERT(script_cache_ == NULL); | |
1525 script_cache_ = new ScriptCache(); | |
1526 | |
1527 // Scan heap for Script objects. | |
1528 int count = 0; | |
1529 HeapIterator iterator; | |
1530 while (iterator.has_next()) { | |
1531 HeapObject* obj = iterator.next(); | |
1532 ASSERT(obj != NULL); | |
1533 if (obj->IsScript() && IsExternalStringValid(Script::cast(obj)->source())) { | |
1534 script_cache_->Add(Handle<Script>(Script::cast(obj))); | |
1535 count++; | |
1536 } | |
1537 } | |
1538 } | |
1539 | |
1540 | |
1541 void Debug::DestroyScriptCache() { | |
1542 // Get rid of the script cache if it was created. | |
1543 if (script_cache_ != NULL) { | |
1544 delete script_cache_; | |
1545 script_cache_ = NULL; | |
1546 } | |
1547 } | |
1548 | |
1549 | |
1550 void Debug::AddScriptToScriptCache(Handle<Script> script) { | |
1551 if (script_cache_ != NULL) { | |
1552 script_cache_->Add(script); | |
1553 } | |
1554 } | |
1555 | |
1556 | |
1557 Handle<FixedArray> Debug::GetLoadedScripts() { | |
1558 // Create and fill the script cache when the loaded scripts is requested for | |
1559 // the first time. | |
1560 if (script_cache_ == NULL) { | |
1561 CreateScriptCache(); | |
1562 } | |
1563 | |
1564 // If the script cache is not active just return an empty array. | |
1565 ASSERT(script_cache_ != NULL); | |
1566 if (script_cache_ == NULL) { | |
1567 Factory::NewFixedArray(0); | |
1568 } | |
1569 | |
1570 // Perform GC to get unreferenced scripts evicted from the cache before before | |
Mads Ager (chromium)
2009/05/18 12:57:00
before before -> before
Søren Thygesen Gjesse
2009/05/18 13:13:17
Done.
| |
1571 // returning the content. | |
1572 Heap::CollectAllGarbage(); | |
1573 | |
1574 // Get the scripts from the cache. | |
1575 return script_cache_->GetScripts(); | |
1576 } | |
1577 | |
1578 | |
1579 void Debug::AfterGarbageCollection() { | |
1580 // Generate events for collected scripts. | |
1581 if (script_cache_ != NULL) { | |
1582 script_cache_->ProcessCollectedScripts(); | |
1583 } | |
1584 } | |
1585 | |
1586 | |
1417 Mutex* Debugger::debugger_access_ = OS::CreateMutex(); | 1587 Mutex* Debugger::debugger_access_ = OS::CreateMutex(); |
1418 Handle<Object> Debugger::event_listener_ = Handle<Object>(); | 1588 Handle<Object> Debugger::event_listener_ = Handle<Object>(); |
1419 Handle<Object> Debugger::event_listener_data_ = Handle<Object>(); | 1589 Handle<Object> Debugger::event_listener_data_ = Handle<Object>(); |
1420 bool Debugger::compiling_natives_ = false; | 1590 bool Debugger::compiling_natives_ = false; |
1421 bool Debugger::is_loading_debugger_ = false; | 1591 bool Debugger::is_loading_debugger_ = false; |
1422 bool Debugger::never_unload_debugger_ = false; | 1592 bool Debugger::never_unload_debugger_ = false; |
1423 v8::Debug::MessageHandler2 Debugger::message_handler_ = NULL; | 1593 v8::Debug::MessageHandler2 Debugger::message_handler_ = NULL; |
1424 bool Debugger::message_handler_cleared_ = false; | 1594 bool Debugger::message_handler_cleared_ = false; |
1425 v8::Debug::HostDispatchHandler Debugger::host_dispatch_handler_ = NULL; | 1595 v8::Debug::HostDispatchHandler Debugger::host_dispatch_handler_ = NULL; |
1426 int Debugger::host_dispatch_micros_ = 100 * 1000; | 1596 int Debugger::host_dispatch_micros_ = 100 * 1000; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1511 before ? Factory::true_value().location() : | 1681 before ? Factory::true_value().location() : |
1512 Factory::false_value().location() }; | 1682 Factory::false_value().location() }; |
1513 | 1683 |
1514 return MakeJSObject(CStrVector("MakeCompileEvent"), | 1684 return MakeJSObject(CStrVector("MakeCompileEvent"), |
1515 argc, | 1685 argc, |
1516 argv, | 1686 argv, |
1517 caught_exception); | 1687 caught_exception); |
1518 } | 1688 } |
1519 | 1689 |
1520 | 1690 |
1691 Handle<Object> Debugger::MakeScriptCollectedEvent(int id, | |
1692 bool* caught_exception) { | |
1693 // Create the script collected event object. | |
1694 Handle<Object> exec_state = MakeExecutionState(caught_exception); | |
1695 Handle<Object> id_object = Handle<Smi>(Smi::FromInt(id)); | |
1696 const int argc = 2; | |
1697 Object** argv[argc] = { exec_state.location(), id_object.location() }; | |
1698 | |
1699 return MakeJSObject(CStrVector("MakeScriptCollectedEvent"), | |
1700 argc, | |
1701 argv, | |
1702 caught_exception); | |
1703 } | |
1704 | |
1705 | |
1521 void Debugger::OnException(Handle<Object> exception, bool uncaught) { | 1706 void Debugger::OnException(Handle<Object> exception, bool uncaught) { |
1522 HandleScope scope; | 1707 HandleScope scope; |
1523 | 1708 |
1524 // Bail out based on state or if there is no listener for this event | 1709 // Bail out based on state or if there is no listener for this event |
1525 if (Debug::InDebugger()) return; | 1710 if (Debug::InDebugger()) return; |
1526 if (!Debugger::EventActive(v8::Exception)) return; | 1711 if (!Debugger::EventActive(v8::Exception)) return; |
1527 | 1712 |
1528 // Bail out if exception breaks are not active | 1713 // Bail out if exception breaks are not active |
1529 if (uncaught) { | 1714 if (uncaught) { |
1530 // Uncaught exceptions are reported by either flags. | 1715 // Uncaught exceptions are reported by either flags. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1617 ProcessDebugEvent(v8::BeforeCompile, | 1802 ProcessDebugEvent(v8::BeforeCompile, |
1618 Handle<JSObject>::cast(event_data), | 1803 Handle<JSObject>::cast(event_data), |
1619 true); | 1804 true); |
1620 } | 1805 } |
1621 | 1806 |
1622 | 1807 |
1623 // Handle debugger actions when a new script is compiled. | 1808 // Handle debugger actions when a new script is compiled. |
1624 void Debugger::OnAfterCompile(Handle<Script> script, Handle<JSFunction> fun) { | 1809 void Debugger::OnAfterCompile(Handle<Script> script, Handle<JSFunction> fun) { |
1625 HandleScope scope; | 1810 HandleScope scope; |
1626 | 1811 |
1812 // Add the newly compiled script to the script cache. | |
1813 Debug::AddScriptToScriptCache(script); | |
1814 | |
1815 // No more to do if not debugging. | |
1816 if (!IsDebuggerActive()) return; | |
1817 | |
1627 // No compile events while compiling natives. | 1818 // No compile events while compiling natives. |
1628 if (compiling_natives()) return; | 1819 if (compiling_natives()) return; |
1629 | 1820 |
1630 // No more to do if not debugging. | |
1631 if (!IsDebuggerActive()) return; | |
1632 | |
1633 // Store whether in debugger before entering debugger. | 1821 // Store whether in debugger before entering debugger. |
1634 bool in_debugger = Debug::InDebugger(); | 1822 bool in_debugger = Debug::InDebugger(); |
1635 | 1823 |
1636 // Enter the debugger. | 1824 // Enter the debugger. |
1637 EnterDebugger debugger; | 1825 EnterDebugger debugger; |
1638 if (debugger.FailedToEnter()) return; | 1826 if (debugger.FailedToEnter()) return; |
1639 | 1827 |
1640 // If debugging there might be script break points registered for this | 1828 // If debugging there might be script break points registered for this |
1641 // script. Make sure that these break points are set. | 1829 // script. Make sure that these break points are set. |
1642 | 1830 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1701 Handle<Object> event_data = MakeNewFunctionEvent(function, &caught_exception); | 1889 Handle<Object> event_data = MakeNewFunctionEvent(function, &caught_exception); |
1702 // Bail out and don't call debugger if exception. | 1890 // Bail out and don't call debugger if exception. |
1703 if (caught_exception) { | 1891 if (caught_exception) { |
1704 return; | 1892 return; |
1705 } | 1893 } |
1706 // Process debug event. | 1894 // Process debug event. |
1707 ProcessDebugEvent(v8::NewFunction, Handle<JSObject>::cast(event_data), true); | 1895 ProcessDebugEvent(v8::NewFunction, Handle<JSObject>::cast(event_data), true); |
1708 } | 1896 } |
1709 | 1897 |
1710 | 1898 |
1899 void Debugger::OnScriptCollected(int id) { | |
1900 HandleScope scope; | |
1901 | |
1902 // No more to do if not debugging. | |
1903 if (!IsDebuggerActive()) return; | |
1904 if (!Debugger::EventActive(v8::ScriptCollected)) return; | |
1905 | |
1906 // Enter the debugger. | |
1907 EnterDebugger debugger; | |
1908 if (debugger.FailedToEnter()) return; | |
1909 | |
1910 // Create the script collected state object. | |
1911 bool caught_exception = false; | |
1912 Handle<Object> event_data = MakeScriptCollectedEvent(id, | |
1913 &caught_exception); | |
1914 // Bail out and don't call debugger if exception. | |
1915 if (caught_exception) { | |
1916 return; | |
1917 } | |
1918 | |
1919 // Process debug event. | |
1920 ProcessDebugEvent(v8::ScriptCollected, | |
1921 Handle<JSObject>::cast(event_data), | |
1922 true); | |
1923 } | |
1924 | |
1925 | |
1711 void Debugger::ProcessDebugEvent(v8::DebugEvent event, | 1926 void Debugger::ProcessDebugEvent(v8::DebugEvent event, |
1712 Handle<JSObject> event_data, | 1927 Handle<JSObject> event_data, |
1713 bool auto_continue) { | 1928 bool auto_continue) { |
1714 HandleScope scope; | 1929 HandleScope scope; |
1715 | 1930 |
1716 // Create the execution state. | 1931 // Create the execution state. |
1717 bool caught_exception = false; | 1932 bool caught_exception = false; |
1718 Handle<Object> exec_state = MakeExecutionState(&caught_exception); | 1933 Handle<Object> exec_state = MakeExecutionState(&caught_exception); |
1719 if (caught_exception) { | 1934 if (caught_exception) { |
1720 return; | 1935 return; |
(...skipping 28 matching lines...) Expand all Loading... | |
1749 exec_state.location(), | 1964 exec_state.location(), |
1750 Handle<Object>::cast(event_data).location(), | 1965 Handle<Object>::cast(event_data).location(), |
1751 event_listener_data_.location() }; | 1966 event_listener_data_.location() }; |
1752 Handle<Object> result = Execution::TryCall(fun, Top::global(), | 1967 Handle<Object> result = Execution::TryCall(fun, Top::global(), |
1753 argc, argv, &caught_exception); | 1968 argc, argv, &caught_exception); |
1754 if (caught_exception) { | 1969 if (caught_exception) { |
1755 // Silently ignore exceptions from debug event listeners. | 1970 // Silently ignore exceptions from debug event listeners. |
1756 } | 1971 } |
1757 } | 1972 } |
1758 } | 1973 } |
1759 | |
1760 // Clear the mirror cache. | |
1761 Debug::ClearMirrorCache(); | |
1762 } | 1974 } |
1763 | 1975 |
1764 | 1976 |
1765 void Debugger::UnloadDebugger() { | 1977 void Debugger::UnloadDebugger() { |
1766 // Make sure that there are no breakpoints left. | 1978 // Make sure that there are no breakpoints left. |
1767 Debug::ClearAllBreakPoints(); | 1979 Debug::ClearAllBreakPoints(); |
1768 | 1980 |
1769 // Unload the debugger if feasible. | 1981 // Unload the debugger if feasible. |
1770 if (!never_unload_debugger_) { | 1982 if (!never_unload_debugger_) { |
1771 Debug::Unload(); | 1983 Debug::Unload(); |
(...skipping 19 matching lines...) Expand all Loading... | |
1791 sendEventMessage = !auto_continue; | 2003 sendEventMessage = !auto_continue; |
1792 break; | 2004 break; |
1793 case v8::Exception: | 2005 case v8::Exception: |
1794 sendEventMessage = true; | 2006 sendEventMessage = true; |
1795 break; | 2007 break; |
1796 case v8::BeforeCompile: | 2008 case v8::BeforeCompile: |
1797 break; | 2009 break; |
1798 case v8::AfterCompile: | 2010 case v8::AfterCompile: |
1799 sendEventMessage = true; | 2011 sendEventMessage = true; |
1800 break; | 2012 break; |
2013 case v8::ScriptCollected: | |
2014 sendEventMessage = true; | |
2015 break; | |
1801 case v8::NewFunction: | 2016 case v8::NewFunction: |
1802 break; | 2017 break; |
1803 default: | 2018 default: |
1804 UNREACHABLE(); | 2019 UNREACHABLE(); |
1805 } | 2020 } |
1806 | 2021 |
1807 // The debug command interrupt flag might have been set when the command was | 2022 // The debug command interrupt flag might have been set when the command was |
1808 // added. It should be enough to clear the flag only once while we are in the | 2023 // added. It should be enough to clear the flag only once while we are in the |
1809 // debugger. | 2024 // debugger. |
1810 ASSERT(Debug::InDebugger()); | 2025 ASSERT(Debug::InDebugger()); |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2289 | 2504 |
2290 | 2505 |
2291 void LockingCommandMessageQueue::Clear() { | 2506 void LockingCommandMessageQueue::Clear() { |
2292 ScopedLock sl(lock_); | 2507 ScopedLock sl(lock_); |
2293 queue_.Clear(); | 2508 queue_.Clear(); |
2294 } | 2509 } |
2295 | 2510 |
2296 #endif // ENABLE_DEBUGGER_SUPPORT | 2511 #endif // ENABLE_DEBUGGER_SUPPORT |
2297 | 2512 |
2298 } } // namespace v8::internal | 2513 } } // namespace v8::internal |
OLD | NEW |