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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
975 DCHECK(in_debug_scope()); | 975 DCHECK(in_debug_scope()); |
976 | 976 |
977 // Get the frame where the execution has stopped and skip the debug frame if | 977 // Get the frame where the execution has stopped and skip the debug frame if |
978 // any. The debug frame will only be present if execution was stopped due to | 978 // any. The debug frame will only be present if execution was stopped due to |
979 // hitting a break point. In other situations (e.g. unhandled exception) the | 979 // hitting a break point. In other situations (e.g. unhandled exception) the |
980 // debug frame is not present. | 980 // debug frame is not present. |
981 StackFrame::Id frame_id = break_frame_id(); | 981 StackFrame::Id frame_id = break_frame_id(); |
982 // If there is no JavaScript stack don't do anything. | 982 // If there is no JavaScript stack don't do anything. |
983 if (frame_id == StackFrame::NO_ID) return; | 983 if (frame_id == StackFrame::NO_ID) return; |
984 | 984 |
985 JavaScriptFrameIterator frames_it(isolate_, frame_id); | 985 StackTraceFrameIterator frames_it(isolate_, frame_id); |
986 JavaScriptFrame* frame = frames_it.frame(); | 986 StandardFrame* frame = frames_it.frame(); |
987 | 987 |
988 feature_tracker()->Track(DebugFeatureTracker::kStepping); | 988 feature_tracker()->Track(DebugFeatureTracker::kStepping); |
989 | 989 |
990 thread_local_.last_step_action_ = step_action; | 990 thread_local_.last_step_action_ = step_action; |
991 UpdateHookOnFunctionCall(); | 991 UpdateHookOnFunctionCall(); |
992 | 992 |
993 // Handle stepping in wasm functions via the wasm interpreter. | |
994 if (frame->is_wasm()) { | |
995 // If the top frame is compiled, we cannot step. | |
996 if (frame->is_wasm_compiled()) return; | |
997 WasmInterpreterEntryFrame* wasm_frame = | |
998 WasmInterpreterEntryFrame::cast(frame); | |
999 wasm_frame->wasm_instance()->debug_info()->PrepareStep(step_action); | |
1000 return; | |
1001 } | |
1002 | |
1003 JavaScriptFrame* js_frame = JavaScriptFrame::cast(frame); | |
1004 | |
993 // If the function on the top frame is unresolved perform step out. This will | 1005 // If the function on the top frame is unresolved perform step out. This will |
994 // be the case when calling unknown function and having the debugger stopped | 1006 // be the case when calling unknown function and having the debugger stopped |
995 // in an unhandled exception. | 1007 // in an unhandled exception. |
996 if (!frame->function()->IsJSFunction()) { | 1008 if (!js_frame->function()->IsJSFunction()) { |
997 // Step out: Find the calling JavaScript frame and flood it with | 1009 // Step out: Find the calling JavaScript frame and flood it with |
998 // breakpoints. | 1010 // breakpoints. |
999 frames_it.Advance(); | 1011 frames_it.Advance(); |
1000 // Fill the function to return to with one-shot break points. | 1012 // Fill the function to return to with one-shot break points. |
1001 JSFunction* function = frames_it.frame()->function(); | 1013 JSFunction* function = JavaScriptFrame::cast(frames_it.frame())->function(); |
1002 FloodWithOneShot(Handle<JSFunction>(function)); | 1014 FloodWithOneShot(handle(function, isolate_)); |
1003 return; | 1015 return; |
1004 } | 1016 } |
1005 | 1017 |
1006 // Get the debug info (create it if it does not exist). | 1018 // Get the debug info (create it if it does not exist). |
1007 auto summary = FrameSummary::GetTop(frame).AsJavaScript(); | 1019 auto summary = FrameSummary::GetTop(frame).AsJavaScript(); |
1008 Handle<JSFunction> function(summary.function()); | 1020 Handle<JSFunction> function(summary.function()); |
1009 Handle<SharedFunctionInfo> shared(function->shared()); | 1021 Handle<SharedFunctionInfo> shared(function->shared()); |
1010 if (!EnsureDebugInfo(shared, function)) { | 1022 if (!EnsureDebugInfo(shared, function)) { |
1011 // Return if ensuring debug info failed. | 1023 // Return if ensuring debug info failed. |
1012 return; | 1024 return; |
1013 } | 1025 } |
1014 | 1026 |
1015 Handle<DebugInfo> debug_info(shared->GetDebugInfo()); | 1027 Handle<DebugInfo> debug_info(shared->GetDebugInfo()); |
1016 BreakLocation location = BreakLocation::FromFrame(debug_info, frame); | 1028 BreakLocation location = BreakLocation::FromFrame(debug_info, js_frame); |
1017 | 1029 |
1018 // Any step at a return is a step-out. | 1030 // Any step at a return is a step-out. |
1019 if (location.IsReturn()) step_action = StepOut; | 1031 if (location.IsReturn()) step_action = StepOut; |
1020 // A step-next at a tail call is a step-out. | 1032 // A step-next at a tail call is a step-out. |
1021 if (location.IsTailCall() && step_action == StepNext) step_action = StepOut; | 1033 if (location.IsTailCall() && step_action == StepNext) step_action = StepOut; |
1022 | 1034 |
1023 thread_local_.last_statement_position_ = | 1035 thread_local_.last_statement_position_ = |
1024 summary.abstract_code()->SourceStatementPosition(summary.code_offset()); | 1036 summary.abstract_code()->SourceStatementPosition(summary.code_offset()); |
1025 thread_local_.last_fp_ = frame->UnpaddedFP(); | 1037 thread_local_.last_fp_ = frame->UnpaddedFP(); |
1026 // No longer perform the current async step. | 1038 // No longer perform the current async step. |
1027 clear_suspended_generator(); | 1039 clear_suspended_generator(); |
1028 | 1040 |
1029 switch (step_action) { | 1041 switch (step_action) { |
1030 case StepNone: | 1042 case StepNone: |
1031 UNREACHABLE(); | 1043 UNREACHABLE(); |
1032 break; | 1044 break; |
1033 case StepOut: | 1045 case StepOut: |
1034 // Advance to caller frame. | 1046 // Advance to caller frame. |
1035 frames_it.Advance(); | 1047 frames_it.Advance(); |
1036 // Skip native and extension functions on the stack. | 1048 // Skip native and extension functions on the stack. |
1037 while (!frames_it.done() && | 1049 while (!frames_it.done()) { |
titzer
2017/01/23 18:30:45
As per previous comment, mind cleaning up this loo
Clemens Hammacher
2017/01/23 18:47:27
Done, but I'm not sure if it improves readability.
| |
1038 !frames_it.frame()->function()->shared()->IsSubjectToDebugging()) { | 1050 if (!frames_it.frame()->is_java_script()) break; |
1051 JavaScriptFrame* js_frame = JavaScriptFrame::cast(frames_it.frame()); | |
1052 if (js_frame->function()->shared()->IsSubjectToDebugging()) break; | |
1039 // Builtin functions are not subject to stepping, but need to be | 1053 // Builtin functions are not subject to stepping, but need to be |
1040 // deoptimized to include checks for step-in at call sites. | 1054 // deoptimized to include checks for step-in at call sites. |
1041 Deoptimizer::DeoptimizeFunction(frames_it.frame()->function()); | 1055 Deoptimizer::DeoptimizeFunction(js_frame->function()); |
1042 frames_it.Advance(); | 1056 frames_it.Advance(); |
1043 } | 1057 } |
1044 if (!frames_it.done()) { | 1058 if (!frames_it.done()) { |
1045 // Fill the caller function to return to with one-shot break points. | 1059 StandardFrame* caller_frame = frames_it.frame(); |
1046 Handle<JSFunction> caller_function(frames_it.frame()->function()); | 1060 if (caller_frame->is_wasm()) { |
1047 FloodWithOneShot(caller_function); | 1061 // TODO(clemensh): Implement stepping out from JS to WASM. |
1048 thread_local_.target_fp_ = frames_it.frame()->UnpaddedFP(); | 1062 } else { |
1063 JavaScriptFrame* js_caller_frame = | |
1064 JavaScriptFrame::cast(caller_frame); | |
1065 // Fill the caller function to return to with one-shot break points. | |
1066 Handle<JSFunction> caller_function(js_caller_frame->function()); | |
1067 FloodWithOneShot(caller_function); | |
1068 thread_local_.target_fp_ = frames_it.frame()->UnpaddedFP(); | |
1069 } | |
1049 } | 1070 } |
1050 // Clear last position info. For stepping out it does not matter. | 1071 // Clear last position info. For stepping out it does not matter. |
1051 thread_local_.last_statement_position_ = kNoSourcePosition; | 1072 thread_local_.last_statement_position_ = kNoSourcePosition; |
1052 thread_local_.last_fp_ = 0; | 1073 thread_local_.last_fp_ = 0; |
1053 break; | 1074 break; |
1054 case StepNext: | 1075 case StepNext: |
1055 thread_local_.target_fp_ = frame->UnpaddedFP(); | 1076 thread_local_.target_fp_ = frame->UnpaddedFP(); |
1056 FloodWithOneShot(function); | 1077 FloodWithOneShot(function); |
1057 break; | 1078 break; |
1058 case StepIn: | 1079 case StepIn: |
1080 // TODO(clemensh): Implement stepping from JS into WASM. | |
1059 FloodWithOneShot(function); | 1081 FloodWithOneShot(function); |
1060 break; | 1082 break; |
1061 case StepFrame: | 1083 case StepFrame: |
1084 // TODO(clemensh): Implement stepping from JS into WASM or vice versa. | |
Yang
2017/01/23 14:26:20
StepFrame will be removed soonish. Once Framework
| |
1062 // No point in setting one-shot breaks at places where we are not about | 1085 // No point in setting one-shot breaks at places where we are not about |
1063 // to leave the current frame. | 1086 // to leave the current frame. |
1064 FloodWithOneShot(function, CALLS_AND_RETURNS); | 1087 FloodWithOneShot(function, CALLS_AND_RETURNS); |
1065 break; | 1088 break; |
1066 } | 1089 } |
1067 } | 1090 } |
1068 | 1091 |
1069 // Simple function for returning the source positions for active break points. | 1092 // Simple function for returning the source positions for active break points. |
1070 Handle<Object> Debug::GetSourceBreakLocations( | 1093 Handle<Object> Debug::GetSourceBreakLocations( |
1071 Handle<SharedFunctionInfo> shared, | 1094 Handle<SharedFunctionInfo> shared, |
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2268 return v8::Utils::ToLocal(callback_data_); | 2291 return v8::Utils::ToLocal(callback_data_); |
2269 } | 2292 } |
2270 | 2293 |
2271 | 2294 |
2272 v8::Isolate* EventDetailsImpl::GetIsolate() const { | 2295 v8::Isolate* EventDetailsImpl::GetIsolate() const { |
2273 return reinterpret_cast<v8::Isolate*>(exec_state_->GetIsolate()); | 2296 return reinterpret_cast<v8::Isolate*>(exec_state_->GetIsolate()); |
2274 } | 2297 } |
2275 | 2298 |
2276 } // namespace internal | 2299 } // namespace internal |
2277 } // namespace v8 | 2300 } // namespace v8 |
OLD | NEW |