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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 | 470 |
471 // Threading support. | 471 // Threading support. |
472 void Debug::ThreadInit() { | 472 void Debug::ThreadInit() { |
473 thread_local_.break_count_ = 0; | 473 thread_local_.break_count_ = 0; |
474 thread_local_.break_id_ = 0; | 474 thread_local_.break_id_ = 0; |
475 thread_local_.break_frame_id_ = StackFrame::NO_ID; | 475 thread_local_.break_frame_id_ = StackFrame::NO_ID; |
476 thread_local_.last_step_action_ = StepNone; | 476 thread_local_.last_step_action_ = StepNone; |
477 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; | 477 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; |
478 thread_local_.last_fp_ = 0; | 478 thread_local_.last_fp_ = 0; |
479 thread_local_.target_fp_ = 0; | 479 thread_local_.target_fp_ = 0; |
480 thread_local_.step_in_enabled_ = false; | |
481 thread_local_.return_value_ = Handle<Object>(); | 480 thread_local_.return_value_ = Handle<Object>(); |
482 clear_suspended_generator(); | 481 clear_suspended_generator(); |
483 // TODO(isolates): frames_are_dropped_? | 482 // TODO(isolates): frames_are_dropped_? |
484 base::NoBarrier_Store(&thread_local_.current_debug_scope_, | 483 base::NoBarrier_Store(&thread_local_.current_debug_scope_, |
485 static_cast<base::AtomicWord>(0)); | 484 static_cast<base::AtomicWord>(0)); |
486 } | 485 } |
487 | 486 |
488 | 487 |
489 char* Debug::ArchiveDebug(char* storage) { | 488 char* Debug::ArchiveDebug(char* storage) { |
490 // Simply reset state. Don't archive anything. | 489 // Simply reset state. Don't archive anything. |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 bool Debug::IsBreakOnException(ExceptionBreakType type) { | 924 bool Debug::IsBreakOnException(ExceptionBreakType type) { |
926 if (type == BreakUncaughtException) { | 925 if (type == BreakUncaughtException) { |
927 return break_on_uncaught_exception_; | 926 return break_on_uncaught_exception_; |
928 } else { | 927 } else { |
929 return break_on_exception_; | 928 return break_on_exception_; |
930 } | 929 } |
931 } | 930 } |
932 | 931 |
933 | 932 |
934 void Debug::PrepareStepIn(Handle<JSFunction> function) { | 933 void Debug::PrepareStepIn(Handle<JSFunction> function) { |
| 934 CHECK(last_step_action() >= StepIn); |
935 if (!is_active()) return; | 935 if (!is_active()) return; |
936 if (last_step_action() < StepIn) return; | |
937 if (in_debug_scope()) return; | 936 if (in_debug_scope()) return; |
938 if (thread_local_.step_in_enabled_) { | 937 FloodWithOneShot(function); |
939 FloodWithOneShot(function); | |
940 } | |
941 } | 938 } |
942 | 939 |
943 void Debug::PrepareStepInSuspendedGenerator() { | 940 void Debug::PrepareStepInSuspendedGenerator() { |
| 941 CHECK(has_suspended_generator()); |
944 if (!is_active()) return; | 942 if (!is_active()) return; |
945 if (in_debug_scope()) return; | 943 if (in_debug_scope()) return; |
946 DCHECK(has_suspended_generator()); | |
947 thread_local_.last_step_action_ = StepIn; | 944 thread_local_.last_step_action_ = StepIn; |
948 thread_local_.step_in_enabled_ = true; | |
949 Handle<JSFunction> function( | 945 Handle<JSFunction> function( |
950 JSGeneratorObject::cast(thread_local_.suspended_generator_)->function()); | 946 JSGeneratorObject::cast(thread_local_.suspended_generator_)->function()); |
951 FloodWithOneShot(function); | 947 FloodWithOneShot(function); |
952 clear_suspended_generator(); | 948 clear_suspended_generator(); |
953 } | 949 } |
954 | 950 |
955 void Debug::PrepareStepOnThrow() { | 951 void Debug::PrepareStepOnThrow() { |
956 if (!is_active()) return; | 952 if (!is_active()) return; |
957 if (last_step_action() == StepNone) return; | 953 if (last_step_action() == StepNone) return; |
958 if (in_debug_scope()) return; | 954 if (in_debug_scope()) return; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 // debug frame is not present. | 994 // debug frame is not present. |
999 StackFrame::Id frame_id = break_frame_id(); | 995 StackFrame::Id frame_id = break_frame_id(); |
1000 // If there is no JavaScript stack don't do anything. | 996 // If there is no JavaScript stack don't do anything. |
1001 if (frame_id == StackFrame::NO_ID) return; | 997 if (frame_id == StackFrame::NO_ID) return; |
1002 | 998 |
1003 JavaScriptFrameIterator frames_it(isolate_, frame_id); | 999 JavaScriptFrameIterator frames_it(isolate_, frame_id); |
1004 JavaScriptFrame* frame = frames_it.frame(); | 1000 JavaScriptFrame* frame = frames_it.frame(); |
1005 | 1001 |
1006 feature_tracker()->Track(DebugFeatureTracker::kStepping); | 1002 feature_tracker()->Track(DebugFeatureTracker::kStepping); |
1007 | 1003 |
1008 // Remember this step action and count. | |
1009 thread_local_.last_step_action_ = step_action; | 1004 thread_local_.last_step_action_ = step_action; |
1010 STATIC_ASSERT(StepFrame > StepIn); | |
1011 thread_local_.step_in_enabled_ = (step_action >= StepIn); | |
1012 | 1005 |
1013 // If the function on the top frame is unresolved perform step out. This will | 1006 // If the function on the top frame is unresolved perform step out. This will |
1014 // be the case when calling unknown function and having the debugger stopped | 1007 // be the case when calling unknown function and having the debugger stopped |
1015 // in an unhandled exception. | 1008 // in an unhandled exception. |
1016 if (!frame->function()->IsJSFunction()) { | 1009 if (!frame->function()->IsJSFunction()) { |
1017 // Step out: Find the calling JavaScript frame and flood it with | 1010 // Step out: Find the calling JavaScript frame and flood it with |
1018 // breakpoints. | 1011 // breakpoints. |
1019 frames_it.Advance(); | 1012 frames_it.Advance(); |
1020 // Fill the function to return to with one-shot break points. | 1013 // Fill the function to return to with one-shot break points. |
1021 JSFunction* function = frames_it.frame()->function(); | 1014 JSFunction* function = frames_it.frame()->function(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 // Advance to caller frame. | 1056 // Advance to caller frame. |
1064 frames_it.Advance(); | 1057 frames_it.Advance(); |
1065 // Skip native and extension functions on the stack. | 1058 // Skip native and extension functions on the stack. |
1066 while (!frames_it.done() && | 1059 while (!frames_it.done() && |
1067 !frames_it.frame()->function()->shared()->IsSubjectToDebugging()) { | 1060 !frames_it.frame()->function()->shared()->IsSubjectToDebugging()) { |
1068 // Builtin functions are not subject to stepping, but need to be | 1061 // Builtin functions are not subject to stepping, but need to be |
1069 // deoptimized to include checks for step-in at call sites. | 1062 // deoptimized to include checks for step-in at call sites. |
1070 Deoptimizer::DeoptimizeFunction(frames_it.frame()->function()); | 1063 Deoptimizer::DeoptimizeFunction(frames_it.frame()->function()); |
1071 frames_it.Advance(); | 1064 frames_it.Advance(); |
1072 } | 1065 } |
1073 if (frames_it.done()) { | 1066 if (!frames_it.done()) { |
1074 // Stepping out to the embedder. Disable step-in to avoid stepping into | |
1075 // the next (unrelated) call that the embedder makes. | |
1076 thread_local_.step_in_enabled_ = false; | |
1077 } else { | |
1078 // Fill the caller function to return to with one-shot break points. | 1067 // Fill the caller function to return to with one-shot break points. |
1079 Handle<JSFunction> caller_function(frames_it.frame()->function()); | 1068 Handle<JSFunction> caller_function(frames_it.frame()->function()); |
1080 FloodWithOneShot(caller_function); | 1069 FloodWithOneShot(caller_function); |
1081 thread_local_.target_fp_ = frames_it.frame()->UnpaddedFP(); | 1070 thread_local_.target_fp_ = frames_it.frame()->UnpaddedFP(); |
1082 } | 1071 } |
1083 // Clear last position info. For stepping out it does not matter. | 1072 // Clear last position info. For stepping out it does not matter. |
1084 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; | 1073 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; |
1085 thread_local_.last_fp_ = 0; | 1074 thread_local_.last_fp_ = 0; |
1086 break; | 1075 break; |
1087 case StepNext: | 1076 case StepNext: |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 } | 1124 } |
1136 return locations; | 1125 return locations; |
1137 } | 1126 } |
1138 | 1127 |
1139 | 1128 |
1140 void Debug::ClearStepping() { | 1129 void Debug::ClearStepping() { |
1141 // Clear the various stepping setup. | 1130 // Clear the various stepping setup. |
1142 ClearOneShot(); | 1131 ClearOneShot(); |
1143 | 1132 |
1144 thread_local_.last_step_action_ = StepNone; | 1133 thread_local_.last_step_action_ = StepNone; |
1145 thread_local_.step_in_enabled_ = false; | |
1146 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; | 1134 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; |
1147 thread_local_.last_fp_ = 0; | 1135 thread_local_.last_fp_ = 0; |
1148 thread_local_.target_fp_ = 0; | 1136 thread_local_.target_fp_ = 0; |
1149 } | 1137 } |
1150 | 1138 |
1151 | 1139 |
1152 // Clears all the one-shot break points that are currently set. Normally this | 1140 // Clears all the one-shot break points that are currently set. Normally this |
1153 // function is called each time a break point is hit as one shot break points | 1141 // function is called each time a break point is hit as one shot break points |
1154 // are used to support stepping. | 1142 // are used to support stepping. |
1155 void Debug::ClearOneShot() { | 1143 void Debug::ClearOneShot() { |
1156 // The current implementation just runs through all the breakpoints. When the | 1144 // The current implementation just runs through all the breakpoints. When the |
1157 // last break point for a function is removed that function is automatically | 1145 // last break point for a function is removed that function is automatically |
1158 // removed from the list. | 1146 // removed from the list. |
1159 for (DebugInfoListNode* node = debug_info_list_; node != NULL; | 1147 for (DebugInfoListNode* node = debug_info_list_; node != NULL; |
1160 node = node->next()) { | 1148 node = node->next()) { |
1161 for (base::SmartPointer<BreakLocation::Iterator> it( | 1149 for (base::SmartPointer<BreakLocation::Iterator> it( |
1162 BreakLocation::GetIterator(node->debug_info())); | 1150 BreakLocation::GetIterator(node->debug_info())); |
1163 !it->Done(); it->Next()) { | 1151 !it->Done(); it->Next()) { |
1164 it->GetBreakLocation().ClearOneShot(); | 1152 it->GetBreakLocation().ClearOneShot(); |
1165 } | 1153 } |
1166 } | 1154 } |
1167 } | 1155 } |
1168 | 1156 |
1169 | 1157 |
1170 void Debug::EnableStepIn() { | |
1171 STATIC_ASSERT(StepFrame > StepIn); | |
1172 thread_local_.step_in_enabled_ = (last_step_action() >= StepIn); | |
1173 } | |
1174 | |
1175 | |
1176 bool MatchingCodeTargets(Code* target1, Code* target2) { | 1158 bool MatchingCodeTargets(Code* target1, Code* target2) { |
1177 if (target1 == target2) return true; | 1159 if (target1 == target2) return true; |
1178 if (target1->kind() != target2->kind()) return false; | 1160 if (target1->kind() != target2->kind()) return false; |
1179 return target1->is_handler() || target1->is_inline_cache_stub(); | 1161 return target1->is_handler() || target1->is_inline_cache_stub(); |
1180 } | 1162 } |
1181 | 1163 |
1182 | 1164 |
1183 // Count the number of calls before the current frame PC to find the | 1165 // Count the number of calls before the current frame PC to find the |
1184 // corresponding PC in the newly recompiled code. | 1166 // corresponding PC in the newly recompiled code. |
1185 static Address ComputeNewPcForRedirect(Code* new_code, Code* old_code, | 1167 static Address ComputeNewPcForRedirect(Code* new_code, Code* old_code, |
(...skipping 1424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2610 } | 2592 } |
2611 | 2593 |
2612 | 2594 |
2613 void LockingCommandMessageQueue::Clear() { | 2595 void LockingCommandMessageQueue::Clear() { |
2614 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 2596 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
2615 queue_.Clear(); | 2597 queue_.Clear(); |
2616 } | 2598 } |
2617 | 2599 |
2618 } // namespace internal | 2600 } // namespace internal |
2619 } // namespace v8 | 2601 } // namespace v8 |
OLD | NEW |