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 #ifndef V8_DEBUG_DEBUG_FRAMES_H_
6 #define V8_DEBUG_DEBUG_FRAMES_H_
7 
8 #include "src/deoptimizer.h"
9 #include "src/frames.h"
10 #include "src/isolate.h"
11 #include "src/objects.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 class FrameInspector {
17  public:
18   FrameInspector(StandardFrame* frame, int inlined_jsframe_index,
19                  Isolate* isolate);
20 
21   ~FrameInspector();
22 
23   int GetParametersCount();
24   Handle<JSFunction> GetFunction();
25   Handle<Script> GetScript();
26   Handle<Object> GetParameter(int index);
27   Handle<Object> GetExpression(int index);
28   int GetSourcePosition();
29   bool IsConstructor();
30   Handle<Object> GetContext();
31 
javascript_frame()32   inline JavaScriptFrame* javascript_frame() {
33     return frame_->is_arguments_adaptor() ? ArgumentsAdaptorFrame::cast(frame_)
34                                           : JavaScriptFrame::cast(frame_);
35   }
wasm_frame()36   inline WasmFrame* wasm_frame() { return WasmFrame::cast(frame_); }
37 
GetArgumentsFrame()38   JavaScriptFrame* GetArgumentsFrame() { return javascript_frame(); }
39   void SetArgumentsFrame(StandardFrame* frame);
40 
41   void MaterializeStackLocals(Handle<JSObject> target,
42                               Handle<ScopeInfo> scope_info);
43 
44   void MaterializeStackLocals(Handle<JSObject> target,
45                               Handle<JSFunction> function);
46 
47   void UpdateStackLocalsFromMaterializedObject(Handle<JSObject> object,
48                                                Handle<ScopeInfo> scope_info);
49 
50  private:
51   bool ParameterIsShadowedByContextLocal(Handle<ScopeInfo> info,
52                                          Handle<String> parameter_name);
53 
54   StandardFrame* frame_;
55   DeoptimizedFrameInfo* deoptimized_frame_;
56   Isolate* isolate_;
57   bool is_optimized_;
58   bool is_interpreted_;
59   bool is_bottommost_;
60   bool has_adapted_arguments_;
61 
62   DISALLOW_COPY_AND_ASSIGN(FrameInspector);
63 };
64 
65 
66 class DebugFrameHelper : public AllStatic {
67  public:
68   static SaveContext* FindSavedContextForFrame(Isolate* isolate,
69                                                StandardFrame* frame);
70   // Advances the iterator to the frame that matches the index and returns the
71   // inlined frame index, or -1 if not found.  Skips native JS functions.
72   static int FindIndexedNonNativeFrame(StackTraceFrameIterator* it, int index);
73 
74   // Helper functions for wrapping and unwrapping stack frame ids.
WrapFrameId(StackFrame::Id id)75   static Smi* WrapFrameId(StackFrame::Id id) {
76     DCHECK(IsAligned(OffsetFrom(id), static_cast<intptr_t>(4)));
77     return Smi::FromInt(id >> 2);
78   }
79 
UnwrapFrameId(int wrapped)80   static StackFrame::Id UnwrapFrameId(int wrapped) {
81     return static_cast<StackFrame::Id>(wrapped << 2);
82   }
83 };
84 
85 }  // namespace internal
86 }  // namespace v8
87 
88 #endif  // V8_DEBUG_DEBUG_FRAMES_H_
89