Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(487)

Side by Side Diff: src/debug/debug.cc

Issue 2068603002: [debugger] simplify debug stepping. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: remove declaration Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
935 if (!is_active()) return; 934 if (!is_active()) return;
936 if (last_step_action() < StepIn) return; 935 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() {
944 if (!is_active()) return; 941 if (!is_active()) return;
945 if (in_debug_scope()) return; 942 if (in_debug_scope()) return;
946 DCHECK(has_suspended_generator()); 943 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
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 14 matching lines...) Expand all
1036 // Refresh frame summary if the code has been recompiled for debugging. 1029 // Refresh frame summary if the code has been recompiled for debugging.
1037 if (AbstractCode::cast(shared->code()) != *summary.abstract_code()) { 1030 if (AbstractCode::cast(shared->code()) != *summary.abstract_code()) {
1038 summary = FrameSummary::GetFirst(frame); 1031 summary = FrameSummary::GetFirst(frame);
1039 } 1032 }
1040 1033
1041 int call_offset = 1034 int call_offset =
1042 CallOffsetFromCodeOffset(summary.code_offset(), frame->is_interpreted()); 1035 CallOffsetFromCodeOffset(summary.code_offset(), frame->is_interpreted());
1043 BreakLocation location = 1036 BreakLocation location =
1044 BreakLocation::FromCodeOffset(debug_info, call_offset); 1037 BreakLocation::FromCodeOffset(debug_info, call_offset);
1045 1038
1046 // Any step at a return is a step-out. 1039 // Any step at a return or a step-next at a tail call is a step-out.
1047 if (location.IsReturn()) step_action = StepOut; 1040 if (location.IsReturn() ||
1048 // A step-next at a tail call is a step-out. 1041 (location.IsTailCall() && thread_local_.last_step_action_ == StepNext)) {
1049 if (location.IsTailCall() && step_action == StepNext) step_action = StepOut; 1042 thread_local_.last_step_action_ = StepOut;
1043 }
1050 1044
1051 thread_local_.last_statement_position_ = 1045 thread_local_.last_statement_position_ =
1052 debug_info->abstract_code()->SourceStatementPosition( 1046 debug_info->abstract_code()->SourceStatementPosition(
1053 summary.code_offset()); 1047 summary.code_offset());
1054 thread_local_.last_fp_ = frame->UnpaddedFP(); 1048 thread_local_.last_fp_ = frame->UnpaddedFP();
1055 // No longer perform the current async step. 1049 // No longer perform the current async step.
1056 clear_suspended_generator(); 1050 clear_suspended_generator();
1057 1051
1058 switch (step_action) { 1052 switch (thread_local_.last_step_action_) {
1059 case StepNone: 1053 case StepNone:
1060 UNREACHABLE(); 1054 UNREACHABLE();
1061 break; 1055 break;
1062 case StepOut: 1056 case StepOut:
1063 // Advance to caller frame. 1057 // Advance to caller frame.
1064 frames_it.Advance(); 1058 frames_it.Advance();
1065 // Skip native and extension functions on the stack. 1059 // Skip native and extension functions on the stack.
1066 while (!frames_it.done() && 1060 while (!frames_it.done() &&
1067 !frames_it.frame()->function()->shared()->IsSubjectToDebugging()) { 1061 !frames_it.frame()->function()->shared()->IsSubjectToDebugging()) {
1068 // Builtin functions are not subject to stepping, but need to be 1062 // Builtin functions are not subject to stepping, but need to be
1069 // deoptimized to include checks for step-in at call sites. 1063 // deoptimized to include checks for step-in at call sites.
1070 Deoptimizer::DeoptimizeFunction(frames_it.frame()->function()); 1064 Deoptimizer::DeoptimizeFunction(frames_it.frame()->function());
1071 frames_it.Advance(); 1065 frames_it.Advance();
1072 } 1066 }
1073 if (frames_it.done()) { 1067 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. 1068 // Fill the caller function to return to with one-shot break points.
1079 Handle<JSFunction> caller_function(frames_it.frame()->function()); 1069 Handle<JSFunction> caller_function(frames_it.frame()->function());
1080 FloodWithOneShot(caller_function); 1070 FloodWithOneShot(caller_function);
1081 thread_local_.target_fp_ = frames_it.frame()->UnpaddedFP(); 1071 thread_local_.target_fp_ = frames_it.frame()->UnpaddedFP();
1082 } 1072 }
1083 // Clear last position info. For stepping out it does not matter. 1073 // Clear last position info. For stepping out it does not matter.
1084 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; 1074 thread_local_.last_statement_position_ = RelocInfo::kNoPosition;
1085 thread_local_.last_fp_ = 0; 1075 thread_local_.last_fp_ = 0;
1086 break; 1076 break;
1087 case StepNext: 1077 case StepNext:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 } 1125 }
1136 return locations; 1126 return locations;
1137 } 1127 }
1138 1128
1139 1129
1140 void Debug::ClearStepping() { 1130 void Debug::ClearStepping() {
1141 // Clear the various stepping setup. 1131 // Clear the various stepping setup.
1142 ClearOneShot(); 1132 ClearOneShot();
1143 1133
1144 thread_local_.last_step_action_ = StepNone; 1134 thread_local_.last_step_action_ = StepNone;
1145 thread_local_.step_in_enabled_ = false;
1146 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; 1135 thread_local_.last_statement_position_ = RelocInfo::kNoPosition;
1147 thread_local_.last_fp_ = 0; 1136 thread_local_.last_fp_ = 0;
1148 thread_local_.target_fp_ = 0; 1137 thread_local_.target_fp_ = 0;
1149 } 1138 }
1150 1139
1151 1140
1152 // Clears all the one-shot break points that are currently set. Normally this 1141 // 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 1142 // function is called each time a break point is hit as one shot break points
1154 // are used to support stepping. 1143 // are used to support stepping.
1155 void Debug::ClearOneShot() { 1144 void Debug::ClearOneShot() {
1156 // The current implementation just runs through all the breakpoints. When the 1145 // The current implementation just runs through all the breakpoints. When the
1157 // last break point for a function is removed that function is automatically 1146 // last break point for a function is removed that function is automatically
1158 // removed from the list. 1147 // removed from the list.
1159 for (DebugInfoListNode* node = debug_info_list_; node != NULL; 1148 for (DebugInfoListNode* node = debug_info_list_; node != NULL;
1160 node = node->next()) { 1149 node = node->next()) {
1161 for (base::SmartPointer<BreakLocation::Iterator> it( 1150 for (base::SmartPointer<BreakLocation::Iterator> it(
1162 BreakLocation::GetIterator(node->debug_info())); 1151 BreakLocation::GetIterator(node->debug_info()));
1163 !it->Done(); it->Next()) { 1152 !it->Done(); it->Next()) {
1164 it->GetBreakLocation().ClearOneShot(); 1153 it->GetBreakLocation().ClearOneShot();
1165 } 1154 }
1166 } 1155 }
1167 } 1156 }
1168 1157
1169 1158
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) { 1159 bool MatchingCodeTargets(Code* target1, Code* target2) {
1177 if (target1 == target2) return true; 1160 if (target1 == target2) return true;
1178 if (target1->kind() != target2->kind()) return false; 1161 if (target1->kind() != target2->kind()) return false;
1179 return target1->is_handler() || target1->is_inline_cache_stub(); 1162 return target1->is_handler() || target1->is_inline_cache_stub();
1180 } 1163 }
1181 1164
1182 1165
1183 // Count the number of calls before the current frame PC to find the 1166 // Count the number of calls before the current frame PC to find the
1184 // corresponding PC in the newly recompiled code. 1167 // corresponding PC in the newly recompiled code.
1185 static Address ComputeNewPcForRedirect(Code* new_code, Code* old_code, 1168 static Address ComputeNewPcForRedirect(Code* new_code, Code* old_code,
(...skipping 1424 matching lines...) Expand 10 before | Expand all | Expand 10 after
2610 } 2593 }
2611 2594
2612 2595
2613 void LockingCommandMessageQueue::Clear() { 2596 void LockingCommandMessageQueue::Clear() {
2614 base::LockGuard<base::Mutex> lock_guard(&mutex_); 2597 base::LockGuard<base::Mutex> lock_guard(&mutex_);
2615 queue_.Clear(); 2598 queue_.Clear();
2616 } 2599 }
2617 2600
2618 } // namespace internal 2601 } // namespace internal
2619 } // namespace v8 2602 } // namespace v8
OLDNEW
« no previous file with comments | « src/debug/debug.h ('k') | src/external-reference-table.cc » ('j') | src/x87/builtins-x87.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698