LCOV - code coverage report
Current view: top level - src/debug - debug-frames.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 47 55 85.5 %
Date: 2019-04-18 Functions: 10 12 83.3 %

          Line data    Source code
       1             : // Copyright 2015 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/debug/debug-frames.h"
       6             : 
       7             : #include "src/accessors.h"
       8             : #include "src/frames-inl.h"
       9             : #include "src/wasm/wasm-interpreter.h"
      10             : #include "src/wasm/wasm-objects-inl.h"
      11             : 
      12             : namespace v8 {
      13             : namespace internal {
      14             : 
      15      261834 : FrameInspector::FrameInspector(StandardFrame* frame, int inlined_frame_index,
      16             :                                Isolate* isolate)
      17             :     : frame_(frame),
      18             :       inlined_frame_index_(inlined_frame_index),
      19      785502 :       isolate_(isolate) {
      20             :   // Extract the relevant information from the frame summary and discard it.
      21      523668 :   FrameSummary summary = FrameSummary::Get(frame, inlined_frame_index);
      22      261834 :   summary.EnsureSourcePositionsAvailable();
      23             : 
      24      261834 :   is_constructor_ = summary.is_constructor();
      25      261834 :   source_position_ = summary.SourcePosition();
      26      261834 :   function_name_ = summary.FunctionName();
      27      261834 :   script_ = Handle<Script>::cast(summary.script());
      28      261834 :   receiver_ = summary.receiver();
      29             : 
      30      261834 :   if (summary.IsJavaScript()) {
      31      260994 :     function_ = summary.AsJavaScript().function();
      32             :   }
      33             : 
      34             :   JavaScriptFrame* js_frame =
      35      261834 :       frame->is_java_script() ? javascript_frame() : nullptr;
      36             :   DCHECK(js_frame || frame->is_wasm());
      37      522828 :   has_adapted_arguments_ = js_frame && js_frame->has_adapted_arguments();
      38      523668 :   is_optimized_ = frame_->is_optimized();
      39      523668 :   is_interpreted_ = frame_->is_interpreted();
      40             : 
      41             :   // Calculate the deoptimized frame.
      42      261834 :   if (is_optimized_) {
      43             :     DCHECK_NOT_NULL(js_frame);
      44       24955 :     deoptimized_frame_.reset(Deoptimizer::DebuggerInspectableFrame(
      45       24955 :         js_frame, inlined_frame_index, isolate));
      46      473758 :   } else if (frame_->is_wasm_interpreter_entry()) {
      47             :     wasm_interpreted_frame_ =
      48             :         WasmInterpreterEntryFrame::cast(frame_)
      49        1496 :             ->debug_info()
      50        2244 :             ->GetInterpretedFrame(frame_->fp(), inlined_frame_index);
      51             :     DCHECK(wasm_interpreted_frame_);
      52             :   }
      53      261834 : }
      54             : 
      55             : // NOLINTNEXTLINE
      56      523668 : FrameInspector::~FrameInspector() {
      57             :   // Destructor needs to be defined in the .cc file, because it instantiates
      58             :   // std::unique_ptr destructors but the types are not known in the header.
      59      261834 : }
      60             : 
      61           0 : int FrameInspector::GetParametersCount() {
      62           0 :   if (is_optimized_) return deoptimized_frame_->parameters_count();
      63           0 :   if (wasm_interpreted_frame_)
      64           0 :     return wasm_interpreted_frame_->GetParameterCount();
      65           0 :   return frame_->ComputeParametersCount();
      66             : }
      67             : 
      68       25375 : Handle<Object> FrameInspector::GetParameter(int index) {
      69       25375 :   if (is_optimized_) return deoptimized_frame_->GetParameter(index);
      70             :   // TODO(clemensh): Handle wasm_interpreted_frame_.
      71       13113 :   return handle(frame_->GetParameter(index), isolate_);
      72             : }
      73             : 
      74     3996622 : Handle<Object> FrameInspector::GetExpression(int index) {
      75     3996622 :   return is_optimized_ ? deoptimized_frame_->GetExpression(index)
      76    11980564 :                        : handle(frame_->GetExpression(index), isolate_);
      77             : }
      78             : 
      79      477161 : Handle<Object> FrameInspector::GetContext() {
      80             :   return deoptimized_frame_ ? deoptimized_frame_->GetContext()
      81      954322 :                             : handle(frame_->context(), isolate_);
      82             : }
      83             : 
      84      383226 : bool FrameInspector::IsWasm() { return frame_->is_wasm(); }
      85             : 
      86      294215 : bool FrameInspector::IsJavaScript() { return frame_->is_java_script(); }
      87             : 
      88           0 : bool FrameInspector::ParameterIsShadowedByContextLocal(
      89             :     Handle<ScopeInfo> info, Handle<String> parameter_name) {
      90             :   VariableMode mode;
      91             :   InitializationFlag init_flag;
      92             :   MaybeAssignedFlag maybe_assigned_flag;
      93           0 :   return ScopeInfo::ContextSlotIndex(*info, *parameter_name, &mode, &init_flag,
      94           0 :                                      &maybe_assigned_flag) != -1;
      95             : }
      96             : 
      97       21202 : RedirectActiveFunctions::RedirectActiveFunctions(SharedFunctionInfo shared,
      98             :                                                  Mode mode)
      99       21202 :     : shared_(shared), mode_(mode) {
     100             :   DCHECK(shared->HasBytecodeArray());
     101             :   if (mode == Mode::kUseDebugBytecode) {
     102             :     DCHECK(shared->HasDebugInfo());
     103             :   }
     104       21202 : }
     105             : 
     106       21286 : void RedirectActiveFunctions::VisitThread(Isolate* isolate,
     107             :                                           ThreadLocalTop* top) {
     108       54916 :   for (JavaScriptFrameIterator it(isolate, top); !it.done(); it.Advance()) {
     109             :     JavaScriptFrame* frame = it.frame();
     110       33630 :     JSFunction function = frame->function();
     111       98875 :     if (!frame->is_interpreted()) continue;
     112       30606 :     if (function->shared() != shared_) continue;
     113             :     InterpretedFrame* interpreted_frame =
     114             :         reinterpret_cast<InterpretedFrame*>(frame);
     115        2015 :     BytecodeArray bytecode = mode_ == Mode::kUseDebugBytecode
     116             :                                  ? shared_->GetDebugInfo()->DebugBytecodeArray()
     117        3665 :                                  : shared_->GetBytecodeArray();
     118        2015 :     interpreted_frame->PatchBytecodeArray(bytecode);
     119             :   }
     120       21286 : }
     121             : 
     122             : }  // namespace internal
     123      122036 : }  // namespace v8

Generated by: LCOV version 1.10