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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1097 return Handle<Object>(heap->undefined_value(), isolate); | 1097 return Handle<Object>(heap->undefined_value(), isolate); |
1098 } | 1098 } |
1099 Handle<DebugInfo> debug_info(shared->GetDebugInfo()); | 1099 Handle<DebugInfo> debug_info(shared->GetDebugInfo()); |
1100 if (debug_info->GetBreakPointCount() == 0) { | 1100 if (debug_info->GetBreakPointCount() == 0) { |
1101 return Handle<Object>(heap->undefined_value(), isolate); | 1101 return Handle<Object>(heap->undefined_value(), isolate); |
1102 } | 1102 } |
1103 Handle<FixedArray> locations = | 1103 Handle<FixedArray> locations = |
1104 isolate->factory()->NewFixedArray(debug_info->GetBreakPointCount()); | 1104 isolate->factory()->NewFixedArray(debug_info->GetBreakPointCount()); |
1105 int count = 0; | 1105 int count = 0; |
1106 for (int i = 0; i < debug_info->break_points()->length(); ++i) { | 1106 for (int i = 0; i < debug_info->break_points()->length(); ++i) { |
1107 if (!debug_info->break_points()->get(i)->IsUndefined()) { | 1107 if (!debug_info->break_points()->get(i)->IsUndefined(isolate)) { |
1108 BreakPointInfo* break_point_info = | 1108 BreakPointInfo* break_point_info = |
1109 BreakPointInfo::cast(debug_info->break_points()->get(i)); | 1109 BreakPointInfo::cast(debug_info->break_points()->get(i)); |
1110 int break_points = break_point_info->GetBreakPointCount(); | 1110 int break_points = break_point_info->GetBreakPointCount(); |
1111 if (break_points == 0) continue; | 1111 if (break_points == 0) continue; |
1112 Smi* position = NULL; | 1112 Smi* position = NULL; |
1113 switch (position_alignment) { | 1113 switch (position_alignment) { |
1114 case STATEMENT_ALIGNED: | 1114 case STATEMENT_ALIGNED: |
1115 position = Smi::FromInt(break_point_info->statement_position()); | 1115 position = Smi::FromInt(break_point_info->statement_position()); |
1116 break; | 1116 break; |
1117 case BREAK_POSITION_ALIGNED: | 1117 case BREAK_POSITION_ALIGNED: |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1717 isolate_->thread_local_top()->scheduled_exception_ = *scheduled_exception; | 1717 isolate_->thread_local_top()->scheduled_exception_ = *scheduled_exception; |
1718 } | 1718 } |
1719 } | 1719 } |
1720 | 1720 |
1721 | 1721 |
1722 void Debug::OnPromiseReject(Handle<JSObject> promise, Handle<Object> value) { | 1722 void Debug::OnPromiseReject(Handle<JSObject> promise, Handle<Object> value) { |
1723 if (in_debug_scope() || ignore_events()) return; | 1723 if (in_debug_scope() || ignore_events()) return; |
1724 HandleScope scope(isolate_); | 1724 HandleScope scope(isolate_); |
1725 // Check whether the promise has been marked as having triggered a message. | 1725 // Check whether the promise has been marked as having triggered a message. |
1726 Handle<Symbol> key = isolate_->factory()->promise_debug_marker_symbol(); | 1726 Handle<Symbol> key = isolate_->factory()->promise_debug_marker_symbol(); |
1727 if (JSReceiver::GetDataProperty(promise, key)->IsUndefined()) { | 1727 if (JSReceiver::GetDataProperty(promise, key)->IsUndefined(isolate_)) { |
1728 OnException(value, promise); | 1728 OnException(value, promise); |
1729 } | 1729 } |
1730 } | 1730 } |
1731 | 1731 |
1732 | 1732 |
1733 MaybeHandle<Object> Debug::PromiseHasUserDefinedRejectHandler( | 1733 MaybeHandle<Object> Debug::PromiseHasUserDefinedRejectHandler( |
1734 Handle<JSObject> promise) { | 1734 Handle<JSObject> promise) { |
1735 Handle<JSFunction> fun = isolate_->promise_has_user_defined_reject_handler(); | 1735 Handle<JSFunction> fun = isolate_->promise_has_user_defined_reject_handler(); |
1736 return Execution::Call(isolate_, fun, promise, 0, NULL); | 1736 return Execution::Call(isolate_, fun, promise, 0, NULL); |
1737 } | 1737 } |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2043 command_text).ToHandleChecked(); | 2043 command_text).ToHandleChecked(); |
2044 Handle<Object> request_args[] = { request_text }; | 2044 Handle<Object> request_args[] = { request_text }; |
2045 Handle<Object> answer_value; | 2045 Handle<Object> answer_value; |
2046 Handle<String> answer; | 2046 Handle<String> answer; |
2047 MaybeHandle<Object> maybe_exception; | 2047 MaybeHandle<Object> maybe_exception; |
2048 MaybeHandle<Object> maybe_result = | 2048 MaybeHandle<Object> maybe_result = |
2049 Execution::TryCall(isolate_, process_debug_request, cmd_processor, 1, | 2049 Execution::TryCall(isolate_, process_debug_request, cmd_processor, 1, |
2050 request_args, &maybe_exception); | 2050 request_args, &maybe_exception); |
2051 | 2051 |
2052 if (maybe_result.ToHandle(&answer_value)) { | 2052 if (maybe_result.ToHandle(&answer_value)) { |
2053 if (answer_value->IsUndefined()) { | 2053 if (answer_value->IsUndefined(isolate_)) { |
2054 answer = isolate_->factory()->empty_string(); | 2054 answer = isolate_->factory()->empty_string(); |
2055 } else { | 2055 } else { |
2056 answer = Handle<String>::cast(answer_value); | 2056 answer = Handle<String>::cast(answer_value); |
2057 } | 2057 } |
2058 | 2058 |
2059 // Log the JSON request/response. | 2059 // Log the JSON request/response. |
2060 if (FLAG_trace_debug_json) { | 2060 if (FLAG_trace_debug_json) { |
2061 PrintF("%s\n", request_text->ToCString().get()); | 2061 PrintF("%s\n", request_text->ToCString().get()); |
2062 PrintF("%s\n", answer->ToCString().get()); | 2062 PrintF("%s\n", answer->ToCString().get()); |
2063 } | 2063 } |
(...skipping 30 matching lines...) Expand all Loading... | |
2094 Handle<Object> data) { | 2094 Handle<Object> data) { |
2095 GlobalHandles* global_handles = isolate_->global_handles(); | 2095 GlobalHandles* global_handles = isolate_->global_handles(); |
2096 | 2096 |
2097 // Remove existing entry. | 2097 // Remove existing entry. |
2098 GlobalHandles::Destroy(event_listener_.location()); | 2098 GlobalHandles::Destroy(event_listener_.location()); |
2099 event_listener_ = Handle<Object>(); | 2099 event_listener_ = Handle<Object>(); |
2100 GlobalHandles::Destroy(event_listener_data_.location()); | 2100 GlobalHandles::Destroy(event_listener_data_.location()); |
2101 event_listener_data_ = Handle<Object>(); | 2101 event_listener_data_ = Handle<Object>(); |
2102 | 2102 |
2103 // Set new entry. | 2103 // Set new entry. |
2104 if (!callback->IsUndefined() && !callback->IsNull()) { | 2104 if (!callback->IsUndefined(isolate_) && !callback->IsNull()) { |
Yang
2016/06/01 12:46:02
What about IsNull(Isolate*) :P
Camillo Bruni
2016/06/02 11:48:35
It's on my TODO :)
| |
2105 event_listener_ = global_handles->Create(*callback); | 2105 event_listener_ = global_handles->Create(*callback); |
2106 if (data.is_null()) data = isolate_->factory()->undefined_value(); | 2106 if (data.is_null()) data = isolate_->factory()->undefined_value(); |
2107 event_listener_data_ = global_handles->Create(*data); | 2107 event_listener_data_ = global_handles->Create(*data); |
2108 } | 2108 } |
2109 | 2109 |
2110 UpdateState(); | 2110 UpdateState(); |
2111 } | 2111 } |
2112 | 2112 |
2113 | 2113 |
2114 void Debug::SetMessageHandler(v8::Debug::MessageHandler handler) { | 2114 void Debug::SetMessageHandler(v8::Debug::MessageHandler handler) { |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2585 } | 2585 } |
2586 | 2586 |
2587 | 2587 |
2588 void LockingCommandMessageQueue::Clear() { | 2588 void LockingCommandMessageQueue::Clear() { |
2589 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 2589 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
2590 queue_.Clear(); | 2590 queue_.Clear(); |
2591 } | 2591 } |
2592 | 2592 |
2593 } // namespace internal | 2593 } // namespace internal |
2594 } // namespace v8 | 2594 } // namespace v8 |
OLD | NEW |