Home | History | Annotate | Download | only in debug
      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 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   // Extract the relevant information from the frame summary and discard it.
     21   FrameSummary summary = FrameSummary::Get(frame, inlined_frame_index);
     22 
     23   is_constructor_ = summary.is_constructor();
     24   source_position_ = summary.SourcePosition();
     25   function_name_ = summary.FunctionName();
     26   script_ = Handle<Script>::cast(summary.script());
     27   receiver_ = summary.receiver();
     28 
     29   if (summary.IsJavaScript()) {
     30     function_ = summary.AsJavaScript().function();
     31   }
     32 
     33   JavaScriptFrame* js_frame =
     34       frame->is_java_script() ? javascript_frame() : nullptr;
     35   DCHECK(js_frame || frame->is_wasm());
     36   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     deoptimized_frame_.reset(Deoptimizer::DebuggerInspectableFrame(
     44         js_frame, inlined_frame_index, isolate));
     45   } else if (frame_->is_wasm_interpreter_entry()) {
     46     wasm_interpreted_frame_ =
     47         WasmInterpreterEntryFrame::cast(frame_)
     48             ->debug_info()
     49             ->GetInterpretedFrame(frame_->fp(), inlined_frame_index);
     50     DCHECK(wasm_interpreted_frame_);
     51   }
     52 }
     53 
     54 FrameInspector::~FrameInspector() {
     55   // Destructor needs to be defined in the .cc file, because it instantiates
     56   // std::unique_ptr destructors but the types are not known in the header.
     57 }
     58 
     59 int FrameInspector::GetParametersCount() {
     60   if (is_optimized_) return deoptimized_frame_->parameters_count();
     61   if (wasm_interpreted_frame_)
     62     return wasm_interpreted_frame_->GetParameterCount();
     63   return frame_->ComputeParametersCount();
     64 }
     65 
     66 Handle<Object> FrameInspector::GetParameter(int index) {
     67   if (is_optimized_) return deoptimized_frame_->GetParameter(index);
     68   // TODO(clemensh): Handle wasm_interpreted_frame_.
     69   return handle(frame_->GetParameter(index), isolate_);
     70 }
     71 
     72 Handle<Object> FrameInspector::GetExpression(int index) {
     73   return is_optimized_ ? deoptimized_frame_->GetExpression(index)
     74                        : handle(frame_->GetExpression(index), isolate_);
     75 }
     76 
     77 Handle<Object> FrameInspector::GetContext() {
     78   return deoptimized_frame_ ? deoptimized_frame_->GetContext()
     79                             : handle(frame_->context(), isolate_);
     80 }
     81 
     82 bool FrameInspector::IsWasm() { return frame_->is_wasm(); }
     83 
     84 bool FrameInspector::IsJavaScript() { return frame_->is_java_script(); }
     85 
     86 bool FrameInspector::ParameterIsShadowedByContextLocal(
     87     Handle<ScopeInfo> info, Handle<String> parameter_name) {
     88   VariableMode mode;
     89   InitializationFlag init_flag;
     90   MaybeAssignedFlag maybe_assigned_flag;
     91   return ScopeInfo::ContextSlotIndex(info, parameter_name, &mode, &init_flag,
     92                                      &maybe_assigned_flag) != -1;
     93 }
     94 }  // namespace internal
     95 }  // namespace v8
     96