OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_WASM_DEBUG_H_ | 5 #ifndef V8_WASM_DEBUG_H_ |
6 #define V8_WASM_DEBUG_H_ | 6 #define V8_WASM_DEBUG_H_ |
7 | 7 |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 #include "src/objects.h" | 9 #include "src/objects.h" |
| 10 #include "src/wasm/ast-decoder.h" |
10 | 11 |
11 namespace v8 { | 12 namespace v8 { |
12 namespace internal { | 13 namespace internal { |
13 namespace wasm { | 14 namespace wasm { |
14 | 15 |
| 16 class WasmInstructionIterator { |
| 17 const byte* const start_; |
| 18 const byte* pc_; |
| 19 const byte* const end_; |
| 20 |
| 21 public: |
| 22 WasmInstructionIterator(const byte* start, const byte* end); |
| 23 |
| 24 bool Done() const { return pc_ >= end_; } |
| 25 void Next(); |
| 26 int pc_offset() const { |
| 27 DCHECK_LE(pc_ - start_, kMaxInt); |
| 28 return static_cast<int>(pc_ - start_); |
| 29 } |
| 30 }; |
| 31 |
| 32 class WasmDebugInfo; |
| 33 |
| 34 class InterpreterFrameInfo { |
| 35 Handle<WasmDebugInfo> debug_info_; |
| 36 int func_index_; |
| 37 int pc_offset_; |
| 38 |
| 39 InterpreterFrameInfo(Handle<WasmDebugInfo> debug_info, int func_index, |
| 40 int pc_offset) |
| 41 : debug_info_(debug_info), |
| 42 func_index_(func_index), |
| 43 pc_offset_(pc_offset) {} |
| 44 friend class InterpreterFrameIterator; |
| 45 |
| 46 public: |
| 47 InterpreterFrameInfo(const InterpreterFrameInfo& other) |
| 48 : func_index_(other.func_index_), pc_offset_(other.pc_offset_) {} |
| 49 int func_index() const { return func_index_; } |
| 50 int pc_offset() const { return pc_offset_; } |
| 51 Script* GetScript() const; |
| 52 }; |
| 53 |
| 54 class WasmInterpreter; |
| 55 |
| 56 class InterpreterFrameIterator { |
| 57 int frame_nr_; |
| 58 int frame_count_; |
| 59 |
| 60 Handle<WasmDebugInfo> debug_info_; |
| 61 |
| 62 explicit InterpreterFrameIterator(Handle<WasmDebugInfo> debug_info); |
| 63 friend class WasmDebugInfo; |
| 64 |
| 65 public: |
| 66 bool Done() const { return frame_nr_ == frame_count_; } |
| 67 void Next() { |
| 68 DCHECK(!Done()); |
| 69 ++frame_nr_; |
| 70 } |
| 71 int Remaining() const { return frame_count_ - frame_nr_ - 1; } |
| 72 InterpreterFrameInfo GetFrameInfo() const; |
| 73 }; |
| 74 |
15 class WasmDebugInfo : public FixedArray { | 75 class WasmDebugInfo : public FixedArray { |
16 public: | 76 public: |
17 static Handle<WasmDebugInfo> New(Handle<JSObject> wasm); | 77 static Handle<WasmDebugInfo> New(Handle<JSObject> wasm); |
18 | 78 |
19 static bool IsDebugInfo(Object* object); | 79 static bool IsWasmDebugInfo(Object* object); |
20 static WasmDebugInfo* cast(Object* object); | 80 static WasmDebugInfo* cast(Object* object); |
21 | 81 |
22 JSObject* wasm_object(); | 82 JSObject* wasm_object(); |
23 | 83 |
24 bool SetBreakPoint(int byte_offset); | 84 static void SetBreakpoint(Handle<WasmDebugInfo> debug_info, int func_index, |
| 85 int byte_offset); |
| 86 bool HasBreakpoint(int func_index, int byte_offset); |
25 | 87 |
26 // Get the Script for the specified function. | 88 // Get the Script for the specified function. |
27 static Script* GetFunctionScript(Handle<WasmDebugInfo> debug_info, | 89 static Script* GetFunctionScript(Handle<WasmDebugInfo> debug_info, |
28 int func_index); | 90 int func_index); |
29 | 91 |
30 // Disassemble the specified function from this module. | 92 // Disassemble the specified function from this module. |
31 static Handle<String> DisassembleFunction(Handle<WasmDebugInfo> debug_info, | 93 static Handle<String> DisassembleFunction(Handle<WasmDebugInfo> debug_info, |
32 int func_index); | 94 int func_index); |
33 | 95 |
34 // Get the offset table for the specified function, mapping from byte offsets | 96 // Get the offset table for the specified function, mapping from byte offsets |
35 // to position in the disassembly. | 97 // to position in the disassembly. |
36 // Returns an array with three entries per instruction: byte offset, line and | 98 // Returns an array with three entries per instruction: byte offset, line and |
37 // column. | 99 // column. |
38 static Handle<FixedArray> GetFunctionOffsetTable( | 100 static Handle<FixedArray> GetFunctionOffsetTable( |
39 Handle<WasmDebugInfo> debug_info, int func_index); | 101 Handle<WasmDebugInfo> debug_info, int func_index); |
| 102 |
| 103 // Get the DebugInfo for the specified function. |
| 104 static DebugInfo* GetDebugInfo(Handle<WasmDebugInfo> debug_info, |
| 105 int func_index); |
| 106 |
| 107 enum InstructionType { CALL, RETURN, OTHER }; |
| 108 |
| 109 // Determine the type of instruction for the given function and offset. |
| 110 // Used to determine the BreakLocation::DebugBreakType. |
| 111 InstructionType GetInstructionType(int func_index, int byte_offset); |
| 112 |
| 113 // Get an instruction iterator for the given function. |
| 114 // This iterator might be invalidated when gc happens, so the caller has to |
| 115 // ensure that no heap allocations happen as long as the iterator is in use. |
| 116 static WasmInstructionIterator GetInstructionIterator( |
| 117 Handle<WasmDebugInfo> debug_info, int func_index); |
| 118 |
| 119 // Get an iterator to inspect the frames inside the current interpreter. |
| 120 // The frames are inspected upwards, i.e. caller before callee. |
| 121 InterpreterFrameIterator GetInterpreterFrameIterator(); |
| 122 |
| 123 // Get a pointer to a buffer where arguments to be passed to the interpreter |
| 124 // can be stored. |
| 125 // This is a raw C pointer, encoded in an Object*. Since it is aligned, the GC |
| 126 // will handle it like a Smi. |
| 127 Object* GetInterpreterArgBuffer(int func_index); |
| 128 |
| 129 // Run a specific function in the interpreter. The arg buffer must have been |
| 130 // filled before (see GetInterpreterArgBuffer). |
| 131 void RunInterpreter(int func_index); |
40 }; | 132 }; |
41 | 133 |
42 } // namespace wasm | 134 } // namespace wasm |
43 } // namespace internal | 135 } // namespace internal |
44 } // namespace v8 | 136 } // namespace v8 |
45 | 137 |
46 #endif // V8_WASM_DEBUG_H_ | 138 #endif // V8_WASM_DEBUG_H_ |
OLD | NEW |