debug-frames.cc 3.37 KB
Newer Older
1 2 3 4 5 6
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/debug/debug-frames.h"

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 13 14
namespace v8 {
namespace internal {

15
FrameInspector::FrameInspector(StandardFrame* frame, int inlined_frame_index,
16
                               Isolate* isolate)
17
    : frame_(frame),
18
      inlined_frame_index_(inlined_frame_index),
19
      isolate_(isolate) {
20 21 22 23 24 25 26 27 28 29 30 31 32
  // Extract the relevant information from the frame summary and discard it.
  FrameSummary summary = FrameSummary::Get(frame, inlined_frame_index);

  is_constructor_ = summary.is_constructor();
  source_position_ = summary.SourcePosition();
  function_name_ = summary.FunctionName();
  script_ = Handle<Script>::cast(summary.script());
  receiver_ = summary.receiver();

  if (summary.IsJavaScript()) {
    function_ = summary.AsJavaScript().function();
  }

33 34 35 36
  JavaScriptFrame* js_frame =
      frame->is_java_script() ? javascript_frame() : nullptr;
  DCHECK(js_frame || frame->is_wasm());
  has_adapted_arguments_ = js_frame && js_frame->has_adapted_arguments();
37
  is_optimized_ = frame_->is_optimized();
38
  is_interpreted_ = frame_->is_interpreted();
39

40
  // Calculate the deoptimized frame.
41
  if (is_optimized_) {
42
    DCHECK_NOT_NULL(js_frame);
43 44 45 46
    deoptimized_frame_.reset(Deoptimizer::DebuggerInspectableFrame(
        js_frame, inlined_frame_index, isolate));
  } else if (frame_->is_wasm_interpreter_entry()) {
    wasm_interpreted_frame_ =
47 48 49
        WasmInterpreterEntryFrame::cast(frame_)
            ->debug_info()
            ->GetInterpretedFrame(frame_->fp(), inlined_frame_index);
50
    DCHECK(wasm_interpreted_frame_);
51 52 53
  }
}

54
// NOLINTNEXTLINE
55
FrameInspector::~FrameInspector() {
56 57
  // Destructor needs to be defined in the .cc file, because it instantiates
  // std::unique_ptr destructors but the types are not known in the header.
58 59 60
}

int FrameInspector::GetParametersCount() {
61 62 63 64
  if (is_optimized_) return deoptimized_frame_->parameters_count();
  if (wasm_interpreted_frame_)
    return wasm_interpreted_frame_->GetParameterCount();
  return frame_->ComputeParametersCount();
65 66
}

67
Handle<Object> FrameInspector::GetParameter(int index) {
68 69 70
  if (is_optimized_) return deoptimized_frame_->GetParameter(index);
  // TODO(clemensh): Handle wasm_interpreted_frame_.
  return handle(frame_->GetParameter(index), isolate_);
71 72
}

73
Handle<Object> FrameInspector::GetExpression(int index) {
74
  return is_optimized_ ? deoptimized_frame_->GetExpression(index)
75
                       : handle(frame_->GetExpression(index), isolate_);
76 77
}

78 79 80
Handle<Object> FrameInspector::GetContext() {
  return deoptimized_frame_ ? deoptimized_frame_->GetContext()
                            : handle(frame_->context(), isolate_);
81 82
}

83
bool FrameInspector::IsWasm() { return frame_->is_wasm(); }
84

85
bool FrameInspector::IsJavaScript() { return frame_->is_java_script(); }
86 87 88 89 90 91

bool FrameInspector::ParameterIsShadowedByContextLocal(
    Handle<ScopeInfo> info, Handle<String> parameter_name) {
  VariableMode mode;
  InitializationFlag init_flag;
  MaybeAssignedFlag maybe_assigned_flag;
92
  return ScopeInfo::ContextSlotIndex(*info, *parameter_name, &mode, &init_flag,
93
                                     &maybe_assigned_flag) != -1;
94 95 96
}
}  // namespace internal
}  // namespace v8