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" |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 // Postpone interrupt during breakpoint processing. | 581 // Postpone interrupt during breakpoint processing. |
582 PostponeInterruptsScope postpone(isolate_); | 582 PostponeInterruptsScope postpone(isolate_); |
583 | 583 |
584 // Get the debug info (create it if it does not exist). | 584 // Get the debug info (create it if it does not exist). |
585 Handle<JSFunction> function(frame->function()); | 585 Handle<JSFunction> function(frame->function()); |
586 Handle<SharedFunctionInfo> shared(function->shared()); | 586 Handle<SharedFunctionInfo> shared(function->shared()); |
587 if (!EnsureDebugInfo(shared, function)) { | 587 if (!EnsureDebugInfo(shared, function)) { |
588 // Return if we failed to retrieve the debug info. | 588 // Return if we failed to retrieve the debug info. |
589 return; | 589 return; |
590 } | 590 } |
591 Handle<DebugInfo> debug_info(shared->GetDebugInfo()); | 591 Handle<DebugInfo> debug_info(shared->GetDebugInfo(), isolate_); |
592 | 592 |
593 // Find the break location where execution has stopped. | 593 // Find the break location where execution has stopped. |
594 BreakLocation location = BreakLocation::FromFrame(debug_info, frame); | 594 BreakLocation location = BreakLocation::FromFrame(debug_info, frame); |
595 | 595 |
596 // Find actual break points, if any, and trigger debug break event. | 596 // Find actual break points, if any, and trigger debug break event. |
597 Handle<Object> break_points_hit = CheckBreakPoints(&location); | 597 Handle<Object> break_points_hit = CheckBreakPoints(&location); |
598 if (!break_points_hit->IsUndefined()) { | 598 if (!break_points_hit->IsUndefined(isolate_)) { |
599 // Clear all current stepping setup. | 599 // Clear all current stepping setup. |
600 ClearStepping(); | 600 ClearStepping(); |
601 // Notify the debug event listeners. | 601 // Notify the debug event listeners. |
602 OnDebugBreak(break_points_hit, false); | 602 OnDebugBreak(break_points_hit, false); |
603 return; | 603 return; |
604 } | 604 } |
605 | 605 |
606 // No break point. Check for stepping. | 606 // No break point. Check for stepping. |
607 StepAction step_action = last_step_action(); | 607 StepAction step_action = last_step_action(); |
608 Address current_fp = frame->UnpaddedFP(); | 608 Address current_fp = frame->UnpaddedFP(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 bool has_break_points_to_check = | 659 bool has_break_points_to_check = |
660 break_points_active_ && location->HasBreakPoint(); | 660 break_points_active_ && location->HasBreakPoint(); |
661 if (has_break_points) *has_break_points = has_break_points_to_check; | 661 if (has_break_points) *has_break_points = has_break_points_to_check; |
662 if (!has_break_points_to_check) return factory->undefined_value(); | 662 if (!has_break_points_to_check) return factory->undefined_value(); |
663 | 663 |
664 Handle<Object> break_point_objects = location->BreakPointObjects(); | 664 Handle<Object> break_point_objects = location->BreakPointObjects(); |
665 // Count the number of break points hit. If there are multiple break points | 665 // Count the number of break points hit. If there are multiple break points |
666 // they are in a FixedArray. | 666 // they are in a FixedArray. |
667 Handle<FixedArray> break_points_hit; | 667 Handle<FixedArray> break_points_hit; |
668 int break_points_hit_count = 0; | 668 int break_points_hit_count = 0; |
669 DCHECK(!break_point_objects->IsUndefined()); | 669 DCHECK(!break_point_objects->IsUndefined(isolate_)); |
670 if (break_point_objects->IsFixedArray()) { | 670 if (break_point_objects->IsFixedArray()) { |
671 Handle<FixedArray> array(FixedArray::cast(*break_point_objects)); | 671 Handle<FixedArray> array(FixedArray::cast(*break_point_objects)); |
672 break_points_hit = factory->NewFixedArray(array->length()); | 672 break_points_hit = factory->NewFixedArray(array->length()); |
673 for (int i = 0; i < array->length(); i++) { | 673 for (int i = 0; i < array->length(); i++) { |
674 Handle<Object> break_point_object(array->get(i), isolate_); | 674 Handle<Object> break_point_object(array->get(i), isolate_); |
675 if (CheckBreakPoint(break_point_object)) { | 675 if (CheckBreakPoint(break_point_object)) { |
676 break_points_hit->set(break_points_hit_count++, *break_point_object); | 676 break_points_hit->set(break_points_hit_count++, *break_point_object); |
677 } | 677 } |
678 } | 678 } |
679 } else { | 679 } else { |
(...skipping 27 matching lines...) Expand all Loading... |
707 BreakLocation current_position = BreakLocation::FromFrame(debug_info, frame); | 707 BreakLocation current_position = BreakLocation::FromFrame(debug_info, frame); |
708 List<BreakLocation> break_locations; | 708 List<BreakLocation> break_locations; |
709 BreakLocation::AllForStatementPosition( | 709 BreakLocation::AllForStatementPosition( |
710 debug_info, current_position.statement_position(), &break_locations); | 710 debug_info, current_position.statement_position(), &break_locations); |
711 bool has_break_points_at_all = false; | 711 bool has_break_points_at_all = false; |
712 for (int i = 0; i < break_locations.length(); i++) { | 712 for (int i = 0; i < break_locations.length(); i++) { |
713 bool has_break_points; | 713 bool has_break_points; |
714 Handle<Object> check_result = | 714 Handle<Object> check_result = |
715 CheckBreakPoints(&break_locations[i], &has_break_points); | 715 CheckBreakPoints(&break_locations[i], &has_break_points); |
716 has_break_points_at_all |= has_break_points; | 716 has_break_points_at_all |= has_break_points; |
717 if (has_break_points && !check_result->IsUndefined()) return false; | 717 if (has_break_points && !check_result->IsUndefined(isolate_)) return false; |
718 } | 718 } |
719 return has_break_points_at_all; | 719 return has_break_points_at_all; |
720 } | 720 } |
721 | 721 |
722 | 722 |
723 MaybeHandle<Object> Debug::CallFunction(const char* name, int argc, | 723 MaybeHandle<Object> Debug::CallFunction(const char* name, int argc, |
724 Handle<Object> args[]) { | 724 Handle<Object> args[]) { |
725 PostponeInterruptsScope no_interrupts(isolate_); | 725 PostponeInterruptsScope no_interrupts(isolate_); |
726 AssertDebugContext(); | 726 AssertDebugContext(); |
727 Handle<JSReceiver> holder = | 727 Handle<JSReceiver> holder = |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 | 788 |
789 bool Debug::SetBreakPointForScript(Handle<Script> script, | 789 bool Debug::SetBreakPointForScript(Handle<Script> script, |
790 Handle<Object> break_point_object, | 790 Handle<Object> break_point_object, |
791 int* source_position, | 791 int* source_position, |
792 BreakPositionAlignment alignment) { | 792 BreakPositionAlignment alignment) { |
793 HandleScope scope(isolate_); | 793 HandleScope scope(isolate_); |
794 | 794 |
795 // Obtain shared function info for the function. | 795 // Obtain shared function info for the function. |
796 Handle<Object> result = | 796 Handle<Object> result = |
797 FindSharedFunctionInfoInScript(script, *source_position); | 797 FindSharedFunctionInfoInScript(script, *source_position); |
798 if (result->IsUndefined()) return false; | 798 if (result->IsUndefined(isolate_)) return false; |
799 | 799 |
800 // Make sure the function has set up the debug info. | 800 // Make sure the function has set up the debug info. |
801 Handle<SharedFunctionInfo> shared = Handle<SharedFunctionInfo>::cast(result); | 801 Handle<SharedFunctionInfo> shared = Handle<SharedFunctionInfo>::cast(result); |
802 if (!EnsureDebugInfo(shared, Handle<JSFunction>::null())) { | 802 if (!EnsureDebugInfo(shared, Handle<JSFunction>::null())) { |
803 // Return if retrieving debug info failed. | 803 // Return if retrieving debug info failed. |
804 return false; | 804 return false; |
805 } | 805 } |
806 | 806 |
807 // Find position within function. The script position might be before the | 807 // Find position within function. The script position might be before the |
808 // source position of the first function. | 808 // source position of the first function. |
(...skipping 26 matching lines...) Expand all Loading... |
835 } | 835 } |
836 | 836 |
837 | 837 |
838 void Debug::ClearBreakPoint(Handle<Object> break_point_object) { | 838 void Debug::ClearBreakPoint(Handle<Object> break_point_object) { |
839 HandleScope scope(isolate_); | 839 HandleScope scope(isolate_); |
840 | 840 |
841 DebugInfoListNode* node = debug_info_list_; | 841 DebugInfoListNode* node = debug_info_list_; |
842 while (node != NULL) { | 842 while (node != NULL) { |
843 Handle<Object> result = | 843 Handle<Object> result = |
844 DebugInfo::FindBreakPointInfo(node->debug_info(), break_point_object); | 844 DebugInfo::FindBreakPointInfo(node->debug_info(), break_point_object); |
845 if (!result->IsUndefined()) { | 845 if (!result->IsUndefined(isolate_)) { |
846 // Get information in the break point. | 846 // Get information in the break point. |
847 Handle<BreakPointInfo> break_point_info = | 847 Handle<BreakPointInfo> break_point_info = |
848 Handle<BreakPointInfo>::cast(result); | 848 Handle<BreakPointInfo>::cast(result); |
849 Handle<DebugInfo> debug_info = node->debug_info(); | 849 Handle<DebugInfo> debug_info = node->debug_info(); |
850 | 850 |
851 BreakLocation location = BreakLocation::FromCodeOffset( | 851 BreakLocation location = BreakLocation::FromCodeOffset( |
852 debug_info, break_point_info->code_offset()); | 852 debug_info, break_point_info->code_offset()); |
853 location.ClearBreakPoint(break_point_object); | 853 location.ClearBreakPoint(break_point_object); |
854 | 854 |
855 // If there are no more break points left remove the debug info for this | 855 // If there are no more break points left remove the debug info for this |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 break; | 1085 break; |
1086 } | 1086 } |
1087 } | 1087 } |
1088 | 1088 |
1089 | 1089 |
1090 // Simple function for returning the source positions for active break points. | 1090 // Simple function for returning the source positions for active break points. |
1091 Handle<Object> Debug::GetSourceBreakLocations( | 1091 Handle<Object> Debug::GetSourceBreakLocations( |
1092 Handle<SharedFunctionInfo> shared, | 1092 Handle<SharedFunctionInfo> shared, |
1093 BreakPositionAlignment position_alignment) { | 1093 BreakPositionAlignment position_alignment) { |
1094 Isolate* isolate = shared->GetIsolate(); | 1094 Isolate* isolate = shared->GetIsolate(); |
1095 Heap* heap = isolate->heap(); | |
1096 if (!shared->HasDebugInfo()) { | 1095 if (!shared->HasDebugInfo()) { |
1097 return Handle<Object>(heap->undefined_value(), isolate); | 1096 return isolate->factory()->undefined_value(); |
1098 } | 1097 } |
1099 Handle<DebugInfo> debug_info(shared->GetDebugInfo()); | 1098 Handle<DebugInfo> debug_info(shared->GetDebugInfo()); |
1100 if (debug_info->GetBreakPointCount() == 0) { | 1099 if (debug_info->GetBreakPointCount() == 0) { |
1101 return Handle<Object>(heap->undefined_value(), isolate); | 1100 return isolate->factory()->undefined_value(); |
1102 } | 1101 } |
1103 Handle<FixedArray> locations = | 1102 Handle<FixedArray> locations = |
1104 isolate->factory()->NewFixedArray(debug_info->GetBreakPointCount()); | 1103 isolate->factory()->NewFixedArray(debug_info->GetBreakPointCount()); |
1105 int count = 0; | 1104 int count = 0; |
1106 for (int i = 0; i < debug_info->break_points()->length(); ++i) { | 1105 for (int i = 0; i < debug_info->break_points()->length(); ++i) { |
1107 if (!debug_info->break_points()->get(i)->IsUndefined()) { | 1106 if (!debug_info->break_points()->get(i)->IsUndefined(isolate)) { |
1108 BreakPointInfo* break_point_info = | 1107 BreakPointInfo* break_point_info = |
1109 BreakPointInfo::cast(debug_info->break_points()->get(i)); | 1108 BreakPointInfo::cast(debug_info->break_points()->get(i)); |
1110 int break_points = break_point_info->GetBreakPointCount(); | 1109 int break_points = break_point_info->GetBreakPointCount(); |
1111 if (break_points == 0) continue; | 1110 if (break_points == 0) continue; |
1112 Smi* position = NULL; | 1111 Smi* position = NULL; |
1113 switch (position_alignment) { | 1112 switch (position_alignment) { |
1114 case STATEMENT_ALIGNED: | 1113 case STATEMENT_ALIGNED: |
1115 position = Smi::FromInt(break_point_info->statement_position()); | 1114 position = Smi::FromInt(break_point_info->statement_position()); |
1116 break; | 1115 break; |
1117 case BREAK_POSITION_ALIGNED: | 1116 case BREAK_POSITION_ALIGNED: |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1719 isolate_->thread_local_top()->scheduled_exception_ = *scheduled_exception; | 1718 isolate_->thread_local_top()->scheduled_exception_ = *scheduled_exception; |
1720 } | 1719 } |
1721 } | 1720 } |
1722 | 1721 |
1723 | 1722 |
1724 void Debug::OnPromiseReject(Handle<JSObject> promise, Handle<Object> value) { | 1723 void Debug::OnPromiseReject(Handle<JSObject> promise, Handle<Object> value) { |
1725 if (in_debug_scope() || ignore_events()) return; | 1724 if (in_debug_scope() || ignore_events()) return; |
1726 HandleScope scope(isolate_); | 1725 HandleScope scope(isolate_); |
1727 // Check whether the promise has been marked as having triggered a message. | 1726 // Check whether the promise has been marked as having triggered a message. |
1728 Handle<Symbol> key = isolate_->factory()->promise_debug_marker_symbol(); | 1727 Handle<Symbol> key = isolate_->factory()->promise_debug_marker_symbol(); |
1729 if (JSReceiver::GetDataProperty(promise, key)->IsUndefined()) { | 1728 if (JSReceiver::GetDataProperty(promise, key)->IsUndefined(isolate_)) { |
1730 OnException(value, promise); | 1729 OnException(value, promise); |
1731 } | 1730 } |
1732 } | 1731 } |
1733 | 1732 |
1734 | 1733 |
1735 MaybeHandle<Object> Debug::PromiseHasUserDefinedRejectHandler( | 1734 MaybeHandle<Object> Debug::PromiseHasUserDefinedRejectHandler( |
1736 Handle<JSObject> promise) { | 1735 Handle<JSObject> promise) { |
1737 Handle<JSFunction> fun = isolate_->promise_has_user_defined_reject_handler(); | 1736 Handle<JSFunction> fun = isolate_->promise_has_user_defined_reject_handler(); |
1738 return Execution::Call(isolate_, fun, promise, 0, NULL); | 1737 return Execution::Call(isolate_, fun, promise, 0, NULL); |
1739 } | 1738 } |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2045 command_text).ToHandleChecked(); | 2044 command_text).ToHandleChecked(); |
2046 Handle<Object> request_args[] = { request_text }; | 2045 Handle<Object> request_args[] = { request_text }; |
2047 Handle<Object> answer_value; | 2046 Handle<Object> answer_value; |
2048 Handle<String> answer; | 2047 Handle<String> answer; |
2049 MaybeHandle<Object> maybe_exception; | 2048 MaybeHandle<Object> maybe_exception; |
2050 MaybeHandle<Object> maybe_result = | 2049 MaybeHandle<Object> maybe_result = |
2051 Execution::TryCall(isolate_, process_debug_request, cmd_processor, 1, | 2050 Execution::TryCall(isolate_, process_debug_request, cmd_processor, 1, |
2052 request_args, &maybe_exception); | 2051 request_args, &maybe_exception); |
2053 | 2052 |
2054 if (maybe_result.ToHandle(&answer_value)) { | 2053 if (maybe_result.ToHandle(&answer_value)) { |
2055 if (answer_value->IsUndefined()) { | 2054 if (answer_value->IsUndefined(isolate_)) { |
2056 answer = isolate_->factory()->empty_string(); | 2055 answer = isolate_->factory()->empty_string(); |
2057 } else { | 2056 } else { |
2058 answer = Handle<String>::cast(answer_value); | 2057 answer = Handle<String>::cast(answer_value); |
2059 } | 2058 } |
2060 | 2059 |
2061 // Log the JSON request/response. | 2060 // Log the JSON request/response. |
2062 if (FLAG_trace_debug_json) { | 2061 if (FLAG_trace_debug_json) { |
2063 PrintF("%s\n", request_text->ToCString().get()); | 2062 PrintF("%s\n", request_text->ToCString().get()); |
2064 PrintF("%s\n", answer->ToCString().get()); | 2063 PrintF("%s\n", answer->ToCString().get()); |
2065 } | 2064 } |
(...skipping 30 matching lines...) Expand all Loading... |
2096 Handle<Object> data) { | 2095 Handle<Object> data) { |
2097 GlobalHandles* global_handles = isolate_->global_handles(); | 2096 GlobalHandles* global_handles = isolate_->global_handles(); |
2098 | 2097 |
2099 // Remove existing entry. | 2098 // Remove existing entry. |
2100 GlobalHandles::Destroy(event_listener_.location()); | 2099 GlobalHandles::Destroy(event_listener_.location()); |
2101 event_listener_ = Handle<Object>(); | 2100 event_listener_ = Handle<Object>(); |
2102 GlobalHandles::Destroy(event_listener_data_.location()); | 2101 GlobalHandles::Destroy(event_listener_data_.location()); |
2103 event_listener_data_ = Handle<Object>(); | 2102 event_listener_data_ = Handle<Object>(); |
2104 | 2103 |
2105 // Set new entry. | 2104 // Set new entry. |
2106 if (!callback->IsUndefined() && !callback->IsNull()) { | 2105 if (!callback->IsUndefined(isolate_) && !callback->IsNull()) { |
2107 event_listener_ = global_handles->Create(*callback); | 2106 event_listener_ = global_handles->Create(*callback); |
2108 if (data.is_null()) data = isolate_->factory()->undefined_value(); | 2107 if (data.is_null()) data = isolate_->factory()->undefined_value(); |
2109 event_listener_data_ = global_handles->Create(*data); | 2108 event_listener_data_ = global_handles->Create(*data); |
2110 } | 2109 } |
2111 | 2110 |
2112 UpdateState(); | 2111 UpdateState(); |
2113 } | 2112 } |
2114 | 2113 |
2115 | 2114 |
2116 void Debug::SetMessageHandler(v8::Debug::MessageHandler handler) { | 2115 void Debug::SetMessageHandler(v8::Debug::MessageHandler handler) { |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2587 } | 2586 } |
2588 | 2587 |
2589 | 2588 |
2590 void LockingCommandMessageQueue::Clear() { | 2589 void LockingCommandMessageQueue::Clear() { |
2591 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 2590 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
2592 queue_.Clear(); | 2591 queue_.Clear(); |
2593 } | 2592 } |
2594 | 2593 |
2595 } // namespace internal | 2594 } // namespace internal |
2596 } // namespace v8 | 2595 } // namespace v8 |
OLD | NEW |