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_INSPECTOR_WASMTRANSLATION_H_ | 5 #ifndef V8_INSPECTOR_WASMTRANSLATION_H_ |
6 #define V8_INSPECTOR_WASMTRANSLATION_H_ | 6 #define V8_INSPECTOR_WASMTRANSLATION_H_ |
7 | 7 |
8 #include <unordered_map> | 8 #include <unordered_map> |
9 | 9 |
10 #include "include/v8.h" | 10 #include "include/v8.h" |
11 #include "src/base/macros.h" | 11 #include "src/base/macros.h" |
| 12 #include "src/debug/debug-interface.h" |
12 #include "src/inspector/string-16.h" | 13 #include "src/inspector/string-16.h" |
13 | 14 |
14 namespace v8_inspector { | 15 namespace v8_inspector { |
15 | 16 |
16 // Forward declarations. | 17 // Forward declarations. |
17 class V8Debugger; | 18 class V8DebuggerAgentImpl; |
18 class V8DebuggerScript; | |
19 struct ScriptBreakpoint; | |
20 namespace protocol { | |
21 namespace Debugger { | |
22 class Location; | |
23 } | |
24 } | |
25 | 19 |
26 class WasmTranslation { | 20 class WasmTranslation { |
27 public: | 21 public: |
28 enum Mode { Raw, Disassemble }; | 22 enum Mode { Raw, Disassemble }; |
29 | 23 |
30 WasmTranslation(v8::Isolate* isolate, V8Debugger* debugger); | 24 explicit WasmTranslation(v8::Isolate* isolate); |
31 ~WasmTranslation(); | 25 ~WasmTranslation(); |
32 | 26 |
33 // Set translation mode. | 27 // Set translation mode. |
34 void SetMode(Mode mode) { mode_ = mode; } | 28 void SetMode(Mode mode) { mode_ = mode; } |
35 | 29 |
36 // Make a wasm script known to the translation. Only locations referencing a | 30 // Make a wasm script known to the translation. This will trigger a number of |
37 // registered script will be translated by the Translate functions below. | 31 // didParseScript calls to the given debugger agent. |
38 void AddScript(v8::Local<v8::Object> script_wrapper); | 32 // Only locations referencing a registered script will be translated by the |
| 33 // Translate functions below. |
| 34 void AddScript(v8::Local<v8::DebugInterface::WasmScript> script, |
| 35 V8DebuggerAgentImpl* agent); |
39 | 36 |
40 // Clear all registered scripts. | 37 // Clear all registered scripts. |
41 void Clear(); | 38 void Clear(); |
42 | 39 |
43 // Translate a location as generated by V8 to a location that should be sent | 40 // Translate a location as generated by V8 to a location that should be sent |
44 // over protocol. | 41 // over protocol. |
45 // Does nothing for locations referencing a script which was not registered | 42 // Does nothing for locations referencing a script which was not registered |
46 // before via AddScript. | 43 // before via AddScript. |
47 // Line and column are 0-based. | 44 // Line and column are 0-based. |
48 // The context group id specifies the context of the script. | |
49 // If the script was registered and the respective wasm function was not seen | |
50 // before, a new artificial script representing this function will be created | |
51 // and made public to the frontend. | |
52 // Returns true if the location was translated, false otherwise. | 45 // Returns true if the location was translated, false otherwise. |
53 bool TranslateWasmScriptLocationToProtocolLocation(String16* script_id, | 46 bool TranslateWasmScriptLocationToProtocolLocation(String16* script_id, |
54 int* line_number, | 47 int* line_number, |
55 int* column_number, | 48 int* column_number); |
56 int context_group_id); | |
57 | 49 |
58 // Translate back from protocol locations (potentially referencing artificial | 50 // Translate back from protocol locations (potentially referencing artificial |
59 // scripts for individual wasm functions) to locations that make sense to V8. | 51 // scripts for individual wasm functions) to locations that make sense to V8. |
60 // Does nothing if the location was not generated by the translate method | 52 // Does nothing if the location was not generated by the translate method |
61 // above. | 53 // above. |
62 // Returns true if the location was translated, false otherwise. | 54 // Returns true if the location was translated, false otherwise. |
63 bool TranslateProtocolLocationToWasmScriptLocation(String16* script_id, | 55 bool TranslateProtocolLocationToWasmScriptLocation(String16* script_id, |
64 int* line_number, | 56 int* line_number, |
65 int* column_number); | 57 int* column_number); |
66 | 58 |
67 private: | 59 private: |
68 class TranslatorImpl; | 60 class TranslatorImpl; |
69 friend class TranslatorImpl; | 61 friend class TranslatorImpl; |
70 | 62 |
71 void AddFakeScript(std::unique_ptr<V8DebuggerScript> fake_script, | 63 void AddFakeScript(const String16& scriptId, TranslatorImpl* translator); |
72 TranslatorImpl* translator, int context_group_id); | |
73 | 64 |
74 v8::Isolate* isolate_; | 65 v8::Isolate* isolate_; |
75 V8Debugger* debugger_; | |
76 std::unordered_map<int, std::unique_ptr<TranslatorImpl>> wasm_translators_; | 66 std::unordered_map<int, std::unique_ptr<TranslatorImpl>> wasm_translators_; |
77 std::unordered_map<String16, TranslatorImpl*> fake_scripts_; | 67 std::unordered_map<String16, TranslatorImpl*> fake_scripts_; |
78 Mode mode_; | 68 Mode mode_; |
79 | 69 |
80 DISALLOW_COPY_AND_ASSIGN(WasmTranslation); | 70 DISALLOW_COPY_AND_ASSIGN(WasmTranslation); |
81 }; | 71 }; |
82 | 72 |
83 } // namespace v8_inspector | 73 } // namespace v8_inspector |
84 | 74 |
85 #endif // V8_INSPECTOR_WASMTRANSLATION_H_ | 75 #endif // V8_INSPECTOR_WASMTRANSLATION_H_ |
OLD | NEW |