diff options
Diffstat (limited to 'deps/v8/src/debug/debug.cc')
-rw-r--r-- | deps/v8/src/debug/debug.cc | 180 |
1 files changed, 89 insertions, 91 deletions
diff --git a/deps/v8/src/debug/debug.cc b/deps/v8/src/debug/debug.cc index d33fc31669..5cc200d552 100644 --- a/deps/v8/src/debug/debug.cc +++ b/deps/v8/src/debug/debug.cc @@ -7,29 +7,30 @@ #include <memory> #include <unordered_set> -#include "src/api-inl.h" -#include "src/api-natives.h" -#include "src/arguments.h" -#include "src/assembler-inl.h" +#include "src/api/api-inl.h" +#include "src/api/api-natives.h" #include "src/base/platform/mutex.h" -#include "src/bootstrapper.h" #include "src/builtins/builtins.h" -#include "src/compilation-cache.h" -#include "src/compiler.h" -#include "src/counters.h" +#include "src/codegen/assembler-inl.h" +#include "src/codegen/compilation-cache.h" +#include "src/codegen/compiler.h" +#include "src/common/globals.h" #include "src/debug/debug-evaluate.h" #include "src/debug/liveedit.h" -#include "src/deoptimizer.h" -#include "src/execution.h" -#include "src/frames-inl.h" -#include "src/global-handles.h" -#include "src/globals.h" +#include "src/deoptimizer/deoptimizer.h" +#include "src/execution/arguments.h" +#include "src/execution/execution.h" +#include "src/execution/frames-inl.h" +#include "src/execution/isolate-inl.h" +#include "src/execution/message-template.h" +#include "src/execution/v8threads.h" +#include "src/handles/global-handles.h" #include "src/heap/heap-inl.h" // For NextDebuggingId. +#include "src/init/bootstrapper.h" #include "src/interpreter/bytecode-array-accessor.h" #include "src/interpreter/bytecode-array-iterator.h" #include "src/interpreter/interpreter.h" -#include "src/isolate-inl.h" -#include "src/message-template.h" +#include "src/logging/counters.h" #include "src/objects/api-callbacks-inl.h" #include "src/objects/debug-objects-inl.h" #include "src/objects/js-generator-inl.h" @@ -37,7 +38,6 @@ #include "src/objects/slots.h" #include "src/snapshot/natives.h" #include "src/snapshot/snapshot.h" -#include "src/v8threads.h" #include "src/wasm/wasm-objects-inl.h" namespace v8 { @@ -202,8 +202,8 @@ BreakIterator::BreakIterator(Handle<DebugInfo> debug_info) : debug_info_(debug_info), break_index_(-1), source_position_iterator_( - debug_info->DebugBytecodeArray()->SourcePositionTable()) { - position_ = debug_info->shared()->StartPosition(); + debug_info->DebugBytecodeArray().SourcePositionTable()) { + position_ = debug_info->shared().StartPosition(); statement_position_ = position_; // There is at least one break location. DCHECK(!Done()); @@ -251,12 +251,12 @@ void BreakIterator::Next() { DebugBreakType BreakIterator::GetDebugBreakType() { BytecodeArray bytecode_array = debug_info_->OriginalBytecodeArray(); interpreter::Bytecode bytecode = - interpreter::Bytecodes::FromByte(bytecode_array->get(code_offset())); + interpreter::Bytecodes::FromByte(bytecode_array.get(code_offset())); // Make sure we read the actual bytecode, not a prefix scaling bytecode. if (interpreter::Bytecodes::IsPrefixScalingBytecode(bytecode)) { - bytecode = interpreter::Bytecodes::FromByte( - bytecode_array->get(code_offset() + 1)); + bytecode = + interpreter::Bytecodes::FromByte(bytecode_array.get(code_offset() + 1)); } if (bytecode == interpreter::Bytecode::kDebugger) { @@ -296,7 +296,7 @@ void BreakIterator::ClearDebugBreak() { DCHECK(debug_break_type >= DEBUG_BREAK_SLOT); BytecodeArray bytecode_array = debug_info_->DebugBytecodeArray(); BytecodeArray original = debug_info_->OriginalBytecodeArray(); - bytecode_array->set(code_offset(), original->get(code_offset())); + bytecode_array.set(code_offset(), original.get(code_offset())); } BreakLocation BreakIterator::GetBreakLocation() { @@ -541,8 +541,8 @@ bool Debug::IsMutedAtCurrentLocation(JavaScriptFrame* frame) { FrameSummary summary = FrameSummary::GetTop(frame); DCHECK(!summary.IsWasm()); Handle<JSFunction> function = summary.AsJavaScript().function(); - if (!function->shared()->HasBreakInfo()) return false; - Handle<DebugInfo> debug_info(function->shared()->GetDebugInfo(), isolate_); + if (!function->shared().HasBreakInfo()) return false; + Handle<DebugInfo> debug_info(function->shared().GetDebugInfo(), isolate_); // Enter the debugger. DebugScope debug_scope(this); std::vector<BreakLocation> break_locations; @@ -563,7 +563,7 @@ bool Debug::CheckBreakPoint(Handle<BreakPoint> break_point, bool is_break_at_entry) { HandleScope scope(isolate_); - if (!break_point->condition()->length()) return true; + if (!break_point->condition().length()) return true; Handle<String> condition(break_point->condition(), isolate_); MaybeHandle<Object> maybe_result; Handle<Object> result; @@ -589,13 +589,12 @@ bool Debug::CheckBreakPoint(Handle<BreakPoint> break_point, return result->BooleanValue(isolate_); } -bool Debug::SetBreakPoint(Handle<JSFunction> function, +bool Debug::SetBreakpoint(Handle<SharedFunctionInfo> shared, Handle<BreakPoint> break_point, int* source_position) { HandleScope scope(isolate_); // Make sure the function is compiled and has set up the debug info. - Handle<SharedFunctionInfo> shared(function->shared(), isolate_); if (!EnsureBreakInfo(shared)) return false; PrepareFunctionForDebugExecution(shared); @@ -686,13 +685,13 @@ void Debug::ApplyBreakPoints(Handle<DebugInfo> debug_info) { } else { if (!debug_info->HasInstrumentedBytecodeArray()) return; FixedArray break_points = debug_info->break_points(); - for (int i = 0; i < break_points->length(); i++) { - if (break_points->get(i)->IsUndefined(isolate_)) continue; - BreakPointInfo info = BreakPointInfo::cast(break_points->get(i)); - if (info->GetBreakPointCount(isolate_) == 0) continue; + for (int i = 0; i < break_points.length(); i++) { + if (break_points.get(i).IsUndefined(isolate_)) continue; + BreakPointInfo info = BreakPointInfo::cast(break_points.get(i)); + if (info.GetBreakPointCount(isolate_) == 0) continue; DCHECK(debug_info->HasInstrumentedBytecodeArray()); BreakIterator it(debug_info); - it.SkipToPosition(info->source_position()); + it.SkipToPosition(info.source_position()); it.SetDebugBreak(); } } @@ -750,13 +749,13 @@ int Debug::GetFunctionDebuggingId(Handle<JSFunction> function) { return id; } -bool Debug::SetBreakpointForFunction(Handle<JSFunction> function, +bool Debug::SetBreakpointForFunction(Handle<SharedFunctionInfo> shared, Handle<String> condition, int* id) { *id = ++thread_local_.last_breakpoint_id_; Handle<BreakPoint> breakpoint = isolate_->factory()->NewBreakPoint(*id, condition); int source_position = 0; - return SetBreakPoint(function, breakpoint, &source_position); + return SetBreakpoint(shared, breakpoint, &source_position); } void Debug::RemoveBreakpoint(int id) { @@ -874,7 +873,7 @@ void Debug::PrepareStepInSuspendedGenerator() { thread_local_.last_step_action_ = StepIn; UpdateHookOnFunctionCall(); Handle<JSFunction> function( - JSGeneratorObject::cast(thread_local_.suspended_generator_)->function(), + JSGeneratorObject::cast(thread_local_.suspended_generator_).function(), isolate_); FloodWithOneShot(Handle<SharedFunctionInfo>(function->shared(), isolate_)); clear_suspended_generator(); @@ -978,12 +977,12 @@ void Debug::PrepareStep(StepAction step_action) { if (frame->is_wasm_compiled()) return; WasmInterpreterEntryFrame* wasm_frame = WasmInterpreterEntryFrame::cast(frame); - wasm_frame->debug_info()->PrepareStep(step_action); + wasm_frame->debug_info().PrepareStep(step_action); return; } JavaScriptFrame* js_frame = JavaScriptFrame::cast(frame); - DCHECK(js_frame->function()->IsJSFunction()); + DCHECK(js_frame->function().IsJSFunction()); // Get the debug info (create it if it does not exist). auto summary = FrameSummary::GetTop(frame).AsJavaScript(); @@ -1024,7 +1023,6 @@ void Debug::PrepareStep(StepAction step_action) { switch (step_action) { case StepNone: UNREACHABLE(); - break; case StepOut: { // Clear last position info. For stepping out it does not matter. thread_local_.last_statement_position_ = kNoSourcePosition; @@ -1091,15 +1089,15 @@ Handle<Object> Debug::GetSourceBreakLocations( Handle<FixedArray> locations = isolate->factory()->NewFixedArray( debug_info->GetBreakPointCount(isolate)); int count = 0; - for (int i = 0; i < debug_info->break_points()->length(); ++i) { - if (!debug_info->break_points()->get(i)->IsUndefined(isolate)) { + for (int i = 0; i < debug_info->break_points().length(); ++i) { + if (!debug_info->break_points().get(i).IsUndefined(isolate)) { BreakPointInfo break_point_info = - BreakPointInfo::cast(debug_info->break_points()->get(i)); - int break_points = break_point_info->GetBreakPointCount(isolate); + BreakPointInfo::cast(debug_info->break_points().get(i)); + int break_points = break_point_info.GetBreakPointCount(isolate); if (break_points == 0) continue; for (int j = 0; j < break_points; ++j) { locations->set(count++, - Smi::FromInt(break_point_info->source_position())); + Smi::FromInt(break_point_info.source_position())); } } } @@ -1150,8 +1148,8 @@ void Debug::DeoptimizeFunction(Handle<SharedFunctionInfo> shared) { do { Code code = iterator.Next(); if (code.is_null()) break; - if (code->Inlines(*shared)) { - code->set_marked_for_deoptimization(true); + if (code.Inlines(*shared)) { + code.set_marked_for_deoptimization(true); found_something = true; } } while (true); @@ -1215,7 +1213,7 @@ void Debug::InstallDebugBreakTrampoline() { current = current->next()) { if (current->debug_info()->CanBreakAtEntry()) { needs_to_use_trampoline = true; - if (current->debug_info()->shared()->IsApiFunction()) { + if (current->debug_info()->shared().IsApiFunction()) { needs_to_clear_ic = true; break; } @@ -1231,23 +1229,23 @@ void Debug::InstallDebugBreakTrampoline() { HeapIterator iterator(isolate_->heap()); for (HeapObject obj = iterator.next(); !obj.is_null(); obj = iterator.next()) { - if (needs_to_clear_ic && obj->IsFeedbackVector()) { - FeedbackVector::cast(obj)->ClearSlots(isolate_); + if (needs_to_clear_ic && obj.IsFeedbackVector()) { + FeedbackVector::cast(obj).ClearSlots(isolate_); continue; - } else if (obj->IsJSFunction()) { + } else if (obj.IsJSFunction()) { JSFunction fun = JSFunction::cast(obj); - SharedFunctionInfo shared = fun->shared(); - if (!shared->HasDebugInfo()) continue; - if (!shared->GetDebugInfo()->CanBreakAtEntry()) continue; - if (!fun->is_compiled()) { + SharedFunctionInfo shared = fun.shared(); + if (!shared.HasDebugInfo()) continue; + if (!shared.GetDebugInfo().CanBreakAtEntry()) continue; + if (!fun.is_compiled()) { needs_compile.push_back(handle(fun, isolate_)); } else { - fun->set_code(*trampoline); + fun.set_code(*trampoline); } - } else if (obj->IsAccessorPair()) { + } else if (obj.IsAccessorPair()) { AccessorPair accessor_pair = AccessorPair::cast(obj); - if (accessor_pair->getter()->IsFunctionTemplateInfo() || - accessor_pair->setter()->IsFunctionTemplateInfo()) { + if (accessor_pair.getter().IsFunctionTemplateInfo() || + accessor_pair.setter().IsFunctionTemplateInfo()) { needs_instantiate.push_back(handle(accessor_pair, isolate_)); } } @@ -1257,7 +1255,7 @@ void Debug::InstallDebugBreakTrampoline() { // Forcibly instantiate all lazy accessor pairs to make sure that they // properly hit the debug break trampoline. for (Handle<AccessorPair> accessor_pair : needs_instantiate) { - if (accessor_pair->getter()->IsFunctionTemplateInfo()) { + if (accessor_pair->getter().IsFunctionTemplateInfo()) { Handle<JSFunction> fun = ApiNatives::InstantiateFunction( handle(FunctionTemplateInfo::cast(accessor_pair->getter()), @@ -1265,7 +1263,7 @@ void Debug::InstallDebugBreakTrampoline() { .ToHandleChecked(); accessor_pair->set_getter(*fun); } - if (accessor_pair->setter()->IsFunctionTemplateInfo()) { + if (accessor_pair->setter().IsFunctionTemplateInfo()) { Handle<JSFunction> fun = ApiNatives::InstantiateFunction( handle(FunctionTemplateInfo::cast(accessor_pair->setter()), @@ -1332,12 +1330,12 @@ bool Debug::GetPossibleBreakpoints(Handle<Script> script, int start_position, SharedFunctionInfo::ScriptIterator iterator(isolate_, *script); for (SharedFunctionInfo info = iterator.Next(); !info.is_null(); info = iterator.Next()) { - if (info->EndPosition() < start_position || - info->StartPosition() >= end_position) { + if (info.EndPosition() < start_position || + info.StartPosition() >= end_position) { continue; } - if (!info->IsSubjectToDebugging()) continue; - if (!info->is_compiled() && !info->allows_lazy_compilation()) continue; + if (!info.IsSubjectToDebugging()) continue; + if (!info.is_compiled() && !info.allows_lazy_compilation()) continue; candidates.push_back(i::handle(info, isolate_)); } @@ -1396,26 +1394,26 @@ class SharedFunctionInfoFinder { void NewCandidate(SharedFunctionInfo shared, JSFunction closure = JSFunction()) { - if (!shared->IsSubjectToDebugging()) return; - int start_position = shared->function_token_position(); + if (!shared.IsSubjectToDebugging()) return; + int start_position = shared.function_token_position(); if (start_position == kNoSourcePosition) { - start_position = shared->StartPosition(); + start_position = shared.StartPosition(); } if (start_position > target_position_) return; - if (target_position_ > shared->EndPosition()) return; + if (target_position_ > shared.EndPosition()) return; if (!current_candidate_.is_null()) { if (current_start_position_ == start_position && - shared->EndPosition() == current_candidate_->EndPosition()) { + shared.EndPosition() == current_candidate_.EndPosition()) { // If we already have a matching closure, do not throw it away. if (!current_candidate_closure_.is_null() && closure.is_null()) return; // If a top-level function contains only one function // declaration the source for the top-level and the function // is the same. In that case prefer the non top-level function. - if (!current_candidate_->is_toplevel() && shared->is_toplevel()) return; + if (!current_candidate_.is_toplevel() && shared.is_toplevel()) return; } else if (start_position < current_start_position_ || - current_candidate_->EndPosition() < shared->EndPosition()) { + current_candidate_.EndPosition() < shared.EndPosition()) { return; } } @@ -1464,7 +1462,7 @@ Handle<Object> Debug::FindSharedFunctionInfoInScript(Handle<Script> script, shared = finder.Result(); if (shared.is_null()) break; // We found it if it's already compiled. - is_compiled_scope = shared->is_compiled_scope(); + is_compiled_scope = shared.is_compiled_scope(); if (is_compiled_scope.is_compiled()) { Handle<SharedFunctionInfo> shared_handle(shared, isolate_); // If the iteration count is larger than 1, we had to compile the outer @@ -1481,7 +1479,7 @@ Handle<Object> Debug::FindSharedFunctionInfoInScript(Handle<Script> script, // If not, compile to reveal inner functions. HandleScope scope(isolate_); // Code that cannot be compiled lazily are internal and not debuggable. - DCHECK(shared->allows_lazy_compilation()); + DCHECK(shared.allows_lazy_compilation()); if (!Compiler::Compile(handle(shared, isolate_), Compiler::CLEAR_EXCEPTION, &is_compiled_scope)) { break; @@ -1619,7 +1617,7 @@ void Debug::FreeDebugInfoListNode(DebugInfoListNode* prev, // Pack script back into the // SFI::script_or_debug_info field. Handle<DebugInfo> debug_info(node->debug_info()); - debug_info->shared()->set_script_or_debug_info(debug_info->script()); + debug_info->shared().set_script_or_debug_info(debug_info->script()); delete node; } @@ -1628,7 +1626,7 @@ bool Debug::IsBreakAtReturn(JavaScriptFrame* frame) { HandleScope scope(isolate_); // Get the executing function in which the debug break occurred. - Handle<SharedFunctionInfo> shared(frame->function()->shared(), isolate_); + Handle<SharedFunctionInfo> shared(frame->function().shared(), isolate_); // With no debug info there are no break points, so we can't be at a return. if (!shared->HasBreakInfo()) return false; @@ -1675,7 +1673,7 @@ Handle<FixedArray> Debug::GetLoadedScripts() { Script::Iterator iterator(isolate_); for (Script script = iterator.Next(); !script.is_null(); script = iterator.Next()) { - if (script->HasValidSource()) results->set(length++, script); + if (script.HasValidSource()) results->set(length++, script); } } return FixedArray::ShrinkOrEmpty(isolate_, results, length); @@ -1808,7 +1806,7 @@ void Debug::OnDebugBreak(Handle<FixedArray> break_points_hit) { // This array contains breakpoints installed using JS debug API. for (int i = 0; i < break_points_hit->length(); ++i) { BreakPoint break_point = BreakPoint::cast(break_points_hit->get(i)); - inspector_break_points_hit.push_back(break_point->id()); + inspector_break_points_hit.push_back(break_point.id()); ++inspector_break_points_count; } @@ -1836,13 +1834,13 @@ bool Debug::IsBlackboxed(Handle<SharedFunctionInfo> shared) { Handle<DebugInfo> debug_info = GetOrCreateDebugInfo(shared); if (!debug_info->computed_debug_is_blackboxed()) { bool is_blackboxed = - !shared->IsSubjectToDebugging() || !shared->script()->IsScript(); + !shared->IsSubjectToDebugging() || !shared->script().IsScript(); if (!is_blackboxed) { SuppressDebug while_processing(this); HandleScope handle_scope(isolate_); PostponeInterruptsScope no_interrupts(isolate_); DisableBreak no_recursive_break(this); - DCHECK(shared->script()->IsScript()); + DCHECK(shared->script().IsScript()); Handle<Script> script(Script::cast(shared->script()), isolate_); DCHECK(script->IsUserJavaScript()); debug::Location start = GetDebugLocation(script, shared->StartPosition()); @@ -1980,7 +1978,7 @@ void Debug::HandleDebugBreak(IgnoreBreakMode ignore_break_mode) { { JavaScriptFrameIterator it(isolate_); DCHECK(!it.done()); Object fun = it.frame()->function(); - if (fun->IsJSFunction()) { + if (fun.IsJSFunction()) { HandleScope scope(isolate_); Handle<JSFunction> function(JSFunction::cast(fun), isolate_); // Don't stop in builtin and blackboxed functions. @@ -2032,7 +2030,7 @@ void Debug::PrintBreakLocation() { String::FlatContent content = source->GetFlatContent(no_gc); if (content.IsOneByte()) { PrintF("[debug] %.*s\n", line_end - line_start, - content.ToOneByteVector().start() + line_start); + content.ToOneByteVector().begin() + line_start); PrintF("[debug] "); for (int i = 0; i < column; i++) PrintF(" "); PrintF("^\n"); @@ -2093,7 +2091,7 @@ void Debug::UpdateDebugInfosForExecutionMode() { Handle<DebugInfo> debug_info = current->debug_info(); if (debug_info->HasInstrumentedBytecodeArray() && debug_info->DebugExecutionMode() != isolate_->debug_execution_mode()) { - DCHECK(debug_info->shared()->HasBytecodeArray()); + DCHECK(debug_info->shared().HasBytecodeArray()); if (isolate_->debug_execution_mode() == DebugInfo::kBreakpoints) { ClearSideEffectChecks(debug_info); ApplyBreakPoints(debug_info); @@ -2175,7 +2173,7 @@ bool Debug::PerformSideEffectCheck(Handle<JSFunction> function, Handle<Object> receiver) { DCHECK_EQ(isolate_->debug_execution_mode(), DebugInfo::kSideEffects); DisallowJavascriptExecution no_js(isolate_); - IsCompiledScope is_compiled_scope(function->shared()->is_compiled_scope()); + IsCompiledScope is_compiled_scope(function->shared().is_compiled_scope()); if (!function->is_compiled() && !Compiler::Compile(function, Compiler::KEEP_EXCEPTION, &is_compiled_scope)) { @@ -2190,7 +2188,7 @@ bool Debug::PerformSideEffectCheck(Handle<JSFunction> function, case DebugInfo::kHasSideEffects: if (FLAG_trace_side_effect_free_debug_evaluate) { PrintF("[debug-evaluate] Function %s failed side effect check.\n", - function->shared()->DebugName()->ToCString().get()); + function->shared().DebugName().ToCString().get()); } side_effect_check_failed_ = true; // Throw an uncatchable termination exception. @@ -2227,7 +2225,7 @@ bool Debug::PerformSideEffectCheckForCallback( DCHECK_EQ(!receiver.is_null(), callback_info->IsAccessorInfo()); DCHECK_EQ(isolate_->debug_execution_mode(), DebugInfo::kSideEffects); if (!callback_info.is_null() && callback_info->IsCallHandlerInfo() && - i::CallHandlerInfo::cast(*callback_info)->NextCallHasNoSideEffect()) { + i::CallHandlerInfo::cast(*callback_info).NextCallHasNoSideEffect()) { return true; } // TODO(7515): always pass a valid callback info object. @@ -2236,8 +2234,8 @@ bool Debug::PerformSideEffectCheckForCallback( // List of whitelisted internal accessors can be found in accessors.h. AccessorInfo info = AccessorInfo::cast(*callback_info); DCHECK_NE(kNotAccessor, accessor_kind); - switch (accessor_kind == kSetter ? info->setter_side_effect_type() - : info->getter_side_effect_type()) { + switch (accessor_kind == kSetter ? info.setter_side_effect_type() + : info.getter_side_effect_type()) { case SideEffectType::kHasNoSideEffect: // We do not support setter accessors with no side effects, since // calling set accessors go through a store bytecode. Store bytecodes @@ -2254,18 +2252,18 @@ bool Debug::PerformSideEffectCheckForCallback( } if (FLAG_trace_side_effect_free_debug_evaluate) { PrintF("[debug-evaluate] API Callback '"); - info->name()->ShortPrint(); + info.name().ShortPrint(); PrintF("' may cause side effect.\n"); } } else if (callback_info->IsInterceptorInfo()) { InterceptorInfo info = InterceptorInfo::cast(*callback_info); - if (info->has_no_side_effect()) return true; + if (info.has_no_side_effect()) return true; if (FLAG_trace_side_effect_free_debug_evaluate) { PrintF("[debug-evaluate] API Interceptor may cause side effect.\n"); } } else if (callback_info->IsCallHandlerInfo()) { CallHandlerInfo info = CallHandlerInfo::cast(*callback_info); - if (info->IsSideEffectFreeCallHandlerInfo()) return true; + if (info.IsSideEffectFreeCallHandlerInfo()) return true; if (FLAG_trace_side_effect_free_debug_evaluate) { PrintF("[debug-evaluate] API CallHandlerInfo may cause side effect.\n"); } @@ -2282,8 +2280,8 @@ bool Debug::PerformSideEffectCheckAtBytecode(InterpretedFrame* frame) { using interpreter::Bytecode; DCHECK_EQ(isolate_->debug_execution_mode(), DebugInfo::kSideEffects); - SharedFunctionInfo shared = frame->function()->shared(); - BytecodeArray bytecode_array = shared->GetBytecodeArray(); + SharedFunctionInfo shared = frame->function().shared(); + BytecodeArray bytecode_array = shared.GetBytecodeArray(); int offset = frame->GetBytecodeOffset(); interpreter::BytecodeArrayAccessor bytecode_accessor( handle(bytecode_array, isolate_), offset); |